gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash/server FreetypeRasterizer.cpp FreetypeRas...


From: Sandro Santilli
Subject: [Gnash-commit] gnash/server FreetypeRasterizer.cpp FreetypeRas...
Date: Wed, 13 Jun 2007 00:17:46 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/06/13 00:17:45

Modified files:
        server         : FreetypeRasterizer.cpp FreetypeRasterizer.h 
                         font.cpp fontlib.cpp text.cpp 

Log message:
                * server/FreetypeRasterizer.{cpp,h}: added interface
                  to fetch vectorial glyph (just a stub).
                * server/font.cpp (add_os_glyph): fetch both rasterized
                  and vectorial glyphs, survive to texture glyphs with a null
                  bound (space is one such glyph).
                * server/fontlib.cpp (draw_glyph): skip rendering of textured
                  glyphs with null bounds.
                * server/text.cpp (display_glyph_records): enable debugging by
                  default.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeRasterizer.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeRasterizer.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.cpp?cvsroot=gnash&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/gnash/server/fontlib.cpp?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/server/text.cpp?cvsroot=gnash&r1=1.29&r2=1.30

Patches:
Index: FreetypeRasterizer.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeRasterizer.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- FreetypeRasterizer.cpp      12 Jun 2007 23:00:18 -0000      1.5
+++ FreetypeRasterizer.cpp      13 Jun 2007 00:17:44 -0000      1.6
@@ -15,6 +15,7 @@
 #include "image.h" // for create_alpha
 #include "GnashException.h"
 #include "render.h"
+#include "DynamicShape.h"
 #include "log.h"
 
 #include <cstdio> // for snprintf
@@ -97,6 +98,11 @@
 FreetypeRasterizer::getFontFilename(const std::string& name,
                bool bold, bool italic, std::string& filename)
 {
+#define DEFAULT_FONTFILE "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
+
+       filename = DEFAULT_FONTFILE;
+       return true;
+
        // TODO: implement
        log_error("FIXME: font name to filename mapping unimplemented");
        return false;
@@ -186,20 +192,33 @@
        boost::intrusive_ptr<bitmap_info> bi;
 
        FT_Set_Pixel_Sizes(m_face, 0, FREETYPE_MAX_FONTSIZE);
-       if (FT_Load_Char(m_face, code, FT_LOAD_RENDER))
+       FT_Error error = FT_Load_Char(m_face, code, FT_LOAD_RENDER);
+       if ( error != 0 )
        {
+               log_error("Error loading freetype render glyph for char '%c' 
(error: %d)", code, error);
                return bi;
        }
 
+       FT_GlyphSlot glyph = m_face->glyph;
+       FT_Bitmap bitmap = glyph->bitmap;
+       FT_Glyph_Metrics metrics = glyph->metrics;
+
+       std::auto_ptr<image::alpha> im ( draw_bitmap(bitmap) );
+
+       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 X bearing:%ld, Y bearing:%ld", 
metrics.horiBearingX, metrics.horiBearingY);
 
-       std::auto_ptr<image::alpha> im ( draw_bitmap(m_face->glyph->bitmap) );
        bi = render::create_bitmap_info_alpha(im->m_width, im->m_height, 
im->m_data);
 
-       float xmax = float(m_face->glyph->bitmap.width) / float(im->m_width);
-       float ymax = float(m_face->glyph->bitmap.rows) / float(im->m_height);
+       if ( bitmap.width && bitmap.rows && metrics.width && metrics.height )
+       {
+               float xmax = float(bitmap.width) / float(im->m_width);
+               float ymax = float(bitmap.rows) / float(im->m_height);
 
-       float xmin = float(m_face->glyph->metrics.horiBearingX) / 
float(m_face->glyph->metrics.width);
-       float ymin = float(m_face->glyph->metrics.horiBearingY) / 
float(m_face->glyph->metrics.height);
+               float xmin = float(metrics.horiBearingX) / float(metrics.width);
+               float ymin = float(metrics.horiBearingY) / 
float(metrics.height);
 
        // ???
        xmin *= -xmax;
@@ -207,10 +226,18 @@
 
        box.enclose_point(xmin, ymin);
        box.expand_to_point(xmax, ymax);
+       }
+       else
+       {
+               box.set_null();
+       }
        
        static float s_advance_scale = 0.16666666f; //vv hack
        advance = (float) m_face->glyph->metrics.horiAdvance * s_advance_scale;
 
+       log_debug(" box: %s, advance: %g", box.toString().c_str(), advance);
+
+
        return bi;
 }
 #else // ndef(HAVE_FREETYPE2)
