summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/base/ftglyph.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/base/ftglyph.c')
-rw-r--r--src/3rdparty/freetype/src/base/ftglyph.c436
1 files changed, 349 insertions, 87 deletions
diff --git a/src/3rdparty/freetype/src/base/ftglyph.c b/src/3rdparty/freetype/src/base/ftglyph.c
index 6759aa25d0..393d4949f8 100644
--- a/src/3rdparty/freetype/src/base/ftglyph.c
+++ b/src/3rdparty/freetype/src/base/ftglyph.c
@@ -1,51 +1,52 @@
-/***************************************************************************/
-/* */
-/* ftglyph.c */
-/* */
-/* FreeType convenience functions to handle glyphs (body). */
-/* */
-/* Copyright 1996-2018 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
- /*************************************************************************/
- /* */
- /* This file contains the definition of several convenience functions */
- /* that can be used by client applications to easily retrieve glyph */
- /* bitmaps and outlines from a given face. */
- /* */
- /* These functions should be optional if you are writing a font server */
- /* or text layout engine on top of FreeType. However, they are pretty */
- /* handy for many other simple uses of the library. */
- /* */
- /*************************************************************************/
-
-
-#include <ft2build.h>
-#include FT_INTERNAL_DEBUG_H
-
-#include FT_GLYPH_H
-#include FT_OUTLINE_H
-#include FT_BITMAP_H
-#include FT_INTERNAL_OBJECTS_H
-
-#include "basepic.h"
-
- /*************************************************************************/
- /* */
- /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
- /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
- /* messages during execution. */
- /* */
+/****************************************************************************
+ *
+ * ftglyph.c
+ *
+ * FreeType convenience functions to handle glyphs (body).
+ *
+ * Copyright (C) 1996-2023 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+ /**************************************************************************
+ *
+ * This file contains the definition of several convenience functions
+ * that can be used by client applications to easily retrieve glyph
+ * bitmaps and outlines from a given face.
+ *
+ * These functions should be optional if you are writing a font server
+ * or text layout engine on top of FreeType. However, they are pretty
+ * handy for many other simple uses of the library.
+ *
+ */
+
+
+#include <freetype/internal/ftdebug.h>
+
+#include <freetype/ftglyph.h>
+#include <freetype/ftoutln.h>
+#include <freetype/ftbitmap.h>
+#include <freetype/internal/ftobjs.h>
+#include <freetype/otsvg.h>
+
+#include "ftbase.h"
+
+
+ /**************************************************************************
+ *
+ * The macro FT_COMPONENT is used in trace mode. It is an implicit
+ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
+ * messages during execution.
+ */
#undef FT_COMPONENT
-#define FT_COMPONENT trace_glyph
+#define FT_COMPONENT glyph
/*************************************************************************/
@@ -77,7 +78,7 @@
/* do lazy copying whenever possible */
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
{
- glyph->bitmap = slot->bitmap;
+ glyph->bitmap = slot->bitmap;
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
}
else
@@ -277,6 +278,240 @@
)
+#ifdef FT_CONFIG_OPTION_SVG
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /**** ****/
+ /**** FT_SvgGlyph support ****/
+ /**** ****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+
+ FT_CALLBACK_DEF( FT_Error )
+ ft_svg_glyph_init( FT_Glyph svg_glyph,
+ FT_GlyphSlot slot )
+ {
+ FT_ULong doc_length;
+ FT_SVG_Document document;
+ FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
+
+ FT_Error error = FT_Err_Ok;
+ FT_Memory memory = FT_GLYPH( glyph )->library->memory;
+
+
+ if ( slot->format != FT_GLYPH_FORMAT_SVG )
+ {
+ error = FT_THROW( Invalid_Glyph_Format );
+ goto Exit;
+ }
+
+ if ( slot->other == NULL )
+ {
+ error = FT_THROW( Invalid_Slot_Handle );
+ goto Exit;
+ }
+
+ document = (FT_SVG_Document)slot->other;
+
+ if ( document->svg_document_length == 0 )
+ {
+ error = FT_THROW( Invalid_Slot_Handle );
+ goto Exit;
+ }
+
+ /* allocate a new document */
+ doc_length = document->svg_document_length;
+ if ( FT_QALLOC( glyph->svg_document, doc_length ) )
+ goto Exit;
+ glyph->svg_document_length = doc_length;
+
+ glyph->glyph_index = slot->glyph_index;
+
+ glyph->metrics = document->metrics;
+ glyph->units_per_EM = document->units_per_EM;
+
+ glyph->start_glyph_id = document->start_glyph_id;
+ glyph->end_glyph_id = document->end_glyph_id;
+
+ glyph->transform = document->transform;
+ glyph->delta = document->delta;
+
+ /* copy the document into glyph */
+ FT_MEM_COPY( glyph->svg_document, document->svg_document, doc_length );
+
+ Exit:
+ return error;
+ }
+
+
+ FT_CALLBACK_DEF( void )
+ ft_svg_glyph_done( FT_Glyph svg_glyph )
+ {
+ FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
+ FT_Memory memory = svg_glyph->library->memory;
+
+
+ /* just free the memory */
+ FT_FREE( glyph->svg_document );
+ }
+
+
+ FT_CALLBACK_DEF( FT_Error )
+ ft_svg_glyph_copy( FT_Glyph svg_source,
+ FT_Glyph svg_target )
+ {
+ FT_SvgGlyph source = (FT_SvgGlyph)svg_source;
+ FT_SvgGlyph target = (FT_SvgGlyph)svg_target;
+
+ FT_Error error = FT_Err_Ok;
+ FT_Memory memory = FT_GLYPH( source )->library->memory;
+
+
+ if ( svg_source->format != FT_GLYPH_FORMAT_SVG )
+ {
+ error = FT_THROW( Invalid_Glyph_Format );
+ goto Exit;
+ }
+
+ if ( source->svg_document_length == 0 )
+ {
+ error = FT_THROW( Invalid_Slot_Handle );
+ goto Exit;
+ }
+
+ target->glyph_index = source->glyph_index;
+
+ target->svg_document_length = source->svg_document_length;
+
+ target->metrics = source->metrics;
+ target->units_per_EM = source->units_per_EM;
+
+ target->start_glyph_id = source->start_glyph_id;
+ target->end_glyph_id = source->end_glyph_id;
+
+ target->transform = source->transform;
+ target->delta = source->delta;
+
+ /* allocate space for the SVG document */
+ if ( FT_QALLOC( target->svg_document, target->svg_document_length ) )
+ goto Exit;
+
+ /* copy the document */
+ FT_MEM_COPY( target->svg_document,
+ source->svg_document,
+ target->svg_document_length );
+
+ Exit:
+ return error;
+ }
+
+
+ FT_CALLBACK_DEF( void )
+ ft_svg_glyph_transform( FT_Glyph svg_glyph,
+ const FT_Matrix* _matrix,
+ const FT_Vector* _delta )
+ {
+ FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
+ FT_Matrix* matrix = (FT_Matrix*)_matrix;
+ FT_Vector* delta = (FT_Vector*)_delta;
+
+ FT_Matrix tmp_matrix;
+ FT_Vector tmp_delta;
+
+ FT_Matrix a, b;
+ FT_Pos x, y;
+
+
+ if ( !matrix )
+ {
+ tmp_matrix.xx = 0x10000;
+ tmp_matrix.xy = 0;
+ tmp_matrix.yx = 0;
+ tmp_matrix.yy = 0x10000;
+
+ matrix = &tmp_matrix;
+ }
+
+ if ( !delta )
+ {
+ tmp_delta.x = 0;
+ tmp_delta.y = 0;
+
+ delta = &tmp_delta;
+ }
+
+ a = glyph->transform;
+ b = *matrix;
+ FT_Matrix_Multiply( &b, &a );
+
+ x = ADD_LONG( ADD_LONG( FT_MulFix( matrix->xx, glyph->delta.x ),
+ FT_MulFix( matrix->xy, glyph->delta.y ) ),
+ delta->x );
+ y = ADD_LONG( ADD_LONG( FT_MulFix( matrix->yx, glyph->delta.x ),
+ FT_MulFix( matrix->yy, glyph->delta.y ) ),
+ delta->y );
+
+ glyph->delta.x = x;
+ glyph->delta.y = y;
+
+ glyph->transform = a;
+ }
+
+
+ FT_CALLBACK_DEF( FT_Error )
+ ft_svg_glyph_prepare( FT_Glyph svg_glyph,
+ FT_GlyphSlot slot )
+ {
+ FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
+
+ FT_Error error = FT_Err_Ok;
+ FT_Memory memory = svg_glyph->library->memory;
+
+ FT_SVG_Document document = NULL;
+
+
+ if ( FT_NEW( document ) )
+ return error;
+
+ document->svg_document = glyph->svg_document;
+ document->svg_document_length = glyph->svg_document_length;
+
+ document->metrics = glyph->metrics;
+ document->units_per_EM = glyph->units_per_EM;
+
+ document->start_glyph_id = glyph->start_glyph_id;
+ document->end_glyph_id = glyph->end_glyph_id;
+
+ document->transform = glyph->transform;
+ document->delta = glyph->delta;
+
+ slot->format = FT_GLYPH_FORMAT_SVG;
+ slot->glyph_index = glyph->glyph_index;
+ slot->other = document;
+
+ return error;
+ }
+
+
+ FT_DEFINE_GLYPH(
+ ft_svg_glyph_class,
+
+ sizeof ( FT_SvgGlyphRec ),
+ FT_GLYPH_FORMAT_SVG,
+
+ ft_svg_glyph_init, /* FT_Glyph_InitFunc glyph_init */
+ ft_svg_glyph_done, /* FT_Glyph_DoneFunc glyph_done */
+ ft_svg_glyph_copy, /* FT_Glyph_CopyFunc glyph_copy */
+ ft_svg_glyph_transform, /* FT_Glyph_TransformFunc glyph_transform */
+ NULL, /* FT_Glyph_GetBBoxFunc glyph_bbox */
+ ft_svg_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */
+ )
+
+#endif /* FT_CONFIG_OPTION_SVG */
+
+
/*************************************************************************/
/*************************************************************************/
/**** ****/
@@ -359,37 +594,34 @@
/* documentation is in ftglyph.h */
- FT_EXPORT_DEF( FT_Error )
- FT_Get_Glyph( FT_GlyphSlot slot,
- FT_Glyph *aglyph )
+ FT_EXPORT( FT_Error )
+ FT_New_Glyph( FT_Library library,
+ FT_Glyph_Format format,
+ FT_Glyph *aglyph )
{
- FT_Library library;
- FT_Error error;
- FT_Glyph glyph;
-
const FT_Glyph_Class* clazz = NULL;
-
- if ( !slot )
- return FT_THROW( Invalid_Slot_Handle );
-
- library = slot->library;
-
- if ( !aglyph )
+ if ( !library || !aglyph )
return FT_THROW( Invalid_Argument );
/* if it is a bitmap, that's easy :-) */
- if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
- clazz = FT_BITMAP_GLYPH_CLASS_GET;
+ if ( format == FT_GLYPH_FORMAT_BITMAP )
+ clazz = &ft_bitmap_glyph_class;
/* if it is an outline */
- else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
- clazz = FT_OUTLINE_GLYPH_CLASS_GET;
+ else if ( format == FT_GLYPH_FORMAT_OUTLINE )
+ clazz = &ft_outline_glyph_class;
+
+#ifdef FT_CONFIG_OPTION_SVG
+ /* if it is an SVG glyph */
+ else if ( format == FT_GLYPH_FORMAT_SVG )
+ clazz = &ft_svg_glyph_class;
+#endif
else
{
/* try to find a renderer that supports the glyph image format */
- FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 );
+ FT_Renderer render = FT_Lookup_Renderer( library, format, 0 );
if ( render )
@@ -397,13 +629,31 @@
}
if ( !clazz )
- {
- error = FT_THROW( Invalid_Glyph_Format );
- goto Exit;
- }
+ return FT_THROW( Invalid_Glyph_Format );
+
+ /* create FT_Glyph object */
+ return ft_new_glyph( library, clazz, aglyph );
+ }
+
+
+ /* documentation is in ftglyph.h */
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Get_Glyph( FT_GlyphSlot slot,
+ FT_Glyph *aglyph )
+ {
+ FT_Error error;
+ FT_Glyph glyph;
+
+
+ if ( !slot )
+ return FT_THROW( Invalid_Slot_Handle );
+
+ if ( !aglyph )
+ return FT_THROW( Invalid_Argument );
/* create FT_Glyph object */
- error = ft_new_glyph( library, clazz, &glyph );
+ error = FT_New_Glyph( slot->library, slot->format, &glyph );
if ( error )
goto Exit;
@@ -427,12 +677,15 @@
glyph->advance.y = slot->advance.y * 1024;
/* now import the image from the glyph slot */
- error = clazz->glyph_init( glyph, slot );
+ error = glyph->clazz->glyph_init( glyph, slot );
Exit2:
/* if an error occurred, destroy the glyph */
if ( error )
+ {
FT_Done_Glyph( glyph );
+ *aglyph = NULL;
+ }
else
*aglyph = glyph;
@@ -444,9 +697,9 @@
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
- FT_Glyph_Transform( FT_Glyph glyph,
- FT_Matrix* matrix,
- FT_Vector* delta )
+ FT_Glyph_Transform( FT_Glyph glyph,
+ const FT_Matrix* matrix,
+ const FT_Vector* delta )
{
FT_Error error = FT_Err_Ok;
@@ -505,8 +758,8 @@
{
acbox->xMin = FT_PIX_FLOOR( acbox->xMin );
acbox->yMin = FT_PIX_FLOOR( acbox->yMin );
- acbox->xMax = FT_PIX_CEIL( acbox->xMax );
- acbox->yMax = FT_PIX_CEIL( acbox->yMax );
+ acbox->xMax = FT_PIX_CEIL_LONG( acbox->xMax );
+ acbox->yMax = FT_PIX_CEIL_LONG( acbox->yMax );
}
/* convert to integer pixels if needed */
@@ -524,10 +777,10 @@
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
- FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
- FT_Render_Mode render_mode,
- FT_Vector* origin,
- FT_Bool destroy )
+ FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
+ FT_Render_Mode render_mode,
+ const FT_Vector* origin,
+ FT_Bool destroy )
{
FT_GlyphSlotRec dummy;
FT_GlyphSlot_InternalRec dummy_internal;
@@ -536,7 +789,6 @@
FT_BitmapGlyph bitmap = NULL;
const FT_Glyph_Class* clazz;
- /* FT_BITMAP_GLYPH_CLASS_GET dereferences `library' in PIC mode */
FT_Library library;
@@ -553,7 +805,7 @@
goto Bad;
/* when called with a bitmap glyph, do nothing and return successfully */
- if ( clazz == FT_BITMAP_GLYPH_CLASS_GET )
+ if ( clazz == &ft_bitmap_glyph_class )
goto Exit;
if ( !clazz->glyph_prepare )
@@ -569,7 +821,7 @@
dummy.format = clazz->glyph_format;
/* create result bitmap glyph */
- error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, &b );
+ error = ft_new_glyph( library, &ft_bitmap_glyph_class, &b );
if ( error )
goto Exit;
bitmap = (FT_BitmapGlyph)b;
@@ -577,7 +829,7 @@
#if 1
/* if `origin' is set, translate the glyph image */
if ( origin )
- FT_Glyph_Transform( glyph, 0, origin );
+ FT_Glyph_Transform( glyph, NULL, origin );
#else
FT_UNUSED( origin );
#endif
@@ -587,6 +839,16 @@
if ( !error )
error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
+#ifdef FT_CONFIG_OPTION_SVG
+ if ( clazz == &ft_svg_glyph_class )
+ {
+ FT_Memory memory = library->memory;
+
+
+ FT_FREE( dummy.other );
+ }
+#endif
+
#if 1
if ( !destroy && origin )
{
@@ -595,7 +857,7 @@
v.x = -origin->x;
v.y = -origin->y;
- FT_Glyph_Transform( glyph, 0, &v );
+ FT_Glyph_Transform( glyph, NULL, &v );
}
#endif