gfx/thebes/gfxHarfBuzzShaper.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef GFX_HARFBUZZSHAPER_H
     7 #define GFX_HARFBUZZSHAPER_H
     9 #include "gfxFont.h"
    11 #include "harfbuzz/hb.h"
    13 class gfxHarfBuzzShaper : public gfxFontShaper {
    14 public:
    15     gfxHarfBuzzShaper(gfxFont *aFont);
    16     virtual ~gfxHarfBuzzShaper();
    18     /*
    19      * For HarfBuzz font callback functions, font_data is a ptr to a
    20      * FontCallbackData struct
    21      */
    22     struct FontCallbackData {
    23         gfxHarfBuzzShaper *mShaper;
    24         gfxContext        *mContext;
    25     };
    27     bool Initialize();
    28     virtual bool ShapeText(gfxContext      *aContext,
    29                            const char16_t *aText,
    30                            uint32_t         aOffset,
    31                            uint32_t         aLength,
    32                            int32_t          aScript,
    33                            gfxShapedText   *aShapedText);
    35     // get a given font table in harfbuzz blob form
    36     hb_blob_t * GetFontTable(hb_tag_t aTag) const;
    38     // map unicode character to glyph ID
    39     hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
    40                             hb_codepoint_t variation_selector) const;
    42     // get harfbuzz glyph advance, in font design units
    43     hb_position_t GetGlyphHAdvance(gfxContext *aContext,
    44                                    hb_codepoint_t glyph) const;
    46     // get harfbuzz horizontal advance in 16.16 fixed point format.
    47     static hb_position_t
    48     HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
    49                        hb_codepoint_t glyph, void *user_data);
    51     hb_position_t GetHKerning(uint16_t aFirstGlyph,
    52                               uint16_t aSecondGlyph) const;
    54 protected:
    55     nsresult SetGlyphsFromRun(gfxContext      *aContext,
    56                               gfxShapedText   *aShapedText,
    57                               uint32_t         aOffset,
    58                               uint32_t         aLength,
    59                               const char16_t *aText,
    60                               hb_buffer_t     *aBuffer);
    62     // retrieve glyph positions, applying advance adjustments and attachments
    63     // returns results in appUnits
    64     nscoord GetGlyphPositions(gfxContext *aContext,
    65                               hb_buffer_t *aBuffer,
    66                               nsTArray<nsPoint>& aPositions,
    67                               uint32_t aAppUnitsPerDevUnit);
    69     // harfbuzz face object: we acquire a reference from the font entry
    70     // on shaper creation, and release it in our destructor
    71     hb_face_t         *mHBFace;
    73     // size-specific font object, owned by the gfxHarfBuzzShaper
    74     hb_font_t         *mHBFont;
    76     FontCallbackData   mCallbackData;
    78     // Following table references etc are declared "mutable" because the
    79     // harfbuzz callback functions take a const ptr to the shaper, but
    80     // wish to cache tables here to avoid repeatedly looking them up
    81     // in the font.
    83     // Old-style TrueType kern table, if we're not doing GPOS kerning
    84     mutable hb_blob_t *mKernTable;
    86     // Cached copy of the hmtx table and numLongMetrics field from hhea,
    87     // for use when looking up glyph metrics; initialized to 0 by the
    88     // constructor so we can tell it hasn't been set yet.
    89     // This is a signed value so that we can use -1 to indicate
    90     // an error (if the hhea table was not available).
    91     mutable hb_blob_t *mHmtxTable;
    92     mutable int32_t    mNumLongMetrics;
    94     // Cached pointer to cmap subtable to be used for char-to-glyph mapping.
    95     // This comes from GetFontTablePtr; if it is non-null, our destructor
    96     // must call ReleaseFontTablePtr to avoid permanently caching the table.
    97     mutable hb_blob_t *mCmapTable;
    98     mutable int32_t    mCmapFormat;
    99     mutable uint32_t   mSubtableOffset;
   100     mutable uint32_t   mUVSTableOffset;
   102     // Whether the font implements GetGlyph, or we should read tables
   103     // directly
   104     bool mUseFontGetGlyph;
   105     // Whether the font implements GetGlyphWidth, or we should read tables
   106     // directly to get ideal widths
   107     bool mUseFontGlyphWidths;
   109     bool mInitialized;
   110 };
   112 #endif /* GFX_HARFBUZZSHAPER_H */

mercurial