@@ -221,5 +248,53 @@
 }
 #endif // ndef(HAVE_FREETYPE2)
 
+#ifdef HAVE_FREETYPE2
+boost::intrusive_ptr<shape_character_def>
+FreetypeRasterizer::getGlyph(uint16_t code)
+{
+       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);
+       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);
+
+       sh = new DynamicShape();
+
+       // TODO: implement proper conversion,
+       //       this is just a placeholder
+
+       int width=80*20;
+       int height=100*20;
+
+       //sh->lineStyle(1, rgba(255, 255, 255, 255));
+       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();
+
+       sh->finalize();
+
+       return sh.get();
+}
+#else // ndef(HAVE_FREETYPE2)
+boost::intrusive_ptr<shape_character_def>
+FreetypeRasterizer::getGlyph(uint16_t)
+{
+       assert(0); // should never be called... 
+}
+#endif // ndef(HAVE_FREETYPE2)
+
 } // namespace gnash
 

Index: FreetypeRasterizer.h
===================================================================
RCS file: /sources/gnash/gnash/server/FreetypeRasterizer.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- FreetypeRasterizer.h        12 Jun 2007 12:33:21 -0000      1.3
+++ FreetypeRasterizer.h        13 Jun 2007 00:17:44 -0000      1.4
@@ -30,6 +30,7 @@
 // Forward declarations
 namespace gnash {
        class bitmap_info;
+       class shape_character_def;
 }
 namespace image {
        class alpha;
@@ -40,13 +41,16 @@
 
 /// Truetype font rasterizer based on freetype library
 //
-/// Instances of this class provide rasterized glyphs for a given
-/// truetype font face.
+/// Instances of this class provide rasterized or vectorial glyphs
+/// for a given truetype font face.
 ///
 /// The rasterized glyphs have a max size of 96 (TODO: make parametrizable)
 /// but I think the actual size could change between glyphs (see the 'box'
 /// parameter of getRenderedGlyph() method).
 ///
+/// Vectorial glyphs are instances of a shape_character_def, same class
+/// resulting from parsing of embedded fonts.
+///
 class FreetypeRasterizer 
 {
 
@@ -75,16 +79,30 @@
        ///     Character code.
        ///
        /// @param box
-       ///     Output parameter... TODO: describe what it is.
+       ///     Output parameter. Bounding box of glyph is returned here.
+       ///     TODO: document units, and more about what a bounding box is
+       ///     (ie: actual bounds of visible shape or including padding?).
+       ///     NOTE: can be the NULL bound, for non-visible characters 
+       ///     (space, tab, whatever else).
        ///
        /// @param advance
-       ///     Output parameter... TODO: describe what it is.
+       ///     Output parameter... TODO: describe what it is (units?)
        ///
        /// @return A bitmap_info, or a NULL pointer if the given character code
        ///         doesn't exist in this font.
        ///
        boost::intrusive_ptr<bitmap_info> getRenderedGlyph(uint16_t code, rect& 
box, float& advance);
 
+       /// Return the given character glyph as a shape character definition
+       //
+       /// @param code
+       ///     Character code.
+       ///
+       /// @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);
+
 private:
 
        /// Use the named constructor to create an instance

Index: font.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/font.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- font.cpp    12 Jun 2007 12:33:21 -0000      1.33
+++ font.cpp    13 Jun 2007 00:17:44 -0000      1.34
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: font.cpp,v 1.33 2007/06/12 12:33:21 strk Exp $ */
+/* $Id: font.cpp,v 1.34 2007/06/13 00:17:44 strk Exp $ */
 
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
@@ -564,31 +564,52 @@
                assert ( _ftRasterizer.get() );
                assert(m_code_table.find(code) == m_code_table.end());
 
-               rect box;
-               float advance;
+               // Get the vectorial glyph
+               boost::intrusive_ptr<shape_character_def> sh = 
_ftRasterizer->getGlyph(code);
+
+               // Get the textured glyph and the advance info
+               rect box; float advance;
                boost::intrusive_ptr<bitmap_info> bi ( 
_ftRasterizer->getRenderedGlyph(code, box, advance) );
 
-               if ( ! bi.get() )
+               if ( ! sh && ! bi )
                {
-                       log_error("Could not create glyph for character code %u 
with device font %s (%p)", code, m_name, _ftRasterizer.get());
+                       log_error("Could not create either bitmap or shape "
+                                       "glyph for character code %u (%c) with "
+                                       "device font %s (%p)", code, code, 
m_name,
+                                       _ftRasterizer.get());
                        return -1;
                }
 
                // Create textured glyph from the bitmap info
                texture_glyph tg;
+
+               if ( bi.get() )
+               {
+
+                       if ( ! box.is_null() )
+                       {
                tg.m_uv_bounds.enclose_point(0, 0);
                tg.m_uv_bounds.expand_to_point(box.get_x_max(), 
box.get_y_max());
                // the origin
                tg.m_uv_origin.m_x = box.get_x_min();
                tg.m_uv_origin.m_y = box.get_y_min();
+                       }
+                       else
+                       {
+                               tg.m_uv_bounds.set_null();
+                               tg.m_uv_origin.m_x = 0;
+                               tg.m_uv_origin.m_y = 0;
+                       }
                tg.set_bitmap_info(bi.get());
+               }
 
                // Add the textured glyph
                int newOffset = m_texture_glyphs.size();
                m_code_table[code] = newOffset;
                m_advance_table.push_back(advance);
                m_texture_glyphs.push_back(tg);
-               m_glyphs.push_back(NULL);
+
+               m_glyphs.push_back(sh);
 
                testInvariant();
 

Index: fontlib.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/fontlib.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- fontlib.cpp 11 Nov 2006 22:44:54 -0000      1.26
+++ fontlib.cpp 13 Jun 2007 00:17:45 -0000      1.27
@@ -5,7 +5,7 @@
 
 // A module to take care of all of gnash's loaded fonts.
 
-/* $Id: fontlib.cpp,v 1.26 2006/11/11 22:44:54 strk Exp $ */
+/* $Id: fontlib.cpp,v 1.27 2007/06/13 00:17:45 strk Exp $ */
 
 #include "container.h"
 #include "tu_file.h"
@@ -1309,6 +1309,12 @@
                // @@ worth it to precompute these bounds?
 
                rect    bounds = tg.m_uv_bounds;
+               if ( bounds.is_null() )
+               {
+                       log_debug("Textured glyph rendering skipped, since it's 
bounds are null");
+                       return;
+               }
+
                bounds.shift_x (-tg.m_uv_origin.m_x);
                bounds.shift_y (-tg.m_uv_origin.m_y);
 
@@ -1316,6 +1322,8 @@
                // @@ need to factor this out!
                static float    s_scale = GLYPH_CACHE_TEXTURE_SIZE * 
s_rendering_box / nominal_glyph_height;
 
+               log_msg("Scaling bounds %s by factor %g (nominal_glyph_height: 
%d)", bounds.toString().c_str(), s_scale, nominal_glyph_height);
+
                bounds.scale_x(s_scale);
                bounds.scale_y(s_scale);
                

Index: text.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/text.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- text.cpp    18 Apr 2007 11:00:29 -0000      1.29
+++ text.cpp    13 Jun 2007 00:17:45 -0000      1.30
@@ -17,14 +17,13 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: text.cpp,v 1.29 2007/04/18 11:00:29 jgilmore Exp $ */
+/* $Id: text.cpp,v 1.30 2007/06/13 00:17:45 strk Exp $ */
 
 // Based on the public domain work of Thatcher Ulrich <address@hidden> 2003
 
 #include "utf8.h"
 #include "utility.h"
 #include "impl.h"
-//#include "shape.h"
 #include "shape_character_def.h"
 #include "stream.h"
 #include "log.h"
@@ -35,6 +34,10 @@
 #include "text.h"
 #include "movie_definition.h"
 
+// Define the following macro to get debugging messages
+// for text rendering
+#define GNASH_DEBUG_TEXT_RENDERING 1
+
 namespace gnash {
 
        void text_style::resolve_font(movie_definition* root_def) const
@@ -178,7 +181,7 @@
                                            && (use_glyph_textures || glyph == 
NULL))
                                        {
 #ifdef GNASH_DEBUG_TEXT_RENDERING
-log_msg(_("render glyph using draw_glyph"));
+log_msg(_("render textured glyph (fontlib::draw_glyph)"));
 #endif
                                                fontlib::draw_glyph(mat, tg, 
transformed_color, nominal_glyph_height);
                                        }
@@ -189,7 +192,7 @@
                                                if (glyph)
                                                {
 #ifdef GNASH_DEBUG_TEXT_RENDERING
-log_msg(_("render glyph using filled outline (?) actually draw_glyph()"));
+log_msg(_("render shape glyph using filled outline (render::draw_glyph)"));
 #endif
 
                                                        
gnash::render::draw_glyph(glyph, mat, transformed_color, pixel_scale);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]