gfx/thebes/gfxHarfBuzzShaper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxHarfBuzzShaper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_HARFBUZZSHAPER_H
    1.10 +#define GFX_HARFBUZZSHAPER_H
    1.11 +
    1.12 +#include "gfxFont.h"
    1.13 +
    1.14 +#include "harfbuzz/hb.h"
    1.15 +
    1.16 +class gfxHarfBuzzShaper : public gfxFontShaper {
    1.17 +public:
    1.18 +    gfxHarfBuzzShaper(gfxFont *aFont);
    1.19 +    virtual ~gfxHarfBuzzShaper();
    1.20 +
    1.21 +    /*
    1.22 +     * For HarfBuzz font callback functions, font_data is a ptr to a
    1.23 +     * FontCallbackData struct
    1.24 +     */
    1.25 +    struct FontCallbackData {
    1.26 +        gfxHarfBuzzShaper *mShaper;
    1.27 +        gfxContext        *mContext;
    1.28 +    };
    1.29 +
    1.30 +    bool Initialize();
    1.31 +    virtual bool ShapeText(gfxContext      *aContext,
    1.32 +                           const char16_t *aText,
    1.33 +                           uint32_t         aOffset,
    1.34 +                           uint32_t         aLength,
    1.35 +                           int32_t          aScript,
    1.36 +                           gfxShapedText   *aShapedText);
    1.37 +
    1.38 +    // get a given font table in harfbuzz blob form
    1.39 +    hb_blob_t * GetFontTable(hb_tag_t aTag) const;
    1.40 +
    1.41 +    // map unicode character to glyph ID
    1.42 +    hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
    1.43 +                            hb_codepoint_t variation_selector) const;
    1.44 +
    1.45 +    // get harfbuzz glyph advance, in font design units
    1.46 +    hb_position_t GetGlyphHAdvance(gfxContext *aContext,
    1.47 +                                   hb_codepoint_t glyph) const;
    1.48 +
    1.49 +    // get harfbuzz horizontal advance in 16.16 fixed point format.
    1.50 +    static hb_position_t
    1.51 +    HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
    1.52 +                       hb_codepoint_t glyph, void *user_data);
    1.53 +
    1.54 +    hb_position_t GetHKerning(uint16_t aFirstGlyph,
    1.55 +                              uint16_t aSecondGlyph) const;
    1.56 +
    1.57 +protected:
    1.58 +    nsresult SetGlyphsFromRun(gfxContext      *aContext,
    1.59 +                              gfxShapedText   *aShapedText,
    1.60 +                              uint32_t         aOffset,
    1.61 +                              uint32_t         aLength,
    1.62 +                              const char16_t *aText,
    1.63 +                              hb_buffer_t     *aBuffer);
    1.64 +
    1.65 +    // retrieve glyph positions, applying advance adjustments and attachments
    1.66 +    // returns results in appUnits
    1.67 +    nscoord GetGlyphPositions(gfxContext *aContext,
    1.68 +                              hb_buffer_t *aBuffer,
    1.69 +                              nsTArray<nsPoint>& aPositions,
    1.70 +                              uint32_t aAppUnitsPerDevUnit);
    1.71 +
    1.72 +    // harfbuzz face object: we acquire a reference from the font entry
    1.73 +    // on shaper creation, and release it in our destructor
    1.74 +    hb_face_t         *mHBFace;
    1.75 +
    1.76 +    // size-specific font object, owned by the gfxHarfBuzzShaper
    1.77 +    hb_font_t         *mHBFont;
    1.78 +
    1.79 +    FontCallbackData   mCallbackData;
    1.80 +
    1.81 +    // Following table references etc are declared "mutable" because the
    1.82 +    // harfbuzz callback functions take a const ptr to the shaper, but
    1.83 +    // wish to cache tables here to avoid repeatedly looking them up
    1.84 +    // in the font.
    1.85 +
    1.86 +    // Old-style TrueType kern table, if we're not doing GPOS kerning
    1.87 +    mutable hb_blob_t *mKernTable;
    1.88 +
    1.89 +    // Cached copy of the hmtx table and numLongMetrics field from hhea,
    1.90 +    // for use when looking up glyph metrics; initialized to 0 by the
    1.91 +    // constructor so we can tell it hasn't been set yet.
    1.92 +    // This is a signed value so that we can use -1 to indicate
    1.93 +    // an error (if the hhea table was not available).
    1.94 +    mutable hb_blob_t *mHmtxTable;
    1.95 +    mutable int32_t    mNumLongMetrics;
    1.96 +
    1.97 +    // Cached pointer to cmap subtable to be used for char-to-glyph mapping.
    1.98 +    // This comes from GetFontTablePtr; if it is non-null, our destructor
    1.99 +    // must call ReleaseFontTablePtr to avoid permanently caching the table.
   1.100 +    mutable hb_blob_t *mCmapTable;
   1.101 +    mutable int32_t    mCmapFormat;
   1.102 +    mutable uint32_t   mSubtableOffset;
   1.103 +    mutable uint32_t   mUVSTableOffset;
   1.104 +
   1.105 +    // Whether the font implements GetGlyph, or we should read tables
   1.106 +    // directly
   1.107 +    bool mUseFontGetGlyph;
   1.108 +    // Whether the font implements GetGlyphWidth, or we should read tables
   1.109 +    // directly to get ideal widths
   1.110 +    bool mUseFontGlyphWidths;
   1.111 +
   1.112 +    bool mInitialized;
   1.113 +};
   1.114 +
   1.115 +#endif /* GFX_HARFBUZZSHAPER_H */

mercurial