[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/FreetypeGlyphsProvider.c...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/FreetypeGlyphsProvider.c... |
Date: |
Wed, 13 Jun 2007 16:30:53 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/06/13 16:30:53
Modified files:
. : ChangeLog
server : FreetypeGlyphsProvider.cpp
FreetypeGlyphsProvider.h
Log message:
* server/FreetypeGlyphsProvider.{cpp,h}: document coordinate
space of
getGlyph output values and implement proper scaling between
freetype
glyph EM units and our 1024 EM square.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3526&r2=1.3527
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeGlyphsProvider.cpp?cvsroot=gnash&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeGlyphsProvider.h?cvsroot=gnash&r1=1.1&r2=1.2
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3526
retrieving revision 1.3527
diff -u -b -r1.3526 -r1.3527
--- ChangeLog 13 Jun 2007 15:17:29 -0000 1.3526
+++ ChangeLog 13 Jun 2007 16:30:52 -0000 1.3527
@@ -1,5 +1,11 @@
2007-06-13 Sandro Santilli <address@hidden>
+ * server/FreetypeGlyphsProvider.{cpp,h}: document coordinate space of
+ getGlyph output values and implement proper scaling between freetype
+ glyph EM units and our 1024 EM square.
+
+2007-06-13 Sandro Santilli <address@hidden>
+
* server/: font.{cpp,h}, Makefile.am, FreetypeRasterizer.{cpp,h},
FreetypeGlyphsProvider.{cpp,h}: renamed file and class since
we won't serve rendered glyphs anymore. Rendered glyphs can
Index: server/FreetypeGlyphsProvider.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeGlyphsProvider.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- server/FreetypeGlyphsProvider.cpp 13 Jun 2007 15:17:30 -0000 1.1
+++ server/FreetypeGlyphsProvider.cpp 13 Jun 2007 16:30:52 -0000 1.2
@@ -50,53 +50,110 @@
// Define the following to make outline decomposition verbose
//#define DEBUG_OUTLINE_DECOMPOSITION 1
-// Define the following to make glyph rendering verbose
-//#define DEBUG_GLYPH_RENDERING 1
-
-// TODO: drop this ?
-#define FREETYPE_MAX_FONTSIZE 96
-
namespace gnash {
#ifdef HAVE_FREETYPE2
-static int
-walkMoveTo(FT_Vector* to, void* ptr)
-{
- DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+/// Outline glyph walker/decomposer, for drawing an FT_Outline to DynamicShape
+//
+/// See FT_Outline_Decompose function of freetype2 lib
+///
+class OutlineWalker {
+
+public:
+
+ /// Create an outline walker drawing to the given DynamiShape
+ //
+ /// @param sh
+ /// The DynamiShape to draw to. Externally owned.
+ ///
+ /// @param scale
+ /// The scale to apply to coordinates.
+ /// This is to match an EM of 1024x1024 when units_per_EM
+ /// are of a different value.
+ ///
+ OutlineWalker(DynamicShape& sh, float scale)
+ :
+ _sh(sh),
+ _scale(scale)
+ {}
+
+ ~OutlineWalker() {}
+
+ /// Callback function for the move_to member of FT_Outline_Funcs
+ static int
+ walkMoveTo(FT_Vector* to, void* ptr)
+ {
+ OutlineWalker* walker = static_cast<OutlineWalker*>(ptr);
+ return walker->moveTo(to);
+ }
+
+ /// Callback function for the line_to member of FT_Outline_Funcs
+ static int
+ walkLineTo(FT_Vector* to, void* ptr)
+ {
+ OutlineWalker* walker = static_cast<OutlineWalker*>(ptr);
+ return walker->lineTo(to);
+ }
+
+ /// Callback function for the conic_to member of FT_Outline_Funcs
+ static int
+ walkConicTo(FT_Vector* ctrl, FT_Vector* to, void* ptr)
+ {
+ OutlineWalker* walker = static_cast<OutlineWalker*>(ptr);
+ return walker->conicTo(ctrl, to);
+ }
+
+ /// Callback function for the cubic_to member of FT_Outline_Funcs
+ //
+ /// Transform the cubic curve into a quadratic one an interpolated point
+ /// falling in the middle of the two control points.
+ ///
+ static int
+ walkCubicTo(FT_Vector* ctrl1, FT_Vector* ctrl2, FT_Vector* to, void*
ptr)
+ {
+ OutlineWalker* walker = static_cast<OutlineWalker*>(ptr);
+ return walker->cubicTo(ctrl1, ctrl2, to);
+ }
+
+private:
+
+ DynamicShape& _sh;
+
+ float _scale;
+
+ int moveTo(FT_Vector* to)
+ {
#ifdef DEBUG_OUTLINE_DECOMPOSITION
log_debug("moveTo: %ld,%ld", to->x, to->y);
#endif
- sh->moveTo(to->x, -to->y);
+ _sh.moveTo(to->x*_scale, -to->y*_scale);
return 0;
-}
+ }
-static int
-walkLineTo(FT_Vector* to, void* ptr)
-{
- DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+ int
+ lineTo(FT_Vector* to)
+ {
#ifdef DEBUG_OUTLINE_DECOMPOSITION
log_debug("lineTo: %ld,%ld", to->x, to->y);
#endif
- sh->lineTo(to->x, -to->y);
+ _sh.lineTo(to->x*_scale, -to->y*_scale);
return 0;
-}
+ }
-static int
-walkConicTo(FT_Vector* ctrl, FT_Vector* to, void* ptr)
-{
- DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+ int
+ conicTo(FT_Vector* ctrl, FT_Vector* to)
+ {
#ifdef DEBUG_OUTLINE_DECOMPOSITION
log_debug("conicTo: %ld,%ld %ld,%ld", ctrl->x, ctrl->y, to->x, to->y);
#endif
- sh->curveTo(ctrl->x, -ctrl->y, to->x, -to->y);
+ _sh.curveTo(ctrl->x*_scale, -ctrl->y*_scale, to->x*_scale,
-to->y*_scale);
return 0;
-}
+ }
-static int
-walkCubicTo(FT_Vector* ctrl1, FT_Vector* ctrl2, FT_Vector* to, void* ptr)
-{
- DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+ int
+ cubicTo(FT_Vector* ctrl1, FT_Vector* ctrl2, FT_Vector* to)
+ {
#ifdef DEBUG_OUTLINE_DECOMPOSITION
log_debug("cubicTo: %ld,%ld %ld,%ld %ld,%ld", ctrl1->x, ctrl1->y,
ctrl2->x, ctrl2->y, to->x, to->y);
#endif
@@ -104,10 +161,12 @@
float x = ctrl1->x + ( (ctrl2->x - ctrl1->x) * 0.5 );
float y = ctrl1->y + ( (ctrl2->y - ctrl1->y) * 0.5 );
- sh->curveTo(x, -y, to->x, -to->y);
-
+ _sh.curveTo(x*_scale, -y*_scale, to->x*_scale, -to->y*_scale);
return 0;
-}
+ }
+
+
+};
// static
FT_Library FreetypeGlyphsProvider::m_lib;
@@ -160,20 +219,6 @@
return alpha;
}
-#if 0
-// private
-float
-FreetypeGlyphsProvider::get_advance_x(uint16_t code)
-{
- FT_Set_Pixel_Sizes(m_face, 0, FREETYPE_MAX_FONTSIZE);
- if (FT_Load_Char(m_face, code, FT_LOAD_RENDER))
- {
- return 0;
- }
- return (float) m_face->glyph->metrics.horiAdvance * s_advance_scale;
-}
-#endif
-
// private
bool
FreetypeGlyphsProvider::getFontFilename(const std::string& name,
@@ -312,6 +357,12 @@
throw GnashException(buf);
break;
}
+
+ // We want an EM of 1024, so if units_per_EM is different
+ // we will scale
+ scale = 1024.0f/m_face->units_per_EM;
+
+ log_debug("EM square for font '%s' is %d, scale is thus %g",
name.c_str(), m_face->units_per_EM, scale);
}
#else // ndef(HAVE_FREETYPE2)
FreetypeGlyphsProvider::FreetypeGlyphsProvider(const std::string&, bool, bool)
@@ -333,8 +384,8 @@
return sh.get();
}
- // TODO: check this. Also check FT_FaceRec::units_per_EM
- advance = m_face->glyph->metrics.horiAdvance;
+ // Scale advance by current scale, to match expected output coordinate
space
+ advance = m_face->glyph->metrics.horiAdvance * scale;
assert(m_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE);
@@ -349,19 +400,23 @@
sh->beginFill(rgba(255, 255, 255, 255));
FT_Outline_Funcs walk;
- walk.move_to = walkMoveTo;
- walk.line_to = walkLineTo;
- walk.conic_to = walkConicTo;
- walk.cubic_to = walkCubicTo;
+ walk.move_to = OutlineWalker::walkMoveTo;
+ walk.line_to = OutlineWalker::walkLineTo;
+ walk.conic_to = OutlineWalker::walkConicTo;
+ walk.cubic_to = OutlineWalker::walkCubicTo;
walk.shift = 0; // ?
walk.delta = 0; // ?
#ifdef DEBUG_OUTLINE_DECOMPOSITION
log_debug("Decomposing glyph outline for character %u", code);
#endif
- FT_Outline_Decompose(outline, &walk, sh.get());
+
+ OutlineWalker walker(*sh, scale);
+
+ FT_Outline_Decompose(outline, &walk, &walker);
#ifdef DEBUG_OUTLINE_DECOMPOSITION
- log_msg("Decomposed glyph for character '%c' has bounds %s", code,
sh->get_bound().toString().c_str());
+ rect bound; sh->compute_bound(&bound);
+ log_msg("Decomposed glyph for character '%c' has bounds %s", code,
bound.toString().c_str());
#endif
return sh.get();
Index: server/FreetypeGlyphsProvider.h
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeGlyphsProvider.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- server/FreetypeGlyphsProvider.h 13 Jun 2007 15:17:30 -0000 1.1
+++ server/FreetypeGlyphsProvider.h 13 Jun 2007 16:30:53 -0000 1.2
@@ -88,17 +88,20 @@
///
static std::auto_ptr<FreetypeGlyphsProvider> createFace(const
std::string& name, bool bold, bool italic);
- /// Return the given character glyph as a shape character definition
+ /// Return the given character glyph as a shape character definition in
1024 EM coordinates.
//
+ ///
+ /// TODO: allow using a custom EM square ?
+ ///
/// @param code
/// Character code.
///
/// @param advance
/// Output parameter... units to advance horizontally from this
glyph to the next,
- /// in EM units.
+ /// in 1024 EM units.
///
- /// @return A shape_character_def, or a NULL pointer if the given
character code
- /// doesn't exist in this font.
+ /// @return A shape_character_def in 1024 EM coordinates, or a NULL
pointer if the given
+ /// character code doesn't exist in this font.
///
boost::intrusive_ptr<shape_character_def> getGlyph(uint16_t code,
float& advance);
@@ -113,8 +116,11 @@
#ifdef HAVE_FREETYPE2
- // TODO: drop ?
- //float get_advance_x(uint16_t code);
+ /// Scale factor to make the freetype glyph metrix match our 1024 EM
square
+ /// coordinate space. Not all font faces have am EM square of 1024, so
we
+ /// use this value to scale both coordinates and advance values
+ /// The value is computed by the costructor, as soon as a face is
initialized.
+ float scale;
/// Get filename containing given font
//
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/FreetypeGlyphsProvider.c...,
Sandro Santilli <=