[cairo-commit] 2 commits - src/cairo-ft-font.c src/cairoint.h src/cairo-truetype-subset.c src/cairo-win32-font.c
Adrian Johnson
ajohnson at kemper.freedesktop.org
Tue Nov 23 03:35:56 PST 2010
src/cairo-ft-font.c | 15 ++++++++++++---
src/cairo-truetype-subset.c | 11 +++++++++++
src/cairo-win32-font.c | 7 +++++--
src/cairoint.h | 18 ++++++++++++++++++
4 files changed, 46 insertions(+), 5 deletions(-)
New commits:
commit 67a90e8035d1d7abef45c552e75348f993a3bc93
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Tue Nov 23 22:02:55 2010 +1030
Check table size in cairo_truetype_get_style()
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index a041b16..a703343 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -1518,6 +1518,17 @@ _cairo_truetype_get_style (cairo_scaled_font_t *scaled_font,
if (!backend->load_truetype_table)
return CAIRO_INT_STATUS_UNSUPPORTED;
+ size = 0;
+ status = backend->load_truetype_table (scaled_font,
+ TT_TAG_OS2, 0,
+ NULL,
+ &size);
+ if (status)
+ return status;
+
+ if (size < sizeof(os2))
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
size = sizeof (os2);
status = backend->load_truetype_table (scaled_font,
TT_TAG_OS2, 0,
commit fb0304e2a9c99fa00e68bf4b37074a6885f19cff
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Tue Nov 23 21:44:31 2010 +1030
Document load_truetype_table function and ensure ft-font and Win32-font are compliant
There were some difference between how the FT and Win32
load_truetype_table font backend functions worked due to the
difference between FT_Load_Sfnt_Table() and GetFontData(). eg FT
returns an error if less than the requested number of bytes could be
read while Win32 returns success and sets the length to the number of
bytes read.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 054da25..acb7121 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -2370,6 +2370,11 @@ _cairo_ft_load_truetype_table (void *abstract_font,
FT_Face face;
cairo_status_t status = CAIRO_INT_STATUS_UNSUPPORTED;
+ /* We don't support the FreeType feature of loading a table
+ * without specifying the size since this may overflow our
+ * buffer. */
+ assert (length != NULL);
+
if (_cairo_ft_scaled_font_is_vertical (&scaled_font->base))
return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -2378,9 +2383,13 @@ _cairo_ft_load_truetype_table (void *abstract_font,
if (!face)
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
- if (FT_IS_SFNT (face) &&
- FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0)
- status = CAIRO_STATUS_SUCCESS;
+ if (FT_IS_SFNT (face)) {
+ if (buffer == NULL)
+ *length = 0;
+
+ if (FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0)
+ status = CAIRO_STATUS_SUCCESS;
+ }
_cairo_ft_unscaled_font_unlock_face (unscaled);
#endif
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index fcd7b56..d0c29bb 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -1514,6 +1514,7 @@ _cairo_win32_scaled_font_load_truetype_table (void *abstract_font,
cairo_win32_scaled_font_t *scaled_font = abstract_font;
HDC hdc;
cairo_status_t status;
+ DWORD ret;
hdc = _get_global_font_dc ();
assert (hdc != NULL);
@@ -1523,9 +1524,11 @@ _cairo_win32_scaled_font_load_truetype_table (void *abstract_font,
if (status)
return status;
- *length = GetFontData (hdc, tag, offset, buffer, *length);
- if (*length == GDI_ERROR)
+ ret = GetFontData (hdc, tag, offset, buffer, *length);
+ if (ret == GDI_ERROR || (buffer && ret != *length))
status = CAIRO_INT_STATUS_UNSUPPORTED;
+ else
+ *length = ret;
cairo_win32_scaled_font_done_font (&scaled_font->base);
diff --git a/src/cairoint.h b/src/cairoint.h
index 5a43561..1510f8e 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -502,6 +502,24 @@ struct _cairo_scaled_font_backend {
cairo_region_t *clip_region,
int *remaining_glyphs);
+ /* Read data from a sfnt font table.
+ * @scaled_font: font
+ * @tag: 4 byte table name specifying the table to read.
+ * @offset: offset into the table
+ * @buffer: buffer to write data into. Caller must ensure there is sufficient space.
+ * If NULL, return the size of the table in @length.
+ * @length: If @buffer is NULL, the size of the table will be returned in @length.
+ * If @buffer is not null, @length specifies the number of bytes to read.
+ *
+ * If less than @length bytes are available to read this function
+ * returns CAIRO_INT_STATUS_UNSUPPORTED. Note that requesting more
+ * bytes than are available in the table may continue reading data
+ * from the following table and return success. If this is
+ * undesirable the caller should first query the table size. If an
+ * error occurs the output value of @length is undefined.
+ *
+ * Returns CAIRO_INT_STATUS_UNSUPPORTED if not a sfnt style font or table not found.
+ */
cairo_warn cairo_int_status_t
(*load_truetype_table)(void *scaled_font,
unsigned long tag,
More information about the cairo-commit
mailing list