|
Revision 119, 0.9 kB
(checked in by DRK, 6 years ago)
|
* Added bindings for the Glitz and Xlib backends.
* Checked in cairooo: an OO layer on top of the cairo binding.
* Added snippets directory for cairooo
* Added basic tutorial on how to use cairooo
* Added a simple demo program.
* Added scripts for building import libraries.
* Fixed several bugs.
* Drank WAAY too much coffee.
|
| Line | |
|---|
| 1 |
module snippets.text_align_center; |
|---|
| 2 |
|
|---|
| 3 |
private |
|---|
| 4 |
{ |
|---|
| 5 |
import std.math; |
|---|
| 6 |
import cairooo.all; |
|---|
| 7 |
import snippets.common; |
|---|
| 8 |
} |
|---|
| 9 |
|
|---|
| 10 |
void snippet_text_align_center(Context cr, int width, int height) |
|---|
| 11 |
{ |
|---|
| 12 |
TextExtents extents; |
|---|
| 13 |
auto utf8 = "cairo"c; |
|---|
| 14 |
double x, y; |
|---|
| 15 |
|
|---|
| 16 |
cr.selectFontFace("Sans", FontSlant.Normal, FontWeight.Normal); |
|---|
| 17 |
cr.setFontSize(0.2); |
|---|
| 18 |
extents = cr.textExtents(utf8); |
|---|
| 19 |
x = 0.5 - (extents.width/2 + extents.xBearing); |
|---|
| 20 |
y = 0.5 - (extents.height/2 + extents.yBearing); |
|---|
| 21 |
|
|---|
| 22 |
cr.moveTo(x, y); |
|---|
| 23 |
cr.showText(utf8); |
|---|
| 24 |
|
|---|
| 25 |
// draw helping lines |
|---|
| 26 |
cr.setSourceRGBA(1, 0.2, 0.2, 0.6); |
|---|
| 27 |
cr.arc(x, y, 0.05, 0, 2*PI); |
|---|
| 28 |
cr.fill(); |
|---|
| 29 |
cr.moveTo(0.5, 0); |
|---|
| 30 |
cr.relLineTo(0, 1); |
|---|
| 31 |
cr.moveTo(0, 0.5); |
|---|
| 32 |
cr.relLineTo(1, 0); |
|---|
| 33 |
cr.stroke(); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
static this() |
|---|
| 37 |
{ |
|---|
| 38 |
snippets_hash["text_align_center"] = &snippet_text_align_center; |
|---|
| 39 |
} |
|---|