2009-10-07 21:16:52 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
#ifndef GFX_HARFBUZZSHAPER_H
|
|
|
|
#define GFX_HARFBUZZSHAPER_H
|
|
|
|
|
|
|
|
#include "gfxFont.h"
|
|
|
|
|
|
|
|
#include "harfbuzz/hb.h"
|
2014-07-22 04:02:48 +04:00
|
|
|
#include "nsUnicodeProperties.h"
|
2015-12-07 01:13:19 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
class gfxHarfBuzzShaper : public gfxFontShaper {
|
|
|
|
public:
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit gfxHarfBuzzShaper(gfxFont *aFont);
|
2009-10-07 21:16:52 +04:00
|
|
|
virtual ~gfxHarfBuzzShaper();
|
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
/*
|
|
|
|
* For HarfBuzz font callback functions, font_data is a ptr to a
|
|
|
|
* FontCallbackData struct
|
|
|
|
*/
|
|
|
|
struct FontCallbackData {
|
2015-12-07 01:13:19 +03:00
|
|
|
gfxHarfBuzzShaper* mShaper;
|
|
|
|
mozilla::gfx::DrawTarget* mDrawTarget;
|
2013-05-16 20:29:20 +04:00
|
|
|
};
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
bool Initialize();
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool ShapeText(DrawTarget *aDrawTarget,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aText,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 23:25:48 +04:00
|
|
|
bool aVertical,
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxShapedText *aShapedText);
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
// get a given font table in harfbuzz blob form
|
|
|
|
hb_blob_t * GetFontTable(hb_tag_t aTag) const;
|
|
|
|
|
|
|
|
// map unicode character to glyph ID
|
|
|
|
hb_codepoint_t GetGlyph(hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector) const;
|
|
|
|
|
2010-11-20 20:49:12 +03:00
|
|
|
// get harfbuzz glyph advance, in font design units
|
2014-11-11 00:41:41 +03:00
|
|
|
hb_position_t GetGlyphHAdvance(hb_codepoint_t glyph) const;
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
hb_position_t GetGlyphVAdvance(hb_codepoint_t glyph) const;
|
2014-10-01 23:25:48 +04:00
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
void GetGlyphVOrigin(hb_codepoint_t aGlyph,
|
2014-10-01 23:25:48 +04:00
|
|
|
hb_position_t *aX, hb_position_t *aY) const;
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
// get harfbuzz horizontal advance in 16.16 fixed point format.
|
|
|
|
static hb_position_t
|
|
|
|
HBGetGlyphHAdvance(hb_font_t *font, void *font_data,
|
|
|
|
hb_codepoint_t glyph, void *user_data);
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
// get harfbuzz vertical advance in 16.16 fixed point format.
|
|
|
|
static hb_position_t
|
|
|
|
HBGetGlyphVAdvance(hb_font_t *font, void *font_data,
|
|
|
|
hb_codepoint_t glyph, void *user_data);
|
|
|
|
|
|
|
|
static hb_bool_t
|
|
|
|
HBGetGlyphHOrigin(hb_font_t *font, void *font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_position_t *x, hb_position_t *y,
|
|
|
|
void *user_data);
|
|
|
|
static hb_bool_t
|
|
|
|
HBGetGlyphVOrigin(hb_font_t *font, void *font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_position_t *x, hb_position_t *y,
|
|
|
|
void *user_data);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
hb_position_t GetHKerning(uint16_t aFirstGlyph,
|
|
|
|
uint16_t aSecondGlyph) const;
|
2010-07-28 17:36:07 +04:00
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
hb_bool_t GetGlyphExtents(hb_codepoint_t aGlyph,
|
|
|
|
hb_glyph_extents_t *aExtents) const;
|
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
bool UseVerticalPresentationForms() const
|
|
|
|
{
|
|
|
|
return mUseVerticalPresentationForms;
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:02:48 +04:00
|
|
|
static hb_script_t
|
|
|
|
GetHBScriptUsedForShaping(int32_t aScript) {
|
|
|
|
// Decide what harfbuzz script code will be used for shaping
|
|
|
|
hb_script_t hbScript;
|
|
|
|
if (aScript <= MOZ_SCRIPT_INHERITED) {
|
|
|
|
// For unresolved "common" or "inherited" runs,
|
|
|
|
// default to Latin for now.
|
|
|
|
hbScript = HB_SCRIPT_LATIN;
|
|
|
|
} else {
|
|
|
|
hbScript =
|
|
|
|
hb_script_t(mozilla::unicode::GetScriptTagForCode(aScript));
|
|
|
|
}
|
|
|
|
return hbScript;
|
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
protected:
|
2015-12-16 00:56:41 +03:00
|
|
|
nsresult SetGlyphsFromRun(DrawTarget *aDrawTarget,
|
2014-10-01 23:25:48 +04:00
|
|
|
gfxShapedText *aShapedText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aText,
|
2014-10-01 23:25:48 +04:00
|
|
|
hb_buffer_t *aBuffer,
|
|
|
|
bool aVertical);
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
// retrieve glyph positions, applying advance adjustments and attachments
|
|
|
|
// returns results in appUnits
|
|
|
|
nscoord GetGlyphPositions(gfxContext *aContext,
|
|
|
|
hb_buffer_t *aBuffer,
|
|
|
|
nsTArray<nsPoint>& aPositions,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAppUnitsPerDevUnit);
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
bool InitializeVertical();
|
|
|
|
bool LoadHmtxTable();
|
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
struct Glyf { // we only need the bounding-box at the beginning
|
|
|
|
// of the glyph record, not the actual outline data
|
|
|
|
AutoSwap_PRInt16 numberOfContours;
|
|
|
|
AutoSwap_PRInt16 xMin;
|
|
|
|
AutoSwap_PRInt16 yMin;
|
|
|
|
AutoSwap_PRInt16 xMax;
|
|
|
|
AutoSwap_PRInt16 yMax;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Glyf *FindGlyf(hb_codepoint_t aGlyph, bool *aEmptyGlyf) const;
|
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
// harfbuzz face object: we acquire a reference from the font entry
|
|
|
|
// on shaper creation, and release it in our destructor
|
2009-10-07 21:16:52 +04:00
|
|
|
hb_face_t *mHBFace;
|
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
// size-specific font object, owned by the gfxHarfBuzzShaper
|
|
|
|
hb_font_t *mHBFont;
|
|
|
|
|
|
|
|
FontCallbackData mCallbackData;
|
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
// Following table references etc are declared "mutable" because the
|
|
|
|
// harfbuzz callback functions take a const ptr to the shaper, but
|
|
|
|
// wish to cache tables here to avoid repeatedly looking them up
|
|
|
|
// in the font.
|
|
|
|
|
|
|
|
// Old-style TrueType kern table, if we're not doing GPOS kerning
|
|
|
|
mutable hb_blob_t *mKernTable;
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
// Cached copy of the hmtx table.
|
2009-10-07 21:16:52 +04:00
|
|
|
mutable hb_blob_t *mHmtxTable;
|
2014-10-01 23:25:48 +04:00
|
|
|
|
|
|
|
// For vertical fonts, cached vmtx and VORG table, if present.
|
|
|
|
mutable hb_blob_t *mVmtxTable;
|
|
|
|
mutable hb_blob_t *mVORGTable;
|
2015-01-15 14:07:26 +03:00
|
|
|
// And for vertical TrueType (not CFF) fonts that have vmtx,
|
|
|
|
// we also use loca and glyf to get glyph bounding boxes.
|
|
|
|
mutable hb_blob_t *mLocaTable;
|
|
|
|
mutable hb_blob_t *mGlyfTable;
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
// Cached pointer to cmap subtable to be used for char-to-glyph mapping.
|
|
|
|
// This comes from GetFontTablePtr; if it is non-null, our destructor
|
|
|
|
// must call ReleaseFontTablePtr to avoid permanently caching the table.
|
|
|
|
mutable hb_blob_t *mCmapTable;
|
2012-08-22 19:56:38 +04:00
|
|
|
mutable int32_t mCmapFormat;
|
|
|
|
mutable uint32_t mSubtableOffset;
|
|
|
|
mutable uint32_t mUVSTableOffset;
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
// Cached copy of numLongMetrics field from the hhea table,
|
|
|
|
// for use when looking up glyph metrics; initialized to 0 by the
|
|
|
|
// constructor so we can tell it hasn't been set yet.
|
|
|
|
// This is a signed value so that we can use -1 to indicate
|
|
|
|
// an error (if the hhea table was not available).
|
|
|
|
mutable int32_t mNumLongHMetrics;
|
|
|
|
// Similarly for vhea if it's a vertical font.
|
|
|
|
mutable int32_t mNumLongVMetrics;
|
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
// Whether the font implements GetGlyph, or we should read tables
|
|
|
|
// directly
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUseFontGetGlyph;
|
2011-01-21 13:35:21 +03:00
|
|
|
// Whether the font implements GetGlyphWidth, or we should read tables
|
2009-10-07 21:16:52 +04:00
|
|
|
// directly to get ideal widths
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUseFontGlyphWidths;
|
2013-05-16 20:29:20 +04:00
|
|
|
|
|
|
|
bool mInitialized;
|
2014-10-01 23:25:48 +04:00
|
|
|
bool mVerticalInitialized;
|
2015-01-28 12:03:28 +03:00
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
// Whether to use vertical presentation forms for CJK characters
|
|
|
|
// when available (only set if the 'vert' feature is not available).
|
|
|
|
bool mUseVerticalPresentationForms;
|
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
// these are set from the FindGlyf callback on first use of the glyf data
|
|
|
|
mutable bool mLoadedLocaGlyf;
|
|
|
|
mutable bool mLocaLongOffsets;
|
2009-10-07 21:16:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_HARFBUZZSHAPER_H */
|