mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 96041. Adding win32 glyph extents patch to cairo so it doesn't get lost.
This commit is contained in:
parent
f66451340e
commit
737c2306c1
@ -25,3 +25,7 @@ win32-logical-font-scale.patch: set CAIRO_WIN32_LOGICAL_FONT_SCALE to 1
|
|||||||
|
|
||||||
nonfatal-assertions.patch: Make assertions non-fatal
|
nonfatal-assertions.patch: Make assertions non-fatal
|
||||||
|
|
||||||
|
win32-glyph-metrics.patch: GetGlyphOutline only works on Truetype fonts,
|
||||||
|
so for non-Truetype fonts, assume no left or right bearing and use the
|
||||||
|
font ascent and descent for the glyph extents.
|
||||||
|
|
||||||
|
154
gfx/cairo/win32-glyph-metrics.patch
Normal file
154
gfx/cairo/win32-glyph-metrics.patch
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
Index: gfx/cairo/cairo/src/cairo-win32-font.c
|
||||||
|
===================================================================
|
||||||
|
RCS file: /cvsroot/mozilla/gfx/cairo/cairo/src/cairo-win32-font.c,v
|
||||||
|
retrieving revision 1.37
|
||||||
|
diff -u -p -1 -2 -r1.37 cairo-win32-font.c
|
||||||
|
--- gfx/cairo/cairo/src/cairo-win32-font.c 22 Sep 2007 13:28:16 -0000 1.37
|
||||||
|
+++ gfx/cairo/cairo/src/cairo-win32-font.c 23 Sep 2007 23:55:06 -0000
|
||||||
|
@@ -90,24 +90,25 @@ typedef struct {
|
||||||
|
cairo_bool_t swap_x;
|
||||||
|
cairo_bool_t swap_y;
|
||||||
|
double x_scale;
|
||||||
|
double y_scale;
|
||||||
|
|
||||||
|
/* The size of the design unit of the font
|
||||||
|
*/
|
||||||
|
int em_square;
|
||||||
|
|
||||||
|
HFONT scaled_hfont;
|
||||||
|
HFONT unscaled_hfont;
|
||||||
|
|
||||||
|
+ cairo_bool_t is_truetype;
|
||||||
|
cairo_bool_t glyph_indexing;
|
||||||
|
|
||||||
|
cairo_bool_t delete_scaled_hfont;
|
||||||
|
} cairo_win32_scaled_font_t;
|
||||||
|
|
||||||
|
static cairo_status_t
|
||||||
|
_cairo_win32_scaled_font_set_metrics (cairo_win32_scaled_font_t *scaled_font);
|
||||||
|
|
||||||
|
static cairo_status_t
|
||||||
|
_cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_font,
|
||||||
|
cairo_scaled_glyph_t *scaled_glyph);
|
||||||
|
|
||||||
|
@@ -735,64 +736,81 @@ _cairo_win32_scaled_font_set_metrics (ca
|
||||||
|
return status;
|
||||||
|
GetTextMetrics (hdc, &metrics);
|
||||||
|
_cairo_win32_scaled_font_done_unscaled_font (&scaled_font->base);
|
||||||
|
|
||||||
|
extents.ascent = (double)metrics.tmAscent / scaled_font->em_square;
|
||||||
|
extents.descent = (double)metrics.tmDescent / scaled_font->em_square;
|
||||||
|
extents.height = (double)(metrics.tmHeight + metrics.tmExternalLeading) / scaled_font->em_square;
|
||||||
|
extents.max_x_advance = (double)(metrics.tmMaxCharWidth) / scaled_font->em_square;
|
||||||
|
extents.max_y_advance = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- if ((metrics.tmPitchAndFamily & TMPF_TRUETYPE) ||
|
||||||
|
- (GetFontData (hdc, OPENTYPE_CFF_TAG, 0, NULL, 0) != GDI_ERROR))
|
||||||
|
- scaled_font->glyph_indexing = TRUE;
|
||||||
|
- else
|
||||||
|
- scaled_font->glyph_indexing = FALSE;
|
||||||
|
+ scaled_font->is_truetype = (metrics.tmPitchAndFamily & TMPF_TRUETYPE) != 0;
|
||||||
|
+ scaled_font->glyph_indexing = scaled_font->is_truetype ||
|
||||||
|
+ (GetFontData (hdc, OPENTYPE_CFF_TAG, 0, NULL, 0) != GDI_ERROR);
|
||||||
|
+ // XXX in what situations does this OPENTYPE_CFF thing not have the
|
||||||
|
+ // TMPF_TRUETYPE flag? GetFontData says it only works on Truetype fonts...
|
||||||
|
|
||||||
|
_cairo_scaled_font_set_metrics (&scaled_font->base, &extents);
|
||||||
|
|
||||||
|
return CAIRO_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cairo_status_t
|
||||||
|
_cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_font,
|
||||||
|
cairo_scaled_glyph_t *scaled_glyph)
|
||||||
|
{
|
||||||
|
static const MAT2 matrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
|
||||||
|
GLYPHMETRICS metrics;
|
||||||
|
cairo_status_t status;
|
||||||
|
cairo_text_extents_t extents;
|
||||||
|
HDC hdc;
|
||||||
|
- UINT glyph_index_option;
|
||||||
|
|
||||||
|
hdc = _get_global_font_dc ();
|
||||||
|
if (!hdc)
|
||||||
|
return CAIRO_STATUS_NO_MEMORY;
|
||||||
|
|
||||||
|
- if (scaled_font->glyph_indexing)
|
||||||
|
- glyph_index_option = GGO_GLYPH_INDEX;
|
||||||
|
- else
|
||||||
|
- glyph_index_option = 0;
|
||||||
|
+ if (!scaled_font->is_truetype) {
|
||||||
|
+ /* GetGlyphOutline will not work. Assume that the glyph does not extend outside the font box. */
|
||||||
|
+ cairo_font_extents_t font_extents;
|
||||||
|
+ INT width = 0;
|
||||||
|
+ UINT charIndex = _cairo_scaled_glyph_index (scaled_glyph);
|
||||||
|
+
|
||||||
|
+ cairo_scaled_font_extents (&scaled_font->base, &font_extents);
|
||||||
|
+
|
||||||
|
+ status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
|
||||||
|
+ if (!status) {
|
||||||
|
+ if (!GetCharWidth32(hdc, charIndex, charIndex, &width)) {
|
||||||
|
+ status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetCharWidth32");
|
||||||
|
+ width = 0;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ cairo_win32_scaled_font_done_font (&scaled_font->base);
|
||||||
|
|
||||||
|
- if (scaled_font->preserve_axes && scaled_font->base.options.hint_style != CAIRO_HINT_METRICS_OFF) {
|
||||||
|
+ extents.x_bearing = 0;
|
||||||
|
+ extents.y_bearing = -font_extents.ascent / scaled_font->y_scale;
|
||||||
|
+ extents.width = width / scaled_font->x_scale;
|
||||||
|
+ extents.height = (font_extents.ascent + font_extents.descent) / scaled_font->y_scale;
|
||||||
|
+ extents.x_advance = extents.width;
|
||||||
|
+ extents.y_advance = 0;
|
||||||
|
+ } else if (scaled_font->preserve_axes && scaled_font->base.options.hint_style != CAIRO_HINT_METRICS_OFF) {
|
||||||
|
/* If we aren't rotating / skewing the axes, then we get the metrics
|
||||||
|
* from the GDI in device space and convert to font space.
|
||||||
|
*/
|
||||||
|
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
if (GetGlyphOutlineW (hdc, _cairo_scaled_glyph_index (scaled_glyph),
|
||||||
|
- GGO_METRICS | glyph_index_option,
|
||||||
|
+ GGO_METRICS | GGO_GLYPH_INDEX,
|
||||||
|
&metrics, 0, NULL, &matrix) == GDI_ERROR) {
|
||||||
|
status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetGlyphOutlineW");
|
||||||
|
memset (&metrics, 0, sizeof (GLYPHMETRICS));
|
||||||
|
}
|
||||||
|
cairo_win32_scaled_font_done_font (&scaled_font->base);
|
||||||
|
|
||||||
|
if (scaled_font->swap_axes) {
|
||||||
|
extents.x_bearing = - metrics.gmptGlyphOrigin.y / scaled_font->y_scale;
|
||||||
|
extents.y_bearing = metrics.gmptGlyphOrigin.x / scaled_font->x_scale;
|
||||||
|
extents.width = metrics.gmBlackBoxY / scaled_font->y_scale;
|
||||||
|
extents.height = metrics.gmBlackBoxX / scaled_font->x_scale;
|
||||||
|
extents.x_advance = metrics.gmCellIncY / scaled_font->x_scale;
|
||||||
|
@@ -813,25 +831,25 @@ _cairo_win32_scaled_font_init_glyph_metr
|
||||||
|
|
||||||
|
if (scaled_font->swap_y) {
|
||||||
|
extents.y_bearing = (- extents.y_bearing - extents.height);
|
||||||
|
extents.y_advance = - extents.y_advance;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* For all other transformations, we use the design metrics
|
||||||
|
* of the font.
|
||||||
|
*/
|
||||||
|
status = _cairo_win32_scaled_font_select_unscaled_font (&scaled_font->base, hdc);
|
||||||
|
if (GetGlyphOutlineW (hdc, _cairo_scaled_glyph_index (scaled_glyph),
|
||||||
|
- GGO_METRICS | glyph_index_option,
|
||||||
|
+ GGO_METRICS | GGO_GLYPH_INDEX,
|
||||||
|
&metrics, 0, NULL, &matrix) == GDI_ERROR) {
|
||||||
|
status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetGlyphOutlineW");
|
||||||
|
memset (&metrics, 0, sizeof (GLYPHMETRICS));
|
||||||
|
}
|
||||||
|
_cairo_win32_scaled_font_done_unscaled_font (&scaled_font->base);
|
||||||
|
|
||||||
|
extents.x_bearing = (double)metrics.gmptGlyphOrigin.x / scaled_font->em_square;
|
||||||
|
extents.y_bearing = - (double)metrics.gmptGlyphOrigin.y / scaled_font->em_square;
|
||||||
|
extents.width = (double)metrics.gmBlackBoxX / scaled_font->em_square;
|
||||||
|
extents.height = (double)metrics.gmBlackBoxY / scaled_font->em_square;
|
||||||
|
extents.x_advance = (double)metrics.gmCellIncX / scaled_font->em_square;
|
||||||
|
extents.y_advance = (double)metrics.gmCellIncY / scaled_font->em_square;
|
Loading…
Reference in New Issue
Block a user