gnash-commit
[Top][All Lists]
Advanced

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

Re: [Gnash-commit] gnash ChangeLog server/FreetypeGlyphsProvider.c...


From: zou lunkai
Subject: Re: [Gnash-commit] gnash ChangeLog server/FreetypeGlyphsProvider.c...
Date: Fri, 18 Apr 2008 08:48:56 +0800

> don't assume EM square is 1024x1024, fetch from font instead

Confirmed, I do have some font files with 2048X2048 EM square on my system.

--zou

On 4/18/08, Sandro Santilli <address@hidden> wrote:
> CVSROOT:        /sources/gnash
> Module name:    gnash
> Changes by:     Sandro Santilli <strk>  08/04/17 16:24:08
>
> Modified files:
>        .              : ChangeLog
>        server         : FreetypeGlyphsProvider.cpp
>                         FreetypeGlyphsProvider.h
>                         edit_text_character.cpp font.cpp font.h
>                         text.cpp
>
> Log message:
>        * server/FreetypeGlyphsProvider.{cpp,h}: add a unitsPerEM() method
>          to retrive the nominal EM square size. Currently always 1024
>          but could theoretically match the underlying freetype EM square.
>        * server/font.{cpp,h}: add a unitsPerEM() method workign both
>          for device and embedde fonts, both DEFINEFONT kinds (small
>          and largs).
>        * server/edit_text_character.cpp, server/text.cpp:
>          don't assume EM square is 1024x1024, fetch from font instead.
>          Fixes bug #22965.
>
> CVSWeb URLs:
> http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6317&r2=1.6318
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeGlyphsProvider.cpp?cvsroot=gnash&r1=1.22&r2=1.23
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/FreetypeGlyphsProvider.h?cvsroot=gnash&r1=1.8&r2=1.9
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/edit_text_character.cpp?cvsroot=gnash&r1=1.173&r2=1.174
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.cpp?cvsroot=gnash&r1=1.62&r2=1.63
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/font.h?cvsroot=gnash&r1=1.37&r2=1.38
> http://cvs.savannah.gnu.org/viewcvs/gnash/server/text.cpp?cvsroot=gnash&r1=1.49&r2=1.50
>
> Patches:
> Index: ChangeLog
> ===================================================================
> RCS file: /sources/gnash/gnash/ChangeLog,v
> retrieving revision 1.6317
> retrieving revision 1.6318
> diff -u -b -r1.6317 -r1.6318
> --- ChangeLog   17 Apr 2008 12:39:21 -0000      1.6317
> +++ ChangeLog   17 Apr 2008 16:24:04 -0000      1.6318
> @@ -1,3 +1,15 @@
> +2008-04-17 Sandro Santilli <address@hidden>
> +
> +       * server/FreetypeGlyphsProvider.{cpp,h}: add a unitsPerEM() method
> +         to retrive the nominal EM square size. Currently always 1024
> +         but could theoretically match the underlying freetype EM square.
> +       * server/font.{cpp,h}: add a unitsPerEM() method workign both
> +         for device and embedde fonts, both DEFINEFONT kinds (small
> +         and largs).
> +       * server/edit_text_character.cpp, server/text.cpp:
> +         don't assume EM square is 1024x1024, fetch from font instead.
> +         Fixes bug #22965.
> +
>  2008-04-17 Benjamin Wolsey <address@hidden>
>
>        * testsuite/actionscript.all/case.as: test for case collision
>
> Index: server/FreetypeGlyphsProvider.cpp
> ===================================================================
> RCS file: /sources/gnash/gnash/server/FreetypeGlyphsProvider.cpp,v
> retrieving revision 1.22
> retrieving revision 1.23
> diff -u -b -r1.22 -r1.23
> --- server/FreetypeGlyphsProvider.cpp   16 Apr 2008 11:54:46 -0000      1.22
> +++ server/FreetypeGlyphsProvider.cpp   17 Apr 2008 16:24:06 -0000      1.23
> @@ -80,8 +80,7 @@
>        ///
>        /// @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.
> +       ///     This is to match an arbitrary EM
>        ///
>        OutlineWalker(DynamicShape& sh, float scale)
>                :
> @@ -386,9 +385,9 @@
>                        break;
>        }
>
> -       // We want an EM of 1024, so if units_per_EM is different
> +       // We want an EM of unitsPerEM, so if units_per_EM is different
>        // we will scale
> -       scale = 1024.0f/m_face->units_per_EM;
> +       scale = (float)unitsPerEM()/m_face->units_per_EM;
>
>  #ifdef GNASH_DEBUG_DEVICEFONTS
>        log_debug("EM square for font '%s' is %d, scale is thus %g", 
> name.c_str(), m_face->units_per_EM, scale);
>
> Index: server/FreetypeGlyphsProvider.h
> ===================================================================
> RCS file: /sources/gnash/gnash/server/FreetypeGlyphsProvider.h,v
> retrieving revision 1.8
> retrieving revision 1.9
> diff -u -b -r1.8 -r1.9
> --- server/FreetypeGlyphsProvider.h     27 Mar 2008 10:50:13 -0000      1.8
> +++ server/FreetypeGlyphsProvider.h     17 Apr 2008 16:24:07 -0000      1.9
> @@ -86,7 +86,9 @@
>        ~FreetypeGlyphsProvider();
>
>
> -       /// Return the given character glyph as a shape character definition 
> in 1024 EM coordinates.
> +       /// \brief
> +       /// Return the given character glyph as a shape character definition
> +       /// in unitsPerEM() coordinates.
>        //
>        ///
>        /// TODO: allow using a custom EM square ?
> @@ -95,14 +97,21 @@
>        ///     Character code.
>        ///
>        /// @param advance
> -       ///     Output parameter... units to advance horizontally from this 
> glyph to the next,
> -       ///     in 1024 EM units.
> +       ///     Output parameter... units to advance horizontally from this
> +       ///     glyph to the next, in unitsPerEM() units.
>        ///
> -       /// @return A shape_character_def in 1024 EM coordinates, or a NULL 
> pointer if the given
> -       ///         character code doesn't exist in this font.
> +       /// @return A shape_character_def in unitsPerEM() coordinates,
> +       ///         or a NULL pointer if the given character code
> +       ///         doesn't exist in this font.
>        ///
>        boost::intrusive_ptr<shape_character_def> getGlyph(boost::uint16_t 
> code, float& advance);
>
> +       /// Return the number of units of glyphs EM
> +       //
> +       /// This is currently hard-coded to 1024, but could in future depend
> +       /// on actual font file being used.
> +       ///
> +       unsigned short unitsPerEM() const { return 1024; }
>
>  private:
>
> @@ -114,8 +123,8 @@
>
>  #ifdef USE_FREETYPE
>
> -       /// 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
> +       /// Scale factor to make the freetype glyph metrix match our 
> unitsPerEM()
> +       /// coordinate space. Not all font faces have am EM square of 
> unitsPerEM(), 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;
>
> Index: server/edit_text_character.cpp
> ===================================================================
> RCS file: /sources/gnash/gnash/server/edit_text_character.cpp,v
> retrieving revision 1.173
> retrieving revision 1.174
> diff -u -b -r1.173 -r1.174
> --- server/edit_text_character.cpp      11 Apr 2008 09:58:41 -0000      1.173
> +++ server/edit_text_character.cpp      17 Apr 2008 16:24:07 -0000      1.174
> @@ -651,6 +651,7 @@
>        }
>
>
> +       //log_debug("Displaying glyph records for textfield %s", getTarget());
>        display_glyph_records(m, this, m_text_glyph_records,
>                              m_def->get_root_def(), _embedFonts);
>
> @@ -1281,15 +1282,17 @@
>        }
>
>        boost::uint16_t fontHeight = getFontHeight();
> -       float scale = fontHeight / 1024.0f;     // the EM square is 1024 x 
> 1024
> -       float fontDescent = _font->get_descent() * scale;
> -       float fontLeading = _font->get_leading() * scale;
> +       float scale = fontHeight / (float)_font->unitsPerEM(_embedFonts);
> +       float fontDescent = _embedFonts ? (_font->get_descent()*scale) : 0; 
> // TODO: fetch descent from device fonts as well ?
> +       float fontLeading = _embedFonts ? (_font->get_leading()*scale) : 0;  
> // TODO: fetch leading from device fonts as well ?
>        boost::uint16_t leftMargin = getLeftMargin();
>        boost::uint16_t rightMargin = getRightMargin();
>        boost::uint16_t indent = getIndent();
>        boost::uint16_t blockIndent = getBlockIndent();
>        bool underlined = getUnderlined();
>
> +       //log_debug("%s: fontDescent:%g, fontLeading:%g, fontHeight:%g, 
> scale:%g", getTarget(), fontDescent, fontLeading, fontHeight, scale);
> +
>        text_glyph_record       rec;    // one to work on
>        rec.m_style.setFont(_font.get());
>        rec.m_style.setUnderlined(underlined);
>
> Index: server/font.cpp
> ===================================================================
> RCS file: /sources/gnash/gnash/server/font.cpp,v
> retrieving revision 1.62
> retrieving revision 1.63
> diff -u -b -r1.62 -r1.63
> --- server/font.cpp     10 Apr 2008 08:44:13 -0000      1.62
> +++ server/font.cpp     17 Apr 2008 16:24:07 -0000      1.63
> @@ -143,8 +143,10 @@
>                        assert (tag == SWF::DEFINEFONT2 || tag == 
> SWF::DEFINEFONT3);
>                        readDefineFont2_or_3(in, m);
>                        if (tag == SWF::DEFINEFONT3)
> +                       {
>                                m_subpixel_font = true;
>                }
> +               }
>
>                // TODO: initialize the deviceFontProvider only when needed ?
>                if ( ! m_name.empty() && ! initDeviceFontProvider() )
> @@ -544,6 +546,25 @@
>                return 0;
>        }
>
> +       unsigned short int font::unitsPerEM(bool embed) const
> +       {
> +               // the EM square is 1024 x 1024 for DefineFont up to 2
> +               // and 20 as much for DefineFont3 up
> +               if ( embed )
> +               {
> +                       if ( m_subpixel_font ) return 1024*20;
> +                       else return 1024;
> +               }
> +               else
> +               {
> +                       if ( ! _ftProvider.get() )
> +                       {
> +                               log_error("Device font provider was not 
> initialized, can't get unitsPerEM");
> +                               return 0; // can't query it..
> +                       }
> +                       return _ftProvider->unitsPerEM();
> +               }
> +       }
>
>        int
>        font::add_os_glyph(boost::uint16_t code)
>
> Index: server/font.h
> ===================================================================
> RCS file: /sources/gnash/gnash/server/font.h,v
> retrieving revision 1.37
> retrieving revision 1.38
> diff -u -b -r1.37 -r1.38
> --- server/font.h       10 Apr 2008 08:44:14 -0000      1.37
> +++ server/font.h       17 Apr 2008 16:24:08 -0000      1.38
> @@ -237,6 +237,14 @@
>        ///
>        float   get_kerning_adjustment(int last_code, int this_code) const;
>
> +       /// Return height of the EM square used for glyphs definition
> +       //
> +       /// @param embedded
> +       ///     If true, return is based on the SWF tag the font
> +       ///     was read from, otherwise will query the FreeTypeGlyphsProvider
> +       ///
> +       unsigned short int unitsPerEM(bool embedded) const;
> +
>        float   get_leading() const { return m_leading; }
>        float   get_descent() const { return m_descent; }
>
>
> Index: server/text.cpp
> ===================================================================
> RCS file: /sources/gnash/gnash/server/text.cpp,v
> retrieving revision 1.49
> retrieving revision 1.50
> diff -u -b -r1.49 -r1.50
> --- server/text.cpp     11 Apr 2008 15:48:21 -0000      1.49
> +++ server/text.cpp     17 Apr 2008 16:24:08 -0000      1.50
> @@ -118,9 +118,10 @@
>                                continue;
>                        }
>
> -                       float   scale = 1.0f;
> -                       scale = rec.m_style.m_text_height / 1024.0f;    // 
> the EM square is 1024 x 1024
> -                       if (fnt->is_subpixel_font()) scale*=0.05f;
> +                       // unitsPerEM returns an int, we cast to float to get
> +                       // a float division
> +                       float unitsPerEM = fnt->unitsPerEM(useEmbeddedGlyphs);
> +                       float scale = rec.m_style.m_text_height / unitsPerEM;
>
>  #ifdef GNASH_DEBUG_TEXT_RENDERING
>                        log_debug("font for record %u == %p", i, (const 
> void*)fnt);
> @@ -129,7 +130,7 @@
>                        if ( rec.m_style.hasXOffset() ) x = 
> rec.m_style.getXOffset();
>                        if ( rec.m_style.hasYOffset() ) y = 
> rec.m_style.getYOffset();
>
> -                       float startX = x; // for the underline, if any
> +                       boost::int16_t startX = x; // for the underline, if 
> any
>
>                        s_dummy_style[0].set_color(rec.m_style.m_color);
>
> @@ -158,6 +159,11 @@
>                                        // We'll use about half the width, and 
> around 3/4 the height.
>                                        // Values adjusted by eye.
>                                        // The Y baseline is at 0; negative Y 
> is up.
> +                                       //
> +                                       // TODO: FIXME (if we'll ever enable 
> it back): the EM
> +                                       //       square is not hard-coded 
> anymore but can be
> +                                       //       queried from the font class
> +                                       //
>                                        static const boost::int16_t     
> s_empty_char_box[5 * 2] =
>                                        {
>                                                 32,   32,
> @@ -203,7 +209,9 @@
>                                // The underline is made to be some pixels 
> below the baseline (0)
>                                // and scaled so it's further as font size 
> increases.
>                                //
> -                               boost::int16_t posY = 
> int(y+int(256.0*scale)); // some offset far from baseline (should this be 
> scaled on font size?)
> +                               // 1/4 the EM square offset far from baseline
> +                               boost::int16_t posY = 
> int(y+int((unitsPerEM/4)*scale));
> +
>                                boost::int16_t underline[2 * 2] =
>                                {
>                                        startX,   posY,
>
>
> _______________________________________________
> Gnash-commit mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnash-commit
>




reply via email to

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