[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] wl/freetype-demos-support-ot-svg-glyphs-new 00e3468 2/
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] wl/freetype-demos-support-ot-svg-glyphs-new 00e3468 2/5: Rename the files and update the hooks. |
Date: |
Mon, 3 Jan 2022 13:30:21 -0500 (EST) |
branch: wl/freetype-demos-support-ot-svg-glyphs-new
commit 00e3468bffd5eb390390fa9bf8041eabf945b776
Author: Moazin Khatti <moazinkhatri@gmail.com>
Commit: Werner Lemberg <wl@gnu.org>
Rename the files and update the hooks.
---
Makefile | 4 ++--
src/{rsvg_port.c => rsvg-port.c} | 43 ++++++++++++++++++++++++++++++++--------
src/{rsvg_port.h => rsvg-port.h} | 8 ++++----
3 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
index 9a1bae1..36da010 100644
--- a/Makefile
+++ b/Makefile
@@ -351,7 +351,7 @@ else
$(OBJ_DIR_2)/mlgetopt.$(SO): $(SRC_DIR)/mlgetopt.c
COMMON_OBJ := $(OBJ_DIR_2)/common.$(SO) \
$(OBJ_DIR_2)/strbuf.$(SO) \
- $(OBJ_DIR_2)/rsvg_port.$(SO) \
+ $(OBJ_DIR_2)/rsvg-port.$(SO) \
$(OBJ_DIR_2)/output.$(SO) \
$(OBJ_DIR_2)/md5.$(SO) \
$(OBJ_DIR_2)/mlgetopt.$(SO)
@@ -361,7 +361,7 @@ else
$(LIBRSVG_INCLUDES) \
$T$(subst /,$(COMPILER_SEP),$@ $<)
- $(OBJ_DIR_2)/rsvg_port.$(SO): $(SRC_DIR)/rsvg_port.c $(SRC_DIR)/rsvg_port.h
+ $(OBJ_DIR_2)/rsvg-port.$(SO): $(SRC_DIR)/rsvg-port.c $(SRC_DIR)/rsvg-port.h
$(COMPILE) $(GRAPH_INCLUDES:%=$I%) \
$(LIBRSVG_INCLUDES) \
$T$(subst /,$(COMPILER_SEP),$@ $<)
diff --git a/src/rsvg_port.c b/src/rsvg-port.c
similarity index 89%
rename from src/rsvg_port.c
rename to src/rsvg-port.c
index bb2aa7f..a08fbb3 100644
--- a/src/rsvg_port.c
+++ b/src/rsvg-port.c
@@ -1,6 +1,6 @@
/****************************************************************************
*
- * rsvg_port.h
+ * rsvg-port.h
*
* Librsvg based hook functions for OT-SVG rendering in FreeType.
* (implementation)
@@ -18,7 +18,7 @@
#include <cairo.h>
#include <librsvg/rsvg.h>
-#include <rsvg_port.h>
+#include <rsvg-port.h>
#include <ft2build.h>
#include <stdlib.h>
#include <math.h>
@@ -47,10 +47,10 @@
* Freeing up the state structure.
*/
void
- rsvg_port_free( FT_Pointer state)
+ rsvg_port_free( FT_Pointer *state)
{
/* free the memory of the state structure */
- free( state );
+ free( *state );
}
/**
@@ -61,7 +61,7 @@
*/
FT_Error
- rsvg_port_render( FT_GlyphSlot slot, FT_Pointer _state )
+ rsvg_port_render( FT_GlyphSlot slot, FT_Pointer * _state )
{
FT_Error error = FT_Err_Ok;
@@ -70,7 +70,7 @@
cairo_t *cr;
cairo_surface_t *surface;
- state = (Rsvg_Port_State)_state;
+ state = *(Rsvg_Port_State*)_state;
/* create an image surface to store the rendered image, however,
* don't allocate memory, instead use the space already provided
@@ -136,7 +136,7 @@
* client applications.
*/
FT_Error
- rsvg_port_preset_slot( FT_GlyphSlot slot, FT_Bool cache, FT_Pointer _state
)
+ rsvg_port_preset_slot( FT_GlyphSlot slot, FT_Bool cache, FT_Pointer
*_state )
{
/* FreeType variables */
FT_Error error = FT_Err_Ok;
@@ -178,12 +178,20 @@
double x_svg_to_out;
double y_svg_to_out;
+ float metrics_width;
+ float metrics_height;
+ float horiBearingX;
+ float horiBearingY;
+ float vertBearingX;
+ float vertBearingY;
+ float vertical_advance;
+
/* if cache is `TRUE` we store calculations in the actual port
* state variable, otherwise we just create a dummy variable and
* store there. This saves from too many if statements.
*/
if ( cache )
- state = (Rsvg_Port_State)_state;
+ state = *(Rsvg_Port_State*)_state;
else
state = &state_dummy;
@@ -334,6 +342,25 @@
slot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
+ /* let's compute all the bearings and set them correctly.
+ * The outline is scaled already, we just need to use the
+ * bounding box now.
+ */
+ metrics_width = width;
+ metrics_height = height;
+ horiBearingX = state->x;
+ horiBearingY = state->y * -1;
+ vertBearingX = (slot->metrics.horiBearingX / (1 << 6)) -
((slot->metrics.horiAdvance / (1 << 6)) / 2.0);
+ vertBearingY = ((slot->metrics.vertAdvance / (1 << 6)) -
(slot->metrics.height / (1 << 6)))/2.0;
+ slot->metrics.width = round(metrics_width * (1 << 6));
+ slot->metrics.height = round(metrics_height * (1 << 6));
+ slot->metrics.horiBearingX = horiBearingX * (1 << 6);
+ slot->metrics.horiBearingY = horiBearingY * (1 << 6);
+ slot->metrics.vertBearingX = vertBearingX * (1 << 6);
+ slot->metrics.vertBearingY = vertBearingY * (1 << 6);
+ if(slot->metrics.vertAdvance == 0)
+ slot->metrics.vertAdvance = metrics_height * 1.2 * (1 << 6);
+
/* if a render call is to follow, just destroy the context for the
* recording surface, since no more drawing will be done on it, but,
* keep the surface itself for use by the render hook.
diff --git a/src/rsvg_port.h b/src/rsvg-port.h
similarity index 90%
rename from src/rsvg_port.h
rename to src/rsvg-port.h
index cb10a4b..2d6ff25 100644
--- a/src/rsvg_port.h
+++ b/src/rsvg-port.h
@@ -1,6 +1,6 @@
/****************************************************************************
*
- * rsvg_port.h
+ * rsvg-port.h
*
* Librsvg based hook functions for OT-SVG rendering in FreeType. (headers)
*
@@ -40,15 +40,15 @@
rsvg_port_init( FT_Pointer *state);
void
- rsvg_port_free( FT_Pointer state );
+ rsvg_port_free( FT_Pointer *state );
FT_Error
rsvg_port_render( FT_GlyphSlot slot,
- FT_Pointer state );
+ FT_Pointer *state );
FT_Error
rsvg_port_preset_slot( FT_GlyphSlot slot,
FT_Bool cache,
- FT_Pointer state);
+ FT_Pointer *state);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] wl/freetype-demos-support-ot-svg-glyphs-new 00e3468 2/5: Rename the files and update the hooks.,
Werner Lemberg <=