[cairo-commit] 4 commits - src/cairo-font-face-twin.c
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Dec 24 13:37:01 PST 2008
src/cairo-font-face-twin.c | 63 ++++++++++++++++++++++++++++++++-------------
1 file changed, 45 insertions(+), 18 deletions(-)
New commits:
commit 1116febb40cb5e5f7eafe97999d1143347819b3f
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Dec 24 16:32:25 2008 -0500
[twin] Implement small-caps
diff --git a/src/cairo-font-face-twin.c b/src/cairo-font-face-twin.c
index b4a2717..f911005 100644
--- a/src/cairo-font-face-twin.c
+++ b/src/cairo-font-face-twin.c
@@ -298,11 +298,6 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
int n_snap_y;
} info = {FALSE};
- b = _cairo_twin_outlines +
- _cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph];
- g = twin_glyph_draw(b);
- w = twin_glyph_right(b);
-
cairo_set_tolerance (cr, 0.01);
/* Prepare face */
@@ -330,8 +325,8 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
/* lock pen matrix */
cairo_save (cr);
- /* left margin */
- cairo_translate (cr, lw, 0);
+ /* left margin + pen width */
+ cairo_translate (cr, lw * 1.5, 0);
/* slant */
if (props->slant != CAIRO_FONT_SLANT_NORMAL) {
@@ -339,22 +334,32 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
cairo_transform (cr, &shear);
}
+ if (props->smallcaps && glyph >= 'a' && glyph <= 'z') {
+ glyph += 'A' - 'a';
+ cairo_scale (cr, 1, 28. / 42);
+ }
+
+ b = _cairo_twin_outlines +
+ _cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph];
+ g = twin_glyph_draw(b);
+ w = twin_glyph_right(b);
gw = FX(w);
+ /* monospace */
if (props->monospace) {
double monow = FX(24);
cairo_scale (cr, (monow+lw) / (gw+lw), 1);
gw = monow;
}
- cairo_translate (cr, lw * .5, 0); /* for pen width */
-
- metrics->x_advance = gw + lw;
- metrics->x_advance += 2 * lw /* XXX 2*x.margin */;
+ /* advance width */
+ metrics->x_advance = gw + lw * 3; /* pen width + margin */
metrics->x_advance *= stretch;
if (info.snap)
metrics->x_advance = SNAPI (SNAPX (metrics->x_advance));
+
+ /* glyph shape */
for (;;) {
switch (*g++) {
case 'M':
commit 6767673961401c7ab7b92eb8dfbb345efb560741
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Dec 24 16:13:12 2008 -0500
[twin] Implement stretch
diff --git a/src/cairo-font-face-twin.c b/src/cairo-font-face-twin.c
index 41032dd..b4a2717 100644
--- a/src/cairo-font-face-twin.c
+++ b/src/cairo-font-face-twin.c
@@ -286,7 +286,9 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
const int8_t *b;
const int8_t *g;
int8_t w;
+ double gw;
double lw;
+ double stretch;
struct {
cairo_bool_t snap;
@@ -308,6 +310,7 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
props = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
&twin_face_properties_key);
+ /* weight */
lw = props->weight * (5.5 / 64 / TWIN_WEIGHT_NORMAL);
cairo_set_line_width (cr, lw);
@@ -319,24 +322,36 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
CAIRO_LINE_CAP_SQUARE : */
CAIRO_LINE_CAP_ROUND);
+
+ /* stretch */
+ stretch = 1 + .05 * ((int) props->stretch - (int) TWIN_STRETCH_NORMAL);
+ cairo_scale (cr, stretch, 1);
+
+ /* lock pen matrix */
+ cairo_save (cr);
+
+ /* left margin */
+ cairo_translate (cr, lw, 0);
+
+ /* slant */
if (props->slant != CAIRO_FONT_SLANT_NORMAL) {
cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0};
cairo_transform (cr, &shear);
}
- cairo_translate (cr, lw, 0); /* for margin */
+ gw = FX(w);
- cairo_save (cr);
if (props->monospace) {
- int8_t monow = 24;
- cairo_scale (cr, (FX(monow)+lw) / (FX(w)+lw), 1.);
- w = monow;
+ double monow = FX(24);
+ cairo_scale (cr, (monow+lw) / (gw+lw), 1);
+ gw = monow;
}
cairo_translate (cr, lw * .5, 0); /* for pen width */
- metrics->x_advance = FX(w) + lw;
+ metrics->x_advance = gw + lw;
metrics->x_advance += 2 * lw /* XXX 2*x.margin */;
+ metrics->x_advance *= stretch;
if (info.snap)
metrics->x_advance = SNAPI (SNAPX (metrics->x_advance));
commit 0656e947f11356877014df93bd083123c7313dc3
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Dec 24 15:43:17 2008 -0500
[twin] Implement slant
diff --git a/src/cairo-font-face-twin.c b/src/cairo-font-face-twin.c
index c116df8..41032dd 100644
--- a/src/cairo-font-face-twin.c
+++ b/src/cairo-font-face-twin.c
@@ -301,10 +301,13 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
g = twin_glyph_draw(b);
w = twin_glyph_right(b);
+ cairo_set_tolerance (cr, 0.01);
+
+ /* Prepare face */
+
props = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font),
&twin_face_properties_key);
- cairo_set_tolerance (cr, 0.01);
- /* The weight is tuned to match DejaVu Sans' */
+
lw = props->weight * (5.5 / 64 / TWIN_WEIGHT_NORMAL);
cairo_set_line_width (cr, lw);
@@ -316,6 +319,10 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
CAIRO_LINE_CAP_SQUARE : */
CAIRO_LINE_CAP_ROUND);
+ if (props->slant != CAIRO_FONT_SLANT_NORMAL) {
+ cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0};
+ cairo_transform (cr, &shear);
+ }
cairo_translate (cr, lw, 0); /* for margin */
commit 9d493fcd16fb770f21fa732b08834f3a435fe1f2
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Dec 24 15:36:57 2008 -0500
[twin] Disable the serif mode
diff --git a/src/cairo-font-face-twin.c b/src/cairo-font-face-twin.c
index e06bf26..c116df8 100644
--- a/src/cairo-font-face-twin.c
+++ b/src/cairo-font-face-twin.c
@@ -309,11 +309,11 @@ twin_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
cairo_set_line_width (cr, lw);
cairo_set_miter_limit (cr, M_SQRT2);
- cairo_set_line_join (cr, props->serif ?
- CAIRO_LINE_JOIN_MITER :
+ cairo_set_line_join (cr, /* props->serif ?
+ CAIRO_LINE_JOIN_MITER : */
CAIRO_LINE_JOIN_ROUND);
- cairo_set_line_cap (cr, props->serif ?
- CAIRO_LINE_CAP_SQUARE :
+ cairo_set_line_cap (cr, /* props->serif ?
+ CAIRO_LINE_CAP_SQUARE : */
CAIRO_LINE_CAP_ROUND);
More information about the cairo-commit
mailing list