[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/FreetypeRasterizer.cpp s...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/FreetypeRasterizer.cpp s... |
Date: |
Wed, 13 Jun 2007 02:24:43 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/06/13 02:24:42
Modified files:
. : ChangeLog
server : FreetypeRasterizer.cpp FreetypeRasterizer.h
font.cpp
Log message:
* server/FreetypeRasterizer.{cpp,h}: Implement
shape_character_def
output using DynamicShape; changed getGlyph method to also
take
an 'advance' output parameter (toward deprecation of bitmap
output).
* server/font.cpp (add_os_glyph): update call to ::getGlyph.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3515&r2=1.3516
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeRasterizer.cpp?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeRasterizer.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.cpp?cvsroot=gnash&r1=1.34&r2=1.35
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3515
retrieving revision 1.3516
diff -u -b -r1.3515 -r1.3516
--- ChangeLog 13 Jun 2007 00:18:44 -0000 1.3515
+++ ChangeLog 13 Jun 2007 02:24:42 -0000 1.3516
@@ -1,5 +1,12 @@
2007-06-13 Sandro Santilli <address@hidden>
+ * server/FreetypeRasterizer.{cpp,h}: Implement shape_character_def
+ output using DynamicShape; changed getGlyph method to also take
+ an 'advance' output parameter (toward deprecation of bitmap output).
+ * server/font.cpp (add_os_glyph): update call to ::getGlyph.
+
+2007-06-13 Sandro Santilli <address@hidden>
+
* server/FreetypeRasterizer.{cpp,h}: added interface
to fetch vectorial glyph (just a stub).
* server/font.cpp (add_os_glyph): fetch both rasterized
Index: server/FreetypeRasterizer.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeRasterizer.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- server/FreetypeRasterizer.cpp 13 Jun 2007 00:17:44 -0000 1.6
+++ server/FreetypeRasterizer.cpp 13 Jun 2007 02:24:42 -0000 1.7
@@ -18,16 +18,75 @@
#include "DynamicShape.h"
#include "log.h"
+#ifdef HAVE_FREETYPE2
+# include <ft2build.h>
+# include FT_OUTLINE_H
+# include FT_BBOX_H
+#endif
+
#include <cstdio> // for snprintf
#include <string>
#include <memory> // for auto_ptr
+// Define the following to make outline decomposition verbose
+//#define DEBUG_OUTLINE_DECOMPOSITION 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);
+#ifdef DEBUG_OUTLINE_DECOMPOSITION
+ log_debug("moveTo: %ld,%ld", to->x, to->y);
+#endif
+ sh->moveTo(to->x, -to->y);
+ return 0;
+}
+
+static int
+walkLineTo(FT_Vector* to, void* ptr)
+{
+ DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+#ifdef DEBUG_OUTLINE_DECOMPOSITION
+ log_debug("lineTo: %ld,%ld", to->x, to->y);
+#endif
+ sh->lineTo(to->x, -to->y);
+ return 0;
+}
+
+static int
+walkConicTo(FT_Vector* ctrl, FT_Vector* to, void* ptr)
+{
+ DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+#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);
+ return 0;
+}
+
+static int
+walkCubicTo(FT_Vector* ctrl1, FT_Vector* ctrl2, FT_Vector* to, void* ptr)
+{
+ DynamicShape* sh = static_cast<DynamicShape*>(ptr);
+#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
+
+ 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);
+
+ return 0;
+}
+
// static
FT_Library FreetypeRasterizer::m_lib;
@@ -95,8 +154,8 @@
// private
bool
-FreetypeRasterizer::getFontFilename(const std::string& name,
- bool bold, bool italic, std::string& filename)
+FreetypeRasterizer::getFontFilename(const std::string& /*name*/,
+ bool /*bold*/, bool /*italic*/, std::string& filename)
{
#define DEFAULT_FONTFILE "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
@@ -207,7 +266,7 @@
log_debug("image::alpha drawn for character glyph '%c' bitmap has size
%dx%d", code, im->m_width, im->m_height);
log_debug("ttf bitmap glyph width:%d, rows:%d", bitmap.width,
bitmap.rows);
- log_debug("ttf glyph metrics width:%d, height:%d", metrics.width,
metrics.height);
+ log_debug("ttf glyph metrics width:%ld, height:%ld", metrics.width,
metrics.height);
log_debug("ttf glyph metrics X bearing:%ld, Y bearing:%ld",
metrics.horiBearingX, metrics.horiBearingY);
bi = render::create_bitmap_info_alpha(im->m_width, im->m_height,
im->m_data);
@@ -232,6 +291,7 @@
box.set_null();
}
+ // TODO: check this. Also check FT_FaceRec::units_per_EM
static float s_advance_scale = 0.16666666f; //vv hack
advance = (float) m_face->glyph->metrics.horiAdvance * s_advance_scale;
@@ -250,41 +310,47 @@
#ifdef HAVE_FREETYPE2
boost::intrusive_ptr<shape_character_def>
-FreetypeRasterizer::getGlyph(uint16_t code)
+FreetypeRasterizer::getGlyph(uint16_t code, float& advance)
{
boost::intrusive_ptr<DynamicShape> sh;
- //return sh;
- FT_Set_Pixel_Sizes(m_face, 0, FREETYPE_MAX_FONTSIZE);
- FT_Error error = FT_Load_Char(m_face, code, FT_LOAD_NO_BITMAP);
- //error = FT_Load_Char(m_face, code, FT_LOAD_RENDER);
+ FT_Error error = FT_Load_Char(m_face, code,
FT_LOAD_NO_BITMAP|FT_LOAD_NO_SCALE);
if ( error != 0 )
{
log_error("Error loading freetype outline glyph for char '%c'
(error: %d)", code, error);
return sh.get();
}
- assert(m_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE);
+ // TODO: check this. Also check FT_FaceRec::units_per_EM
+ advance = m_face->glyph->metrics.horiAdvance;
- sh = new DynamicShape();
+ assert(m_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE);
- // TODO: implement proper conversion,
- // this is just a placeholder
+ FT_Outline* outline = &(m_face->glyph->outline);
- int width=80*20;
- int height=100*20;
+ FT_BBox glyphBox;
+ FT_Outline_Get_BBox(outline, &glyphBox);
+ rect r(glyphBox.xMin, glyphBox.yMin, glyphBox.xMax, glyphBox.yMax);
+ log_msg("Glyph for character '%c' has computed bounds %s", code,
r.toString().c_str());
- //sh->lineStyle(1, rgba(255, 255, 255, 255));
+ sh = new DynamicShape();
sh->beginFill(rgba(255, 255, 255, 255));
- sh->moveTo(0, 0);
- sh->lineTo(0, height);
- sh->lineTo(width, height);
- sh->lineTo(width, 0);
- sh->lineTo(0, 0);
- sh->endFill();
+ FT_Outline_Funcs walk;
+ walk.move_to = walkMoveTo;
+ walk.line_to = walkLineTo;
+ walk.conic_to = walkConicTo;
+ walk.cubic_to = walkCubicTo;
+ walk.shift = 0; // ?
+ walk.delta = 0; // ?
- sh->finalize();
+#ifdef DEBUG_OUTLINE_DECOMPOSITION
+ log_debug("Decomposing glyph outline for character %u", code);
+#endif
+ FT_Outline_Decompose(outline, &walk, sh.get());
+#ifdef DEBUG_OUTLINE_DECOMPOSITION
+ log_msg("Decomposed glyph for character '%c' has bounds %s", code,
sh->get_bound().toString().c_str());
+#endif
return sh.get();
}
Index: server/FreetypeRasterizer.h
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeRasterizer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- server/FreetypeRasterizer.h 13 Jun 2007 00:17:44 -0000 1.4
+++ server/FreetypeRasterizer.h 13 Jun 2007 02:24:42 -0000 1.5
@@ -39,7 +39,7 @@
namespace gnash {
-/// Truetype font rasterizer based on freetype library
+/// Truetype font rasterizer/converter based on freetype library
//
/// Instances of this class provide rasterized or vectorial glyphs
/// for a given truetype font face.
@@ -51,6 +51,8 @@
/// Vectorial glyphs are instances of a shape_character_def, same class
/// resulting from parsing of embedded fonts.
///
+/// TODO: rename this class to something like FreetypeGlyphProvider...
+///
class FreetypeRasterizer
{
@@ -91,6 +93,8 @@
/// @return A bitmap_info, or a NULL pointer if the given character code
/// doesn't exist in this font.
///
+ /// TODO: drop ?
+ ///
boost::intrusive_ptr<bitmap_info> getRenderedGlyph(uint16_t code, rect&
box, float& advance);
/// Return the given character glyph as a shape character definition
@@ -98,10 +102,14 @@
/// @param code
/// Character code.
///
+ /// @param advance
+ /// Output parameter... TODO: describe what it is (units?)
+ ///
/// @return A shape_character_def, 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);
+ boost::intrusive_ptr<shape_character_def> getGlyph(uint16_t code,
float& advance);
+
private:
Index: server/font.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/font.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- server/font.cpp 13 Jun 2007 00:17:44 -0000 1.34
+++ server/font.cpp 13 Jun 2007 02:24:42 -0000 1.35
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-/* $Id: font.cpp,v 1.34 2007/06/13 00:17:44 strk Exp $ */
+/* $Id: font.cpp,v 1.35 2007/06/13 02:24:42 strk Exp $ */
// Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
@@ -564,11 +564,13 @@
assert ( _ftRasterizer.get() );
assert(m_code_table.find(code) == m_code_table.end());
+ float advance;
+
// Get the vectorial glyph
- boost::intrusive_ptr<shape_character_def> sh =
_ftRasterizer->getGlyph(code);
+ boost::intrusive_ptr<shape_character_def> sh =
_ftRasterizer->getGlyph(code, advance);
// Get the textured glyph and the advance info
- rect box; float advance;
+ rect box;
boost::intrusive_ptr<bitmap_info> bi (
_ftRasterizer->getRenderedGlyph(code, box, advance) );
if ( ! sh && ! bi )