2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxContext.h"
|
2014-06-23 07:09:16 +04:00
|
|
|
#include "gfxFontConstants.h"
|
2009-10-07 21:16:52 +04:00
|
|
|
#include "gfxHarfBuzzShaper.h"
|
|
|
|
#include "gfxFontUtils.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2012-02-24 14:15:46 +04:00
|
|
|
#include "nsUnicodeProperties.h"
|
|
|
|
#include "nsUnicodeScriptCodes.h"
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2012-04-22 01:24:39 +04:00
|
|
|
#include "harfbuzz/hb.h"
|
2010-07-14 00:31:31 +04:00
|
|
|
#include "harfbuzz/hb-ot.h"
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2015-05-11 21:57:28 +03:00
|
|
|
#include "unicode/unorm.h"
|
|
|
|
#include "unicode/utext.h"
|
2017-09-22 12:37:16 +03:00
|
|
|
|
|
|
|
static const UNormalizer2* sNormalizer = nullptr;
|
2015-05-11 21:57:28 +03:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
#define FloatToFixed(f) (65536 * (f))
|
|
|
|
#define FixedToFloat(f) ((f) * (1.0 / 65536.0))
|
2010-11-14 22:21:37 +03:00
|
|
|
// Right shifts of negative (signed) integers are undefined, as are overflows
|
|
|
|
// when converting unsigned to negative signed integers.
|
|
|
|
// (If speed were an issue we could make some 2's complement assumptions.)
|
|
|
|
#define FixedToIntRound(f) \
|
|
|
|
((f) > 0 ? ((32768 + (f)) >> 16) : -((32767 - (f)) >> 16))
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
using namespace mozilla; // for AutoSwap_* types
|
2012-02-24 14:15:46 +04:00
|
|
|
using namespace mozilla::unicode; // for Unicode property lookup
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Creation and destruction; on deletion, release any font tables we're holding
|
|
|
|
*/
|
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfxFont* aFont)
|
|
|
|
: gfxFontShaper(aFont),
|
|
|
|
mHBFont(nullptr),
|
|
|
|
mBuffer(nullptr),
|
2018-06-16 17:42:33 +03:00
|
|
|
mCallbackData(),
|
2018-04-13 16:01:28 +03:00
|
|
|
mKernTable(nullptr),
|
|
|
|
mHmtxTable(nullptr),
|
|
|
|
mVmtxTable(nullptr),
|
|
|
|
mVORGTable(nullptr),
|
|
|
|
mLocaTable(nullptr),
|
|
|
|
mGlyfTable(nullptr),
|
|
|
|
mCmapTable(nullptr),
|
|
|
|
mCmapFormat(-1),
|
|
|
|
mSubtableOffset(0),
|
|
|
|
mUVSTableOffset(0),
|
|
|
|
mNumLongHMetrics(0),
|
|
|
|
mNumLongVMetrics(0),
|
|
|
|
mDefaultVOrg(-1.0),
|
|
|
|
mUseFontGetGlyph(aFont->ProvidesGetGlyph()),
|
2018-06-27 18:12:43 +03:00
|
|
|
mUseFontGlyphWidths(aFont->ProvidesGlyphWidths()),
|
2018-04-13 16:01:28 +03:00
|
|
|
mInitialized(false),
|
|
|
|
mVerticalInitialized(false),
|
2018-06-16 17:42:33 +03:00
|
|
|
mUseVerticalPresentationForms(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mLoadedLocaGlyf(false),
|
|
|
|
mLocaLongOffsets(false) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxHarfBuzzShaper::~gfxHarfBuzzShaper() {
|
2019-02-18 20:16:22 +03:00
|
|
|
// hb_*_destroy functions are safe to call on nullptr
|
|
|
|
hb_blob_destroy(mCmapTable);
|
|
|
|
hb_blob_destroy(mHmtxTable);
|
|
|
|
hb_blob_destroy(mKernTable);
|
|
|
|
hb_blob_destroy(mVmtxTable);
|
|
|
|
hb_blob_destroy(mVORGTable);
|
|
|
|
hb_blob_destroy(mLocaTable);
|
|
|
|
hb_blob_destroy(mGlyfTable);
|
|
|
|
hb_font_destroy(mHBFont);
|
|
|
|
hb_buffer_destroy(mBuffer);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define UNICODE_BMP_LIMIT 0x10000
|
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
hb_codepoint_t gfxHarfBuzzShaper::GetNominalGlyph(
|
2013-01-04 22:35:37 +04:00
|
|
|
hb_codepoint_t unicode) const {
|
2016-04-13 15:48:40 +03:00
|
|
|
hb_codepoint_t gid = 0;
|
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
if (mUseFontGetGlyph) {
|
2016-04-13 15:48:40 +03:00
|
|
|
gid = mFont->GetGlyph(unicode, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2013-01-04 22:35:37 +04:00
|
|
|
// we only instantiate a harfbuzz shaper if there's a cmap available
|
2016-04-13 15:48:40 +03:00
|
|
|
NS_ASSERTION(mFont->GetFontEntry()->HasCmapTable(),
|
|
|
|
"we cannot be using this font!");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
NS_ASSERTION(mCmapTable && (mCmapFormat > 0) && (mSubtableOffset > 0),
|
|
|
|
"cmap data not correctly set up, expect disaster");
|
|
|
|
|
2018-05-19 10:32:22 +03:00
|
|
|
uint32_t length;
|
|
|
|
const uint8_t* data = (const uint8_t*)hb_blob_get_data(mCmapTable, &length);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
switch (mCmapFormat) {
|
2018-11-30 13:46:48 +03:00
|
|
|
case 4:
|
|
|
|
gid =
|
2016-04-13 15:48:40 +03:00
|
|
|
unicode < UNICODE_BMP_LIMIT
|
2013-01-04 22:35:37 +04:00
|
|
|
? gfxFontUtils::MapCharToGlyphFormat4(
|
2016-04-13 15:48:40 +03:00
|
|
|
data + mSubtableOffset, length - mSubtableOffset, unicode)
|
2018-11-30 13:46:48 +03:00
|
|
|
: 0;
|
|
|
|
break;
|
|
|
|
case 10:
|
2016-04-13 15:48:40 +03:00
|
|
|
gid = gfxFontUtils::MapCharToGlyphFormat10(data + mSubtableOffset,
|
|
|
|
unicode);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
case 13:
|
2016-04-13 15:48:40 +03:00
|
|
|
gid = gfxFontUtils::MapCharToGlyphFormat12or13(data + mSubtableOffset,
|
2014-09-08 12:53:29 +04:00
|
|
|
unicode);
|
2016-04-13 15:48:40 +03:00
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
default:
|
2016-04-13 15:48:40 +03:00
|
|
|
NS_WARNING("unsupported cmap format, glyphs will be missing");
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2016-04-13 15:48:40 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-04-13 15:48:40 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
if (!gid) {
|
|
|
|
// if there's no glyph for , just use the space glyph instead
|
|
|
|
if (unicode == 0xA0) {
|
2016-04-13 15:48:40 +03:00
|
|
|
gid = mFont->GetSpaceGlyph();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
return gid;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
hb_codepoint_t gfxHarfBuzzShaper::GetVariationGlyph(
|
|
|
|
hb_codepoint_t unicode, hb_codepoint_t variation_selector) const {
|
|
|
|
if (mUseFontGetGlyph) {
|
|
|
|
return mFont->GetGlyph(unicode, variation_selector);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
NS_ASSERTION(mFont->GetFontEntry()->HasCmapTable(),
|
|
|
|
"we cannot be using this font!");
|
|
|
|
NS_ASSERTION(mCmapTable && (mCmapFormat > 0) && (mSubtableOffset > 0),
|
|
|
|
"cmap data not correctly set up, expect disaster");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-19 10:32:22 +03:00
|
|
|
uint32_t length;
|
2014-04-23 17:57:42 +04:00
|
|
|
const uint8_t* data = (const uint8_t*)hb_blob_get_data(mCmapTable, &length);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
if (mUVSTableOffset) {
|
2016-04-13 15:48:40 +03:00
|
|
|
hb_codepoint_t gid = gfxFontUtils::MapUVSToGlyphFormat14(
|
|
|
|
data + mUVSTableOffset, unicode, variation_selector);
|
|
|
|
if (gid) {
|
2009-10-07 21:16:52 +04:00
|
|
|
return gid;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
uint32_t compat = gfxFontUtils::GetUVSFallback(unicode, variation_selector);
|
|
|
|
if (compat) {
|
2013-01-04 22:35:37 +04:00
|
|
|
switch (mCmapFormat) {
|
2018-11-30 13:46:48 +03:00
|
|
|
case 4:
|
2016-04-13 15:48:40 +03:00
|
|
|
if (compat < UNICODE_BMP_LIMIT) {
|
|
|
|
return gfxFontUtils::MapCharToGlyphFormat4(
|
2016-12-13 15:15:24 +03:00
|
|
|
data + mSubtableOffset, length - mSubtableOffset, compat);
|
2016-04-13 15:48:40 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
case 10:
|
2014-09-08 12:53:29 +04:00
|
|
|
return gfxFontUtils::MapCharToGlyphFormat10(data + mSubtableOffset,
|
2018-11-30 13:46:48 +03:00
|
|
|
compat);
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
case 13:
|
2016-12-13 15:15:24 +03:00
|
|
|
return gfxFontUtils::MapCharToGlyphFormat12or13(data + mSubtableOffset,
|
2018-11-30 13:46:48 +03:00
|
|
|
compat);
|
|
|
|
break;
|
2016-04-13 15:48:40 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-04-13 15:48:40 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
static int VertFormsGlyphCompare(const void* aKey, const void* aElem) {
|
|
|
|
return int(*((hb_codepoint_t*)(aKey))) - int(*((uint16_t*)(aElem)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a vertical presentation-form codepoint corresponding to the
|
|
|
|
// given Unicode value, or 0 if no such form is available.
|
2018-01-19 13:46:53 +03:00
|
|
|
hb_codepoint_t gfxHarfBuzzShaper::GetVerticalPresentationForm(
|
|
|
|
hb_codepoint_t aUnicode) {
|
2015-05-22 10:40:04 +03:00
|
|
|
static const uint16_t sVerticalForms[][2] = {
|
|
|
|
{0x2013, 0xfe32}, // EN DASH
|
|
|
|
{0x2014, 0xfe31}, // EM DASH
|
|
|
|
{0x2025, 0xfe30}, // TWO DOT LEADER
|
|
|
|
{0x2026, 0xfe19}, // HORIZONTAL ELLIPSIS
|
|
|
|
{0x3001, 0xfe11}, // IDEOGRAPHIC COMMA
|
|
|
|
{0x3002, 0xfe12}, // IDEOGRAPHIC FULL STOP
|
|
|
|
{0x3008, 0xfe3f}, // LEFT ANGLE BRACKET
|
|
|
|
{0x3009, 0xfe40}, // RIGHT ANGLE BRACKET
|
|
|
|
{0x300a, 0xfe3d}, // LEFT DOUBLE ANGLE BRACKET
|
|
|
|
{0x300b, 0xfe3e}, // RIGHT DOUBLE ANGLE BRACKET
|
|
|
|
{0x300c, 0xfe41}, // LEFT CORNER BRACKET
|
|
|
|
{0x300d, 0xfe42}, // RIGHT CORNER BRACKET
|
|
|
|
{0x300e, 0xfe43}, // LEFT WHITE CORNER BRACKET
|
|
|
|
{0x300f, 0xfe44}, // RIGHT WHITE CORNER BRACKET
|
|
|
|
{0x3010, 0xfe3b}, // LEFT BLACK LENTICULAR BRACKET
|
|
|
|
{0x3011, 0xfe3c}, // RIGHT BLACK LENTICULAR BRACKET
|
|
|
|
{0x3014, 0xfe39}, // LEFT TORTOISE SHELL BRACKET
|
|
|
|
{0x3015, 0xfe3a}, // RIGHT TORTOISE SHELL BRACKET
|
|
|
|
{0x3016, 0xfe17}, // LEFT WHITE LENTICULAR BRACKET
|
|
|
|
{0x3017, 0xfe18}, // RIGHT WHITE LENTICULAR BRACKET
|
|
|
|
{0xfe4f, 0xfe34}, // WAVY LOW LINE
|
|
|
|
{0xff01, 0xfe15}, // FULLWIDTH EXCLAMATION MARK
|
|
|
|
{0xff08, 0xfe35}, // FULLWIDTH LEFT PARENTHESIS
|
|
|
|
{0xff09, 0xfe36}, // FULLWIDTH RIGHT PARENTHESIS
|
|
|
|
{0xff0c, 0xfe10}, // FULLWIDTH COMMA
|
|
|
|
{0xff1a, 0xfe13}, // FULLWIDTH COLON
|
|
|
|
{0xff1b, 0xfe14}, // FULLWIDTH SEMICOLON
|
|
|
|
{0xff1f, 0xfe16}, // FULLWIDTH QUESTION MARK
|
|
|
|
{0xff3b, 0xfe47}, // FULLWIDTH LEFT SQUARE BRACKET
|
|
|
|
{0xff3d, 0xfe48}, // FULLWIDTH RIGHT SQUARE BRACKET
|
|
|
|
{0xff3f, 0xfe33}, // FULLWIDTH LOW LINE
|
|
|
|
{0xff5b, 0xfe37}, // FULLWIDTH LEFT CURLY BRACKET
|
|
|
|
{0xff5d, 0xfe38} // FULLWIDTH RIGHT CURLY BRACKET
|
|
|
|
};
|
2018-01-19 13:46:53 +03:00
|
|
|
const uint16_t* charPair = static_cast<const uint16_t*>(
|
2015-05-22 10:40:04 +03:00
|
|
|
bsearch(&aUnicode, sVerticalForms, ArrayLength(sVerticalForms),
|
|
|
|
sizeof(sVerticalForms[0]), VertFormsGlyphCompare));
|
|
|
|
return charPair ? charPair[1] : 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
static hb_bool_t HBGetNominalGlyph(hb_font_t* font, void* font_data,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t* glyph, void* user_data) {
|
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
if (fcd->mShaper->UseVerticalPresentationForms()) {
|
2018-01-19 13:46:53 +03:00
|
|
|
hb_codepoint_t verticalForm =
|
|
|
|
gfxHarfBuzzShaper::GetVerticalPresentationForm(unicode);
|
2016-04-13 15:48:40 +03:00
|
|
|
if (verticalForm) {
|
|
|
|
*glyph = fcd->mShaper->GetNominalGlyph(verticalForm);
|
|
|
|
if (*glyph != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall back to the non-vertical form if we didn't find an alternate
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-04-13 15:48:40 +03:00
|
|
|
|
|
|
|
*glyph = fcd->mShaper->GetNominalGlyph(unicode);
|
|
|
|
return *glyph != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t HBGetVariationGlyph(hb_font_t* font, void* font_data,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t* glyph, void* user_data) {
|
2013-05-16 20:29:20 +04:00
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
if (fcd->mShaper->UseVerticalPresentationForms()) {
|
2018-01-19 13:46:53 +03:00
|
|
|
hb_codepoint_t verticalForm =
|
|
|
|
gfxHarfBuzzShaper::GetVerticalPresentationForm(unicode);
|
2015-05-22 10:40:04 +03:00
|
|
|
if (verticalForm) {
|
2016-04-13 15:48:40 +03:00
|
|
|
*glyph =
|
|
|
|
fcd->mShaper->GetVariationGlyph(verticalForm, variation_selector);
|
2015-05-22 10:40:04 +03:00
|
|
|
if (*glyph != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 15:48:40 +03:00
|
|
|
// fall back to the non-vertical form if we didn't find an alternate
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-22 10:40:04 +03:00
|
|
|
|
2016-04-13 15:48:40 +03:00
|
|
|
*glyph = fcd->mShaper->GetVariationGlyph(unicode, variation_selector);
|
2012-05-22 00:05:36 +04:00
|
|
|
return *glyph != 0;
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
// Glyph metrics structures, shared (with appropriate reinterpretation of
|
|
|
|
// field names) by horizontal and vertical metrics tables.
|
|
|
|
struct LongMetric {
|
|
|
|
AutoSwap_PRUint16 advanceWidth; // or advanceHeight, when vertical
|
|
|
|
AutoSwap_PRInt16 lsb; // or tsb, when vertical
|
2009-10-07 21:16:52 +04:00
|
|
|
};
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
struct GlyphMetrics {
|
|
|
|
LongMetric metrics[1]; // actually numberOfLongMetrics
|
2009-10-07 21:16:52 +04:00
|
|
|
// the variable-length metrics[] array is immediately followed by:
|
|
|
|
// AutoSwap_PRUint16 leftSideBearing[];
|
|
|
|
};
|
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
hb_position_t gfxHarfBuzzShaper::GetGlyphHAdvance(hb_codepoint_t glyph) const {
|
2014-10-01 23:25:48 +04:00
|
|
|
// font did not implement GetGlyphWidth, so get an unhinted value
|
2009-10-07 21:16:52 +04:00
|
|
|
// directly from the font tables
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
NS_ASSERTION((mNumLongHMetrics > 0) && mHmtxTable != nullptr,
|
|
|
|
"font is lacking metrics, we shouldn't be here");
|
|
|
|
|
|
|
|
if (glyph >= uint32_t(mNumLongHMetrics)) {
|
|
|
|
glyph = mNumLongHMetrics - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// glyph must be valid now, because we checked during initialization
|
|
|
|
// that mNumLongHMetrics is > 0, and that the metrics table is large enough
|
|
|
|
// to contain mNumLongHMetrics records
|
2017-02-23 05:29:46 +03:00
|
|
|
const ::GlyphMetrics* metrics = reinterpret_cast<const ::GlyphMetrics*>(
|
|
|
|
hb_blob_get_data(mHmtxTable, nullptr));
|
2014-10-01 23:25:48 +04:00
|
|
|
return FloatToFixed(mFont->FUnitsToDevUnitsFactor() *
|
|
|
|
uint16_t(metrics->metrics[glyph].advanceWidth));
|
|
|
|
}
|
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
hb_position_t gfxHarfBuzzShaper::GetGlyphVAdvance(hb_codepoint_t glyph) const {
|
2014-10-01 23:25:48 +04:00
|
|
|
if (!mVmtxTable) {
|
|
|
|
// Must be a "vertical" font that doesn't actually have vertical metrics;
|
|
|
|
// use a fixed advance.
|
2019-04-01 17:32:19 +03:00
|
|
|
return FloatToFixed(
|
|
|
|
mFont->GetMetrics(nsFontMetrics::eVertical).aveCharWidth);
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
NS_ASSERTION(mNumLongVMetrics > 0,
|
2010-06-16 10:37:37 +04:00
|
|
|
"font is lacking metrics, we shouldn't be here");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
if (glyph >= uint32_t(mNumLongVMetrics)) {
|
|
|
|
glyph = mNumLongVMetrics - 1;
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-22 13:25:23 +04:00
|
|
|
// glyph must be valid now, because we checked during initialization
|
2014-10-01 23:25:48 +04:00
|
|
|
// that mNumLongVMetrics is > 0, and that the metrics table is large enough
|
|
|
|
// to contain mNumLongVMetrics records
|
2017-02-23 05:29:46 +03:00
|
|
|
const ::GlyphMetrics* metrics = reinterpret_cast<const ::GlyphMetrics*>(
|
|
|
|
hb_blob_get_data(mVmtxTable, nullptr));
|
2012-02-14 12:03:01 +04:00
|
|
|
return FloatToFixed(mFont->FUnitsToDevUnitsFactor() *
|
2014-10-01 23:25:48 +04:00
|
|
|
uint16_t(metrics->metrics[glyph].advanceWidth));
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
/* static */
|
|
|
|
hb_position_t gfxHarfBuzzShaper::HBGetGlyphHAdvance(hb_font_t* font,
|
|
|
|
void* font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
void* user_data) {
|
2018-06-27 18:12:43 +03:00
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
2013-05-16 20:29:20 +04:00
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
2018-06-27 18:12:43 +03:00
|
|
|
const gfxHarfBuzzShaper* shaper = fcd->mShaper;
|
|
|
|
if (shaper->mUseFontGlyphWidths) {
|
2018-12-31 14:43:27 +03:00
|
|
|
return shaper->GetFont()->GetGlyphWidth(glyph);
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
2018-06-27 18:12:43 +03:00
|
|
|
return shaper->GetGlyphHAdvance(glyph);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
/* static */
|
|
|
|
hb_position_t gfxHarfBuzzShaper::HBGetGlyphVAdvance(hb_font_t* font,
|
|
|
|
void* font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
void* user_data) {
|
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
2015-01-06 23:56:01 +03:00
|
|
|
// Currently, we don't offer gfxFont subclasses a method to override this
|
|
|
|
// and provide hinted platform-specific vertical advances (analogous to the
|
|
|
|
// GetGlyphWidth method for horizontal advances). If that proves necessary,
|
|
|
|
// we'll add a new gfxFont method and call it from here.
|
2017-09-21 16:15:02 +03:00
|
|
|
//
|
|
|
|
// We negate the value from GetGlyphVAdvance here because harfbuzz shapes
|
|
|
|
// with a coordinate system where positive is upwards, whereas the inline
|
|
|
|
// direction in which glyphs advance is downwards.
|
|
|
|
return -fcd->mShaper->GetGlyphVAdvance(glyph);
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct VORG {
|
|
|
|
AutoSwap_PRUint16 majorVersion;
|
|
|
|
AutoSwap_PRUint16 minorVersion;
|
|
|
|
AutoSwap_PRInt16 defaultVertOriginY;
|
|
|
|
AutoSwap_PRUint16 numVertOriginYMetrics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VORGrec {
|
|
|
|
AutoSwap_PRUint16 glyphIndex;
|
|
|
|
AutoSwap_PRInt16 vertOriginY;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
hb_bool_t gfxHarfBuzzShaper::HBGetGlyphVOrigin(hb_font_t* font, void* font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_position_t* x,
|
|
|
|
hb_position_t* y,
|
|
|
|
void* user_data) {
|
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
2018-12-31 14:43:27 +03:00
|
|
|
fcd->mShaper->GetGlyphVOrigin(glyph, x, y);
|
2014-10-01 23:25:48 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-31 14:43:27 +03:00
|
|
|
void gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
|
2014-10-01 23:25:48 +04:00
|
|
|
hb_position_t* aX,
|
|
|
|
hb_position_t* aY) const {
|
2018-12-31 14:43:27 +03:00
|
|
|
*aX = 0.5 * (mUseFontGlyphWidths ? mFont->GetGlyphWidth(aGlyph)
|
2018-02-16 15:40:43 +03:00
|
|
|
: GetGlyphHAdvance(aGlyph));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
if (mVORGTable) {
|
|
|
|
// We checked in Initialize() that the VORG table is safely readable,
|
|
|
|
// so no length/bounds-check needed here.
|
|
|
|
const VORG* vorg =
|
|
|
|
reinterpret_cast<const VORG*>(hb_blob_get_data(mVORGTable, nullptr));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
const VORGrec* lo = reinterpret_cast<const VORGrec*>(vorg + 1);
|
|
|
|
const VORGrec* hi = lo + uint16_t(vorg->numVertOriginYMetrics);
|
|
|
|
const VORGrec* limit = hi;
|
|
|
|
while (lo < hi) {
|
|
|
|
const VORGrec* mid = lo + (hi - lo) / 2;
|
|
|
|
if (uint16_t(mid->glyphIndex) < aGlyph) {
|
|
|
|
lo = mid + 1;
|
|
|
|
} else {
|
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lo < limit && uint16_t(lo->glyphIndex) == aGlyph) {
|
2017-10-27 20:57:45 +03:00
|
|
|
*aY = FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
|
|
|
|
int16_t(lo->vertOriginY));
|
2014-10-01 23:25:48 +04:00
|
|
|
} else {
|
2017-10-27 20:57:45 +03:00
|
|
|
*aY = FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
|
|
|
|
int16_t(vorg->defaultVertOriginY));
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
|
2015-01-15 14:07:26 +03:00
|
|
|
if (mVmtxTable) {
|
2015-01-28 12:03:28 +03:00
|
|
|
bool emptyGlyf;
|
|
|
|
const Glyf* glyf = FindGlyf(aGlyph, &emptyGlyf);
|
|
|
|
if (glyf) {
|
|
|
|
if (emptyGlyf) {
|
2015-01-15 14:07:26 +03:00
|
|
|
*aY = 0;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-02-23 05:29:46 +03:00
|
|
|
const ::GlyphMetrics* metrics = reinterpret_cast<const ::GlyphMetrics*>(
|
2015-01-15 14:07:26 +03:00
|
|
|
hb_blob_get_data(mVmtxTable, nullptr));
|
2015-03-26 15:23:45 +03:00
|
|
|
int16_t lsb;
|
|
|
|
if (aGlyph < hb_codepoint_t(mNumLongVMetrics)) {
|
|
|
|
// Glyph is covered by the first (advance & sidebearing) array
|
|
|
|
lsb = int16_t(metrics->metrics[aGlyph].lsb);
|
|
|
|
} else {
|
|
|
|
// Glyph is covered by the second (sidebearing-only) array
|
|
|
|
const AutoSwap_PRInt16* sidebearings =
|
|
|
|
reinterpret_cast<const AutoSwap_PRInt16*>(
|
|
|
|
&metrics->metrics[mNumLongVMetrics]);
|
|
|
|
lsb = int16_t(sidebearings[aGlyph - mNumLongVMetrics]);
|
|
|
|
}
|
2017-10-27 20:57:45 +03:00
|
|
|
*aY = FloatToFixed(mFont->FUnitsToDevUnitsFactor() *
|
|
|
|
(lsb + int16_t(glyf->yMax)));
|
2015-01-15 14:07:26 +03:00
|
|
|
return;
|
|
|
|
} else {
|
2015-01-28 12:03:28 +03:00
|
|
|
// XXX TODO: not a truetype font; need to get glyph extents
|
|
|
|
// via some other API?
|
2015-01-15 14:07:26 +03:00
|
|
|
// For now, fall through to default code below.
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-15 14:07:26 +03:00
|
|
|
|
2018-02-16 15:40:43 +03:00
|
|
|
if (mDefaultVOrg < 0.0) {
|
|
|
|
// XXX should we consider using OS/2 sTypo* metrics if available?
|
|
|
|
|
|
|
|
gfxFontEntry::AutoTable hheaTable(GetFont()->GetFontEntry(),
|
|
|
|
TRUETYPE_TAG('h', 'h', 'e', 'a'));
|
|
|
|
if (hheaTable) {
|
|
|
|
uint32_t len;
|
|
|
|
const MetricsHeader* hhea = reinterpret_cast<const MetricsHeader*>(
|
|
|
|
hb_blob_get_data(hheaTable, &len));
|
|
|
|
if (len >= sizeof(MetricsHeader)) {
|
|
|
|
// divide up the default advance we're using (1em) in proportion
|
|
|
|
// to ascender:descender from the hhea table
|
|
|
|
int16_t a = int16_t(hhea->ascender);
|
|
|
|
int16_t d = int16_t(hhea->descender);
|
|
|
|
mDefaultVOrg = FloatToFixed(GetFont()->GetAdjustedSize() * a / (a - d));
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 15:40:43 +03:00
|
|
|
if (mDefaultVOrg < 0.0) {
|
|
|
|
// Last resort, for non-sfnt fonts: get the horizontal metrics and
|
|
|
|
// compute a default VOrg from their ascent and descent.
|
2015-01-28 12:03:28 +03:00
|
|
|
const gfxFont::Metrics& mtx = mFont->GetHorizontalMetrics();
|
2019-04-01 17:32:19 +03:00
|
|
|
gfxFloat advance =
|
|
|
|
mFont->GetMetrics(nsFontMetrics::eVertical).aveCharWidth;
|
2018-02-16 15:40:43 +03:00
|
|
|
gfxFloat ascent = mtx.emAscent;
|
|
|
|
gfxFloat height = ascent + mtx.emDescent;
|
|
|
|
// vOrigin that will place the glyph so that its origin is shifted
|
|
|
|
// down most of the way within overall (vertical) advance, in
|
|
|
|
// proportion to the font ascent as a part of the overall font
|
|
|
|
// height.
|
2014-10-01 23:25:48 +04:00
|
|
|
mDefaultVOrg = FloatToFixed(advance * ascent / height);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 15:40:43 +03:00
|
|
|
*aY = mDefaultVOrg;
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
static hb_bool_t HBGetGlyphExtents(hb_font_t* font, void* font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t* extents,
|
|
|
|
void* user_data) {
|
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
|
|
|
return fcd->mShaper->GetGlyphExtents(glyph, extents);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the data for glyph ID |aGlyph| in the 'glyf' table, if present.
|
|
|
|
// Returns null if not found, otherwise pointer to the beginning of the
|
|
|
|
// glyph's data. Sets aEmptyGlyf true if there is no actual data;
|
|
|
|
// otherwise, it's guaranteed that we can read at least the bounding box.
|
|
|
|
const gfxHarfBuzzShaper::Glyf* gfxHarfBuzzShaper::FindGlyf(
|
|
|
|
hb_codepoint_t aGlyph, bool* aEmptyGlyf) const {
|
|
|
|
if (!mLoadedLocaGlyf) {
|
|
|
|
mLoadedLocaGlyf = true; // only try this once; if it fails, this
|
|
|
|
// isn't a truetype font
|
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
|
|
|
uint32_t len;
|
2014-10-01 23:25:48 +04:00
|
|
|
gfxFontEntry::AutoTable headTable(entry, TRUETYPE_TAG('h', 'e', 'a', 'd'));
|
2015-02-10 12:18:23 +03:00
|
|
|
if (!headTable) {
|
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-28 12:03:28 +03:00
|
|
|
const HeadTable* head =
|
|
|
|
reinterpret_cast<const HeadTable*>(hb_blob_get_data(headTable, &len));
|
|
|
|
if (len < sizeof(HeadTable)) {
|
2015-02-10 12:18:23 +03:00
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-28 12:03:28 +03:00
|
|
|
mLocaLongOffsets = int16_t(head->indexToLocFormat) > 0;
|
|
|
|
mLocaTable = entry->GetFontTable(TRUETYPE_TAG('l', 'o', 'c', 'a'));
|
|
|
|
mGlyfTable = entry->GetFontTable(TRUETYPE_TAG('g', 'l', 'y', 'f'));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
if (!mLocaTable || !mGlyfTable) {
|
|
|
|
// it's not a truetype font
|
2015-02-10 12:18:23 +03:00
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
uint32_t offset; // offset of glyph record in the 'glyf' table
|
|
|
|
uint32_t len;
|
|
|
|
const char* data = hb_blob_get_data(mLocaTable, &len);
|
|
|
|
if (mLocaLongOffsets) {
|
|
|
|
if ((aGlyph + 1) * sizeof(AutoSwap_PRUint32) > len) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const AutoSwap_PRUint32* offsets =
|
|
|
|
reinterpret_cast<const AutoSwap_PRUint32*>(data);
|
|
|
|
offset = offsets[aGlyph];
|
|
|
|
*aEmptyGlyf = (offset == uint16_t(offsets[aGlyph + 1]));
|
|
|
|
} else {
|
|
|
|
if ((aGlyph + 1) * sizeof(AutoSwap_PRUint16) > len) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const AutoSwap_PRUint16* offsets =
|
|
|
|
reinterpret_cast<const AutoSwap_PRUint16*>(data);
|
|
|
|
offset = uint16_t(offsets[aGlyph]);
|
|
|
|
*aEmptyGlyf = (offset == uint16_t(offsets[aGlyph + 1]));
|
|
|
|
offset *= 2;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
data = hb_blob_get_data(mGlyfTable, &len);
|
|
|
|
if (offset + sizeof(Glyf) > len) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
return reinterpret_cast<const Glyf*>(data + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_bool_t gfxHarfBuzzShaper::GetGlyphExtents(
|
|
|
|
hb_codepoint_t aGlyph, hb_glyph_extents_t* aExtents) const {
|
|
|
|
bool emptyGlyf;
|
|
|
|
const Glyf* glyf = FindGlyf(aGlyph, &emptyGlyf);
|
|
|
|
if (!glyf) {
|
|
|
|
// TODO: for non-truetype fonts, get extents some other way?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emptyGlyf) {
|
|
|
|
aExtents->x_bearing = 0;
|
|
|
|
aExtents->y_bearing = 0;
|
|
|
|
aExtents->width = 0;
|
|
|
|
aExtents->height = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double f = mFont->FUnitsToDevUnitsFactor();
|
|
|
|
aExtents->x_bearing = FloatToFixed(int16_t(glyf->xMin) * f);
|
|
|
|
aExtents->width =
|
|
|
|
FloatToFixed((int16_t(glyf->xMax) - int16_t(glyf->xMin)) * f);
|
|
|
|
|
|
|
|
// Our y-coordinates are positive-downwards, whereas harfbuzz assumes
|
|
|
|
// positive-upwards; hence the apparently-reversed subtractions here.
|
|
|
|
aExtents->y_bearing = FloatToFixed(int16_t(glyf->yMax) * f -
|
|
|
|
mFont->GetHorizontalMetrics().emAscent);
|
|
|
|
aExtents->height =
|
|
|
|
FloatToFixed((int16_t(glyf->yMin) - int16_t(glyf->yMax)) * f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-14 12:03:01 +04:00
|
|
|
static hb_bool_t HBGetContourPoint(hb_font_t* font, void* font_data,
|
2009-10-07 21:16:52 +04:00
|
|
|
unsigned int point_index,
|
2012-02-14 12:03:01 +04:00
|
|
|
hb_codepoint_t glyph, hb_position_t* x,
|
|
|
|
hb_position_t* y, void* user_data) {
|
2009-10-07 21:16:52 +04:00
|
|
|
/* not yet implemented - no support for used of hinted contour points
|
|
|
|
to fine-tune anchor positions in GPOS AnchorFormat2 */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
struct KernHeaderFmt0 {
|
|
|
|
AutoSwap_PRUint16 nPairs;
|
|
|
|
AutoSwap_PRUint16 searchRange;
|
|
|
|
AutoSwap_PRUint16 entrySelector;
|
|
|
|
AutoSwap_PRUint16 rangeShift;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KernPair {
|
|
|
|
AutoSwap_PRUint16 left;
|
|
|
|
AutoSwap_PRUint16 right;
|
|
|
|
AutoSwap_PRInt16 value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find a kern pair in a Format 0 subtable.
|
|
|
|
// The aSubtable parameter points to the subtable itself, NOT its header,
|
|
|
|
// as the header structure differs between Windows and Mac (v0 and v1.0)
|
|
|
|
// versions of the 'kern' table.
|
|
|
|
// aSubtableLen is the length of the subtable EXCLUDING its header.
|
|
|
|
// If the pair <aFirstGlyph,aSecondGlyph> is found, the kerning value is
|
|
|
|
// added to aValue, so that multiple subtables can accumulate a total
|
|
|
|
// kerning value for a given pair.
|
|
|
|
static void GetKernValueFmt0(const void* aSubtable, uint32_t aSubtableLen,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aFirstGlyph, uint16_t aSecondGlyph,
|
2011-09-29 10:19:26 +04:00
|
|
|
int32_t& aValue, bool aIsOverride = false,
|
|
|
|
bool aIsMinimum = false) {
|
2010-07-28 17:36:07 +04:00
|
|
|
const KernHeaderFmt0* hdr =
|
|
|
|
reinterpret_cast<const KernHeaderFmt0*>(aSubtable);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
const KernPair* lo = reinterpret_cast<const KernPair*>(hdr + 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
const KernPair* hi = lo + uint16_t(hdr->nPairs);
|
2010-09-22 13:15:57 +04:00
|
|
|
const KernPair* limit = hi;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
if (reinterpret_cast<const char*>(aSubtable) + aSubtableLen <
|
|
|
|
reinterpret_cast<const char*>(hi)) {
|
|
|
|
// subtable is not large enough to contain the claimed number
|
|
|
|
// of kern pairs, so just ignore it
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
#define KERN_PAIR_KEY(l, r) (uint32_t((uint16_t(l) << 16) + uint16_t(r)))
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t key = KERN_PAIR_KEY(aFirstGlyph, aSecondGlyph);
|
2010-07-28 17:36:07 +04:00
|
|
|
while (lo < hi) {
|
|
|
|
const KernPair* mid = lo + (hi - lo) / 2;
|
|
|
|
if (KERN_PAIR_KEY(mid->left, mid->right) < key) {
|
|
|
|
lo = mid + 1;
|
|
|
|
} else {
|
|
|
|
hi = mid;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-28 17:36:07 +04:00
|
|
|
|
2010-09-22 13:15:57 +04:00
|
|
|
if (lo < limit && KERN_PAIR_KEY(lo->left, lo->right) == key) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (aIsOverride) {
|
2012-08-22 19:56:38 +04:00
|
|
|
aValue = int16_t(lo->value);
|
2010-07-28 17:36:07 +04:00
|
|
|
} else if (aIsMinimum) {
|
2013-01-15 16:22:03 +04:00
|
|
|
aValue = std::max(aValue, int32_t(lo->value));
|
2010-07-28 17:36:07 +04:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
aValue += int16_t(lo->value);
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get kerning value from Apple (version 1.0) kern table,
|
|
|
|
// subtable format 2 (simple N x M array of kerning values)
|
|
|
|
|
|
|
|
// See http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html
|
|
|
|
// for details of version 1.0 format 2 subtable.
|
|
|
|
|
|
|
|
struct KernHeaderVersion1Fmt2 {
|
|
|
|
KernTableSubtableHeaderVersion1 header;
|
|
|
|
AutoSwap_PRUint16 rowWidth;
|
|
|
|
AutoSwap_PRUint16 leftOffsetTable;
|
|
|
|
AutoSwap_PRUint16 rightOffsetTable;
|
|
|
|
AutoSwap_PRUint16 array;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KernClassTableHdr {
|
|
|
|
AutoSwap_PRUint16 firstGlyph;
|
|
|
|
AutoSwap_PRUint16 nGlyphs;
|
2014-08-29 08:18:28 +04:00
|
|
|
AutoSwap_PRUint16 offsets[1]; // actually an array of nGlyphs entries
|
2010-07-28 17:36:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int16_t GetKernValueVersion1Fmt2(const void* aSubtable,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSubtableLen,
|
|
|
|
uint16_t aFirstGlyph,
|
|
|
|
uint16_t aSecondGlyph) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (aSubtableLen < sizeof(KernHeaderVersion1Fmt2)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* base = reinterpret_cast<const char*>(aSubtable);
|
|
|
|
const char* subtableEnd = base + aSubtableLen;
|
|
|
|
|
|
|
|
const KernHeaderVersion1Fmt2* h =
|
|
|
|
reinterpret_cast<const KernHeaderVersion1Fmt2*>(aSubtable);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset = h->array;
|
2010-07-28 17:36:07 +04:00
|
|
|
|
|
|
|
const KernClassTableHdr* leftClassTable =
|
|
|
|
reinterpret_cast<const KernClassTableHdr*>(base +
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t(h->leftOffsetTable));
|
2010-07-28 17:36:07 +04:00
|
|
|
if (reinterpret_cast<const char*>(leftClassTable) +
|
|
|
|
sizeof(KernClassTableHdr) >
|
2012-08-22 19:56:38 +04:00
|
|
|
subtableEnd) {
|
2010-07-28 17:36:07 +04:00
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aFirstGlyph >= uint16_t(leftClassTable->firstGlyph)) {
|
|
|
|
aFirstGlyph -= uint16_t(leftClassTable->firstGlyph);
|
|
|
|
if (aFirstGlyph < uint16_t(leftClassTable->nGlyphs)) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (reinterpret_cast<const char*>(leftClassTable) +
|
|
|
|
sizeof(KernClassTableHdr) + aFirstGlyph * sizeof(uint16_t) >=
|
|
|
|
subtableEnd) {
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
offset = uint16_t(leftClassTable->offsets[aFirstGlyph]);
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const KernClassTableHdr* rightClassTable =
|
|
|
|
reinterpret_cast<const KernClassTableHdr*>(base +
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t(h->rightOffsetTable));
|
2010-07-28 17:36:07 +04:00
|
|
|
if (reinterpret_cast<const char*>(rightClassTable) +
|
|
|
|
sizeof(KernClassTableHdr) >
|
2012-08-22 19:56:38 +04:00
|
|
|
subtableEnd) {
|
2010-07-28 17:36:07 +04:00
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aSecondGlyph >= uint16_t(rightClassTable->firstGlyph)) {
|
|
|
|
aSecondGlyph -= uint16_t(rightClassTable->firstGlyph);
|
|
|
|
if (aSecondGlyph < uint16_t(rightClassTable->nGlyphs)) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (reinterpret_cast<const char*>(rightClassTable) +
|
|
|
|
sizeof(KernClassTableHdr) + aSecondGlyph * sizeof(uint16_t) >=
|
|
|
|
subtableEnd) {
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
offset += uint16_t(rightClassTable->offsets[aSecondGlyph]);
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const AutoSwap_PRInt16* pval =
|
|
|
|
reinterpret_cast<const AutoSwap_PRInt16*>(base + offset);
|
|
|
|
if (reinterpret_cast<const char*>(pval + 1) >= subtableEnd) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return *pval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get kerning value from Apple (version 1.0) kern table,
|
|
|
|
// subtable format 3 (simple N x M array of kerning values)
|
|
|
|
|
|
|
|
// See http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html
|
|
|
|
// for details of version 1.0 format 3 subtable.
|
|
|
|
|
|
|
|
struct KernHeaderVersion1Fmt3 {
|
|
|
|
KernTableSubtableHeaderVersion1 header;
|
|
|
|
AutoSwap_PRUint16 glyphCount;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t kernValueCount;
|
|
|
|
uint8_t leftClassCount;
|
|
|
|
uint8_t rightClassCount;
|
|
|
|
uint8_t flags;
|
2010-07-28 17:36:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int16_t GetKernValueVersion1Fmt3(const void* aSubtable,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSubtableLen,
|
|
|
|
uint16_t aFirstGlyph,
|
|
|
|
uint16_t aSecondGlyph) {
|
2010-07-28 17:36:07 +04:00
|
|
|
// check that we can safely read the header fields
|
|
|
|
if (aSubtableLen < sizeof(KernHeaderVersion1Fmt3)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KernHeaderVersion1Fmt3* hdr =
|
|
|
|
reinterpret_cast<const KernHeaderVersion1Fmt3*>(aSubtable);
|
|
|
|
if (hdr->flags != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t glyphCount = hdr->glyphCount;
|
2010-07-28 17:36:07 +04:00
|
|
|
|
|
|
|
// check that table is large enough for the arrays
|
2012-08-22 19:56:38 +04:00
|
|
|
if (sizeof(KernHeaderVersion1Fmt3) + hdr->kernValueCount * sizeof(int16_t) +
|
2010-07-28 17:36:07 +04:00
|
|
|
glyphCount + glyphCount + hdr->leftClassCount * hdr->rightClassCount >
|
|
|
|
aSubtableLen) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFirstGlyph >= glyphCount || aSecondGlyph >= glyphCount) {
|
|
|
|
// glyphs are out of range for the class tables
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
// get pointers to the four arrays within the subtable
|
|
|
|
const AutoSwap_PRInt16* kernValue =
|
|
|
|
reinterpret_cast<const AutoSwap_PRInt16*>(hdr + 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t* leftClass =
|
|
|
|
reinterpret_cast<const uint8_t*>(kernValue + hdr->kernValueCount);
|
|
|
|
const uint8_t* rightClass = leftClass + glyphCount;
|
|
|
|
const uint8_t* kernIndex = rightClass + glyphCount;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t lc = leftClass[aFirstGlyph];
|
|
|
|
uint8_t rc = rightClass[aSecondGlyph];
|
2010-07-28 17:36:07 +04:00
|
|
|
if (lc >= hdr->leftClassCount || rc >= hdr->rightClassCount) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t ki = kernIndex[leftClass[aFirstGlyph] * hdr->rightClassCount +
|
2010-07-28 17:36:07 +04:00
|
|
|
rightClass[aSecondGlyph]];
|
|
|
|
if (ki >= hdr->kernValueCount) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kernValue[ki];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KERN0_COVERAGE_HORIZONTAL 0x0001
|
|
|
|
#define KERN0_COVERAGE_MINIMUM 0x0002
|
|
|
|
#define KERN0_COVERAGE_CROSS_STREAM 0x0004
|
|
|
|
#define KERN0_COVERAGE_OVERRIDE 0x0008
|
|
|
|
#define KERN0_COVERAGE_RESERVED 0x00F0
|
|
|
|
|
|
|
|
#define KERN1_COVERAGE_VERTICAL 0x8000
|
|
|
|
#define KERN1_COVERAGE_CROSS_STREAM 0x4000
|
|
|
|
#define KERN1_COVERAGE_VARIATION 0x2000
|
|
|
|
#define KERN1_COVERAGE_RESERVED 0x1F00
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
hb_position_t gfxHarfBuzzShaper::GetHKerning(uint16_t aFirstGlyph,
|
|
|
|
uint16_t aSecondGlyph) const {
|
2010-07-28 17:36:07 +04:00
|
|
|
// We want to ignore any kern pairs involving <space>, because we are
|
|
|
|
// handling words in isolation, the only space characters seen here are
|
|
|
|
// the ones artificially added by the textRun code.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t spaceGlyph = mFont->GetSpaceGlyph();
|
2010-07-28 17:36:07 +04:00
|
|
|
if (aFirstGlyph == spaceGlyph || aSecondGlyph == spaceGlyph) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mKernTable) {
|
2013-05-16 20:29:20 +04:00
|
|
|
mKernTable =
|
|
|
|
mFont->GetFontEntry()->GetFontTable(TRUETYPE_TAG('k', 'e', 'r', 'n'));
|
2010-07-28 17:36:07 +04:00
|
|
|
if (!mKernTable) {
|
2012-02-14 12:03:01 +04:00
|
|
|
mKernTable = hb_blob_get_empty();
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-28 17:36:07 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len;
|
2012-02-14 12:03:01 +04:00
|
|
|
const char* base = hb_blob_get_data(mKernTable, &len);
|
2010-07-28 17:36:07 +04:00
|
|
|
if (len < sizeof(KernTableVersion0)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t value = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-28 17:36:07 +04:00
|
|
|
// First try to interpret as "version 0" kern table
|
|
|
|
// (see http://www.microsoft.com/typography/otspec/kern.htm)
|
|
|
|
const KernTableVersion0* kern0 =
|
|
|
|
reinterpret_cast<const KernTableVersion0*>(base);
|
2012-08-22 19:56:38 +04:00
|
|
|
if (uint16_t(kern0->version) == 0) {
|
|
|
|
uint16_t nTables = kern0->nTables;
|
|
|
|
uint32_t offs = sizeof(KernTableVersion0);
|
|
|
|
for (uint16_t i = 0; i < nTables; ++i) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (offs + sizeof(KernTableSubtableHeaderVersion0) > len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const KernTableSubtableHeaderVersion0* st0 =
|
|
|
|
reinterpret_cast<const KernTableSubtableHeaderVersion0*>(base + offs);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t subtableLen = uint16_t(st0->length);
|
2010-07-28 17:36:07 +04:00
|
|
|
if (offs + subtableLen > len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offs += subtableLen;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t coverage = st0->coverage;
|
2010-07-28 17:36:07 +04:00
|
|
|
if (!(coverage & KERN0_COVERAGE_HORIZONTAL)) {
|
|
|
|
// we only care about horizontal kerning (for now)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (coverage & (KERN0_COVERAGE_CROSS_STREAM | KERN0_COVERAGE_RESERVED)) {
|
|
|
|
// we don't support cross-stream kerning, and
|
|
|
|
// reserved bits should be zero;
|
|
|
|
// ignore the subtable if not
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t format = (coverage >> 8);
|
2010-07-28 17:36:07 +04:00
|
|
|
switch (format) {
|
|
|
|
case 0:
|
|
|
|
GetKernValueFmt0(st0 + 1, subtableLen - sizeof(*st0), aFirstGlyph,
|
|
|
|
aSecondGlyph, value,
|
|
|
|
(coverage & KERN0_COVERAGE_OVERRIDE) != 0,
|
|
|
|
(coverage & KERN0_COVERAGE_MINIMUM) != 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// TODO: implement support for other formats,
|
|
|
|
// if they're ever used in practice
|
|
|
|
#if DEBUG
|
|
|
|
{
|
|
|
|
char buf[1024];
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(buf,
|
|
|
|
"unknown kern subtable in %s: "
|
|
|
|
"ver 0 format %d\n",
|
2018-09-12 22:34:57 +03:00
|
|
|
mFont->GetName().get(), format);
|
2010-07-28 17:36:07 +04:00
|
|
|
NS_WARNING(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-28 17:36:07 +04:00
|
|
|
// It wasn't a "version 0" table; check if it is Apple version 1.0
|
|
|
|
// (see http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html)
|
|
|
|
const KernTableVersion1* kern1 =
|
|
|
|
reinterpret_cast<const KernTableVersion1*>(base);
|
2012-08-22 19:56:38 +04:00
|
|
|
if (uint32_t(kern1->version) == 0x00010000) {
|
|
|
|
uint32_t nTables = kern1->nTables;
|
|
|
|
uint32_t offs = sizeof(KernTableVersion1);
|
|
|
|
for (uint32_t i = 0; i < nTables; ++i) {
|
2010-07-28 17:36:07 +04:00
|
|
|
if (offs + sizeof(KernTableSubtableHeaderVersion1) > len) {
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
|
|
|
const KernTableSubtableHeaderVersion1* st1 =
|
|
|
|
reinterpret_cast<const KernTableSubtableHeaderVersion1*>(base +
|
2012-08-22 19:56:38 +04:00
|
|
|
offs);
|
|
|
|
uint32_t subtableLen = uint32_t(st1->length);
|
2010-07-28 17:36:07 +04:00
|
|
|
offs += subtableLen;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t coverage = st1->coverage;
|
2010-07-28 17:36:07 +04:00
|
|
|
if (coverage & (KERN1_COVERAGE_VERTICAL | KERN1_COVERAGE_CROSS_STREAM |
|
|
|
|
KERN1_COVERAGE_VARIATION | KERN1_COVERAGE_RESERVED)) {
|
|
|
|
// we only care about horizontal kerning (for now),
|
|
|
|
// we don't support cross-stream kerning,
|
|
|
|
// we don't support variations,
|
|
|
|
// reserved bits should be zero;
|
|
|
|
// ignore the subtable if not
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t format = (coverage & 0xff);
|
2010-07-28 17:36:07 +04:00
|
|
|
switch (format) {
|
|
|
|
case 0:
|
|
|
|
GetKernValueFmt0(st1 + 1, subtableLen - sizeof(*st1), aFirstGlyph,
|
|
|
|
aSecondGlyph, value);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
value = GetKernValueVersion1Fmt2(st1, subtableLen, aFirstGlyph,
|
|
|
|
aSecondGlyph);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
value = GetKernValueVersion1Fmt3(st1, subtableLen, aFirstGlyph,
|
|
|
|
aSecondGlyph);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// TODO: implement support for other formats.
|
|
|
|
// Note that format 1 cannot be supported here,
|
|
|
|
// as it requires the full glyph array to run the FSM,
|
|
|
|
// not just the current glyph pair.
|
|
|
|
#if DEBUG
|
|
|
|
{
|
|
|
|
char buf[1024];
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(buf,
|
|
|
|
"unknown kern subtable in %s: "
|
|
|
|
"ver 0 format %d\n",
|
2018-09-12 22:34:57 +03:00
|
|
|
mFont->GetName().get(), format);
|
2010-07-28 17:36:07 +04:00
|
|
|
NS_WARNING(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-28 17:36:07 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-28 17:36:07 +04:00
|
|
|
|
|
|
|
if (value != 0) {
|
|
|
|
return FloatToFixed(mFont->FUnitsToDevUnitsFactor() * value);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 12:03:01 +04:00
|
|
|
static hb_position_t HBGetHKerning(hb_font_t* font, void* font_data,
|
|
|
|
hb_codepoint_t first_glyph,
|
|
|
|
hb_codepoint_t second_glyph,
|
|
|
|
void* user_data) {
|
2013-05-16 20:29:20 +04:00
|
|
|
const gfxHarfBuzzShaper::FontCallbackData* fcd =
|
|
|
|
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
|
|
|
|
return fcd->mShaper->GetHKerning(first_glyph, second_glyph);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HarfBuzz unicode property callbacks
|
|
|
|
*/
|
|
|
|
|
2012-08-06 14:42:20 +04:00
|
|
|
static hb_codepoint_t HBGetMirroring(hb_unicode_funcs_t* ufuncs,
|
|
|
|
hb_codepoint_t aCh, void* user_data) {
|
2012-02-24 14:15:46 +04:00
|
|
|
return GetMirroredChar(aCh);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-14 12:03:01 +04:00
|
|
|
static hb_unicode_general_category_t HBGetGeneralCategory(
|
2012-08-06 14:42:20 +04:00
|
|
|
hb_unicode_funcs_t* ufuncs, hb_codepoint_t aCh, void* user_data) {
|
2012-02-24 14:15:46 +04:00
|
|
|
return hb_unicode_general_category_t(GetGeneralCategory(aCh));
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-14 12:03:01 +04:00
|
|
|
static hb_script_t HBGetScript(hb_unicode_funcs_t* ufuncs, hb_codepoint_t aCh,
|
|
|
|
void* user_data) {
|
2012-08-06 14:42:20 +04:00
|
|
|
return hb_script_t(GetScriptTagForCode(GetScriptCode(aCh)));
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2012-08-06 14:42:20 +04:00
|
|
|
static hb_unicode_combining_class_t HBGetCombiningClass(
|
|
|
|
hb_unicode_funcs_t* ufuncs, hb_codepoint_t aCh, void* user_data) {
|
|
|
|
return hb_unicode_combining_class_t(GetCombiningClass(aCh));
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-21 00:39:59 +04:00
|
|
|
// Hebrew presentation forms with dagesh, for characters 0x05D0..0x05EA;
|
|
|
|
// note that some letters do not have a dagesh presForm encoded
|
2014-01-04 19:02:17 +04:00
|
|
|
static const char16_t sDageshForms[0x05EA - 0x05D0 + 1] = {
|
2012-02-21 00:39:59 +04:00
|
|
|
0xFB30, // ALEF
|
|
|
|
0xFB31, // BET
|
|
|
|
0xFB32, // GIMEL
|
|
|
|
0xFB33, // DALET
|
|
|
|
0xFB34, // HE
|
|
|
|
0xFB35, // VAV
|
|
|
|
0xFB36, // ZAYIN
|
|
|
|
0, // HET
|
|
|
|
0xFB38, // TET
|
|
|
|
0xFB39, // YOD
|
|
|
|
0xFB3A, // FINAL KAF
|
|
|
|
0xFB3B, // KAF
|
|
|
|
0xFB3C, // LAMED
|
|
|
|
0, // FINAL MEM
|
|
|
|
0xFB3E, // MEM
|
|
|
|
0, // FINAL NUN
|
|
|
|
0xFB40, // NUN
|
|
|
|
0xFB41, // SAMEKH
|
|
|
|
0, // AYIN
|
|
|
|
0xFB43, // FINAL PE
|
|
|
|
0xFB44, // PE
|
|
|
|
0, // FINAL TSADI
|
|
|
|
0xFB46, // TSADI
|
|
|
|
0xFB47, // QOF
|
|
|
|
0xFB48, // RESH
|
|
|
|
0xFB49, // SHIN
|
|
|
|
0xFB4A // TAV
|
|
|
|
};
|
|
|
|
|
2012-02-21 00:39:59 +04:00
|
|
|
static hb_bool_t HBUnicodeCompose(hb_unicode_funcs_t* ufuncs, hb_codepoint_t a,
|
|
|
|
hb_codepoint_t b, hb_codepoint_t* ab,
|
|
|
|
void* user_data) {
|
2015-05-11 21:57:28 +03:00
|
|
|
if (sNormalizer) {
|
|
|
|
UChar32 ch = unorm2_composePair(sNormalizer, a, b);
|
|
|
|
if (ch >= 0) {
|
|
|
|
*ab = ch;
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-11 21:57:28 +03:00
|
|
|
|
|
|
|
return false;
|
2012-02-21 00:39:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t HBUnicodeDecompose(hb_unicode_funcs_t* ufuncs,
|
|
|
|
hb_codepoint_t ab, hb_codepoint_t* a,
|
|
|
|
hb_codepoint_t* b, void* user_data) {
|
2014-06-02 15:46:49 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// Hack for the SamsungDevanagari font, bug 1012365:
|
|
|
|
// support U+0972 by decomposing it.
|
|
|
|
if (ab == 0x0972) {
|
|
|
|
*a = 0x0905;
|
|
|
|
*b = 0x0945;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2015-05-11 21:57:28 +03:00
|
|
|
|
|
|
|
if (!sNormalizer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Canonical decompositions are never more than two characters,
|
|
|
|
// or a maximum of 4 utf-16 code units.
|
|
|
|
const unsigned MAX_DECOMP_LENGTH = 4;
|
|
|
|
|
|
|
|
UErrorCode error = U_ZERO_ERROR;
|
|
|
|
UChar decomp[MAX_DECOMP_LENGTH];
|
|
|
|
int32_t len = unorm2_getRawDecomposition(sNormalizer, ab, decomp,
|
|
|
|
MAX_DECOMP_LENGTH, &error);
|
|
|
|
if (U_FAILURE(error) || len < 0) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-11 21:57:28 +03:00
|
|
|
UText text = UTEXT_INITIALIZER;
|
|
|
|
utext_openUChars(&text, decomp, len, &error);
|
|
|
|
NS_ASSERTION(U_SUCCESS(error), "UText failure?");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-11 21:57:28 +03:00
|
|
|
UChar32 ch = UTEXT_NEXT32(&text);
|
|
|
|
if (ch != U_SENTINEL) {
|
|
|
|
*a = ch;
|
|
|
|
}
|
|
|
|
ch = UTEXT_NEXT32(&text);
|
|
|
|
if (ch != U_SENTINEL) {
|
|
|
|
*b = ch;
|
|
|
|
}
|
|
|
|
utext_close(&text);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-11 21:57:28 +03:00
|
|
|
return *b != 0 || *a != ab;
|
2012-02-21 00:39:59 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 17:03:04 +04:00
|
|
|
static void AddOpenTypeFeature(const uint32_t& aTag, uint32_t& aValue,
|
|
|
|
void* aUserArg) {
|
2012-04-26 10:26:03 +04:00
|
|
|
nsTArray<hb_feature_t>* features =
|
|
|
|
static_cast<nsTArray<hb_feature_t>*>(aUserArg);
|
|
|
|
|
|
|
|
hb_feature_t feat = {0, 0, 0, UINT_MAX};
|
|
|
|
feat.tag = aTag;
|
|
|
|
feat.value = aValue;
|
|
|
|
features->AppendElement(feat);
|
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
/*
|
|
|
|
* gfxFontShaper override to initialize the text run using HarfBuzz
|
|
|
|
*/
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static hb_font_funcs_t* sHBFontFuncs = nullptr;
|
|
|
|
static hb_unicode_funcs_t* sHBUnicodeFuncs = nullptr;
|
2014-01-30 19:59:16 +04:00
|
|
|
static const hb_script_t sMathScript =
|
|
|
|
hb_ot_tag_to_script(HB_TAG('m', 'a', 't', 'h'));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
bool gfxHarfBuzzShaper::Initialize() {
|
|
|
|
if (mInitialized) {
|
|
|
|
return mHBFont != nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-04-23 17:57:42 +04:00
|
|
|
mInitialized = true;
|
|
|
|
mCallbackData.mShaper = this;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-28 12:03:28 +03:00
|
|
|
if (!sHBFontFuncs) {
|
2014-04-23 17:57:42 +04:00
|
|
|
// static function callback pointers, initialized by the first
|
|
|
|
// harfbuzz shaper used
|
|
|
|
sHBFontFuncs = hb_font_funcs_create();
|
|
|
|
hb_font_funcs_set_nominal_glyph_func(sHBFontFuncs, HBGetNominalGlyph,
|
|
|
|
nullptr, nullptr);
|
|
|
|
hb_font_funcs_set_variation_glyph_func(sHBFontFuncs, HBGetVariationGlyph,
|
2014-04-22 19:00:13 +04:00
|
|
|
nullptr, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
hb_font_funcs_set_glyph_h_advance_func(sHBFontFuncs, HBGetGlyphHAdvance,
|
2016-04-13 15:48:40 +03:00
|
|
|
nullptr, nullptr);
|
2014-10-01 23:25:48 +04:00
|
|
|
hb_font_funcs_set_glyph_v_advance_func(sHBFontFuncs, HBGetGlyphVAdvance,
|
2016-04-13 15:48:40 +03:00
|
|
|
nullptr, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
hb_font_funcs_set_glyph_v_origin_func(sHBFontFuncs, HBGetGlyphVOrigin,
|
|
|
|
nullptr, nullptr);
|
|
|
|
hb_font_funcs_set_glyph_extents_func(sHBFontFuncs, HBGetGlyphExtents,
|
2016-04-13 15:48:40 +03:00
|
|
|
nullptr, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
hb_font_funcs_set_glyph_contour_point_func(sHBFontFuncs, HBGetContourPoint,
|
|
|
|
nullptr, nullptr);
|
|
|
|
hb_font_funcs_set_glyph_h_kerning_func(sHBFontFuncs, HBGetHKerning, nullptr,
|
|
|
|
nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
sHBUnicodeFuncs = hb_unicode_funcs_create(hb_unicode_funcs_get_empty());
|
|
|
|
hb_unicode_funcs_set_mirroring_func(sHBUnicodeFuncs, HBGetMirroring,
|
2017-09-11 21:23:30 +03:00
|
|
|
nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_script_func(sHBUnicodeFuncs, HBGetScript, nullptr,
|
2014-04-23 17:57:42 +04:00
|
|
|
nullptr);
|
|
|
|
hb_unicode_funcs_set_general_category_func(
|
2014-10-01 23:25:48 +04:00
|
|
|
sHBUnicodeFuncs, HBGetGeneralCategory, nullptr, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
hb_unicode_funcs_set_combining_class_func(
|
|
|
|
sHBUnicodeFuncs, HBGetCombiningClass, nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_compose_func(sHBUnicodeFuncs, HBUnicodeCompose,
|
|
|
|
nullptr, nullptr);
|
|
|
|
hb_unicode_funcs_set_decompose_func(sHBUnicodeFuncs, HBUnicodeDecompose,
|
2016-04-13 15:48:40 +03:00
|
|
|
nullptr, nullptr);
|
2014-04-23 17:57:42 +04:00
|
|
|
|
2015-05-11 21:57:28 +03:00
|
|
|
UErrorCode error = U_ZERO_ERROR;
|
2017-05-02 18:41:42 +03:00
|
|
|
sNormalizer = unorm2_getNFCInstance(&error);
|
|
|
|
MOZ_ASSERT(U_SUCCESS(error), "failed to get ICU normalizer");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
2017-10-12 16:25:11 +03:00
|
|
|
if (!mUseFontGetGlyph) {
|
|
|
|
// get the cmap table and find offset to our subtable
|
|
|
|
mCmapTable = entry->GetFontTable(TRUETYPE_TAG('c', 'm', 'a', 'p'));
|
2014-04-23 17:57:42 +04:00
|
|
|
if (!mCmapTable) {
|
2017-10-12 16:25:11 +03:00
|
|
|
NS_WARNING("failed to load cmap, glyphs will be missing");
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-23 17:57:42 +04:00
|
|
|
uint32_t len;
|
|
|
|
const uint8_t* data = (const uint8_t*)hb_blob_get_data(mCmapTable, &len);
|
2014-09-08 12:53:29 +04:00
|
|
|
mCmapFormat = gfxFontUtils::FindPreferredSubtable(
|
2017-09-11 21:23:30 +03:00
|
|
|
data, len, &mSubtableOffset, &mUVSTableOffset);
|
2014-04-23 17:57:42 +04:00
|
|
|
if (mCmapFormat <= 0) {
|
2015-05-11 21:57:28 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
if (!mUseFontGlyphWidths) {
|
2014-10-01 23:25:48 +04:00
|
|
|
// If font doesn't implement GetGlyphWidth, we will be reading
|
|
|
|
// the metrics table directly, so make sure we can load it.
|
|
|
|
if (!LoadHmtxTable()) {
|
2015-05-11 21:57:28 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 18:41:42 +03:00
|
|
|
mBuffer = hb_buffer_create();
|
|
|
|
hb_buffer_set_unicode_funcs(mBuffer, sHBUnicodeFuncs);
|
|
|
|
hb_buffer_set_cluster_level(mBuffer,
|
|
|
|
HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-04-15 17:14:55 +03:00
|
|
|
mHBFont = CreateHBFont(mFont, sHBFontFuncs, &mCallbackData);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_font_t* gfxHarfBuzzShaper::CreateHBFont(gfxFont* aFont,
|
|
|
|
hb_font_funcs_t* aFontFuncs,
|
|
|
|
FontCallbackData* aCallbackData) {
|
|
|
|
hb_face_t* hbFace = aFont->GetFontEntry()->GetHBFace();
|
|
|
|
hb_font_t* result = hb_font_create(hbFace);
|
|
|
|
hb_face_destroy(hbFace);
|
|
|
|
|
|
|
|
if (!aFontFuncs || !aCallbackData ||
|
|
|
|
aFont->GetFontEntry()->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '))) {
|
|
|
|
hb_ot_font_set_funcs(result);
|
Bug 197649 - For OpenType/CFF fonts, use harfbuzz ot-font functions rather than thebes callbacks. r=jrmuizel
This provides glyph-extents support for these fonts, so that fallback diacritic positioning can work.
In principle we could try switching to the hb_ot_font functions for all fonts, but this carries
some risk of disrupting other issues: (1) on some platforms, our glyph-advance callbacks use platform
APIs rather than reading the font file directly, in order to respect hinting that may be in effect;
and (2) the hb_ot_font functions don't currently provide fallbacks for CJK Compatibility Ideographs
Standardized Variants, as implemented for Gecko in bug 989557, so that case would be regressed.
Hence, for the time being switching only for OpenType/CFF fonts, where the thebes callbacks are
known to be incomplete (no glyph-extents support) is the safer, more conservative approach.
Differential Revision: https://phabricator.services.mozilla.com/D29010
--HG--
extra : moz-landing-system : lando
2019-05-01 00:11:06 +03:00
|
|
|
} else {
|
2020-04-15 17:14:55 +03:00
|
|
|
hb_font_set_funcs(result, aFontFuncs, aCallbackData, nullptr);
|
Bug 197649 - For OpenType/CFF fonts, use harfbuzz ot-font functions rather than thebes callbacks. r=jrmuizel
This provides glyph-extents support for these fonts, so that fallback diacritic positioning can work.
In principle we could try switching to the hb_ot_font functions for all fonts, but this carries
some risk of disrupting other issues: (1) on some platforms, our glyph-advance callbacks use platform
APIs rather than reading the font file directly, in order to respect hinting that may be in effect;
and (2) the hb_ot_font functions don't currently provide fallbacks for CJK Compatibility Ideographs
Standardized Variants, as implemented for Gecko in bug 989557, so that case would be regressed.
Hence, for the time being switching only for OpenType/CFF fonts, where the thebes callbacks are
known to be incomplete (no glyph-extents support) is the safer, more conservative approach.
Differential Revision: https://phabricator.services.mozilla.com/D29010
--HG--
extra : moz-landing-system : lando
2019-05-01 00:11:06 +03:00
|
|
|
}
|
2020-04-15 17:14:55 +03:00
|
|
|
hb_font_set_ppem(result, aFont->GetAdjustedSize(), aFont->GetAdjustedSize());
|
|
|
|
uint32_t scale = FloatToFixed(aFont->GetAdjustedSize()); // 16.16 fixed-point
|
|
|
|
hb_font_set_scale(result, scale, scale);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-10-28 23:57:19 +03:00
|
|
|
AutoTArray<gfxFontVariation, 8> vars;
|
2020-04-15 17:14:55 +03:00
|
|
|
aFont->GetFontEntry()->GetVariationsForStyle(vars, *aFont->GetStyle());
|
2019-10-28 23:57:19 +03:00
|
|
|
if (vars.Length() > 0) {
|
2017-10-12 16:25:11 +03:00
|
|
|
// Fortunately, the hb_variation_t struct is compatible with our
|
2019-10-28 23:57:19 +03:00
|
|
|
// gfxFontVariation, so we can simply cast here.
|
|
|
|
static_assert(
|
|
|
|
sizeof(gfxFontVariation) == sizeof(hb_variation_t) &&
|
|
|
|
offsetof(gfxFontVariation, mTag) == offsetof(hb_variation_t, tag) &&
|
|
|
|
offsetof(gfxFontVariation, mValue) ==
|
|
|
|
offsetof(hb_variation_t, value),
|
|
|
|
"Gecko vs HarfBuzz struct mismatch!");
|
2017-10-12 16:25:11 +03:00
|
|
|
auto hbVars = reinterpret_cast<const hb_variation_t*>(vars.Elements());
|
2020-04-15 17:14:55 +03:00
|
|
|
hb_font_set_variations(result, hbVars, vars.Length());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-04-15 17:14:55 +03:00
|
|
|
return result;
|
2014-04-23 17:57:42 +04:00
|
|
|
}
|
2014-04-22 19:00:13 +04:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
bool gfxHarfBuzzShaper::LoadHmtxTable() {
|
|
|
|
// Read mNumLongHMetrics from metrics-head table without caching its
|
|
|
|
// blob, and preload/cache the metrics table.
|
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
|
|
|
gfxFontEntry::AutoTable hheaTable(entry, TRUETYPE_TAG('h', 'h', 'e', 'a'));
|
|
|
|
if (hheaTable) {
|
|
|
|
uint32_t len;
|
|
|
|
const MetricsHeader* hhea = reinterpret_cast<const MetricsHeader*>(
|
|
|
|
hb_blob_get_data(hheaTable, &len));
|
|
|
|
if (len >= sizeof(MetricsHeader)) {
|
|
|
|
mNumLongHMetrics = hhea->numOfLongMetrics;
|
|
|
|
if (mNumLongHMetrics > 0 && int16_t(hhea->metricDataFormat) == 0) {
|
|
|
|
// no point reading metrics if number of entries is zero!
|
|
|
|
// in that case, we won't be able to use this font
|
|
|
|
// (this method will return FALSE below if mHmtxTable
|
|
|
|
// is null)
|
|
|
|
mHmtxTable = entry->GetFontTable(TRUETYPE_TAG('h', 'm', 't', 'x'));
|
2015-03-09 15:16:22 +03:00
|
|
|
if (mHmtxTable && hb_blob_get_length(mHmtxTable) <
|
2014-10-01 23:25:48 +04:00
|
|
|
mNumLongHMetrics * sizeof(LongMetric)) {
|
|
|
|
// metrics table is not large enough for the claimed
|
|
|
|
// number of entries: invalid, do not use.
|
|
|
|
hb_blob_destroy(mHmtxTable);
|
|
|
|
mHmtxTable = nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
if (!mHmtxTable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxHarfBuzzShaper::InitializeVertical() {
|
2018-02-16 15:40:43 +03:00
|
|
|
// We only do this once. If we don't have a mHmtxTable after that,
|
|
|
|
// we'll be making up fallback metrics.
|
2015-03-12 13:03:09 +03:00
|
|
|
if (mVerticalInitialized) {
|
2018-02-16 15:40:43 +03:00
|
|
|
return;
|
2015-03-12 13:03:09 +03:00
|
|
|
}
|
|
|
|
mVerticalInitialized = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
if (!mHmtxTable) {
|
|
|
|
if (!LoadHmtxTable()) {
|
2018-02-16 15:40:43 +03:00
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
// Load vertical metrics if present in the font; if not, we'll synthesize
|
|
|
|
// vertical glyph advances based on (horizontal) ascent/descent metrics.
|
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
|
|
|
gfxFontEntry::AutoTable vheaTable(entry, TRUETYPE_TAG('v', 'h', 'e', 'a'));
|
|
|
|
if (vheaTable) {
|
|
|
|
uint32_t len;
|
|
|
|
const MetricsHeader* vhea = reinterpret_cast<const MetricsHeader*>(
|
|
|
|
hb_blob_get_data(vheaTable, &len));
|
|
|
|
if (len >= sizeof(MetricsHeader)) {
|
|
|
|
mNumLongVMetrics = vhea->numOfLongMetrics;
|
2015-03-26 15:23:45 +03:00
|
|
|
gfxFontEntry::AutoTable maxpTable(entry,
|
|
|
|
TRUETYPE_TAG('m', 'a', 'x', 'p'));
|
|
|
|
int numGlyphs = -1; // invalid if we fail to read 'maxp'
|
|
|
|
if (maxpTable &&
|
|
|
|
hb_blob_get_length(maxpTable) >= sizeof(MaxpTableHeader)) {
|
|
|
|
const MaxpTableHeader* maxp = reinterpret_cast<const MaxpTableHeader*>(
|
|
|
|
hb_blob_get_data(maxpTable, nullptr));
|
|
|
|
numGlyphs = uint16_t(maxp->numGlyphs);
|
|
|
|
}
|
|
|
|
if (mNumLongVMetrics > 0 && mNumLongVMetrics <= numGlyphs &&
|
2014-10-01 23:25:48 +04:00
|
|
|
int16_t(vhea->metricDataFormat) == 0) {
|
|
|
|
mVmtxTable = entry->GetFontTable(TRUETYPE_TAG('v', 'm', 't', 'x'));
|
2015-03-09 15:16:22 +03:00
|
|
|
if (mVmtxTable &&
|
|
|
|
hb_blob_get_length(mVmtxTable) <
|
2015-03-26 15:23:45 +03:00
|
|
|
mNumLongVMetrics * sizeof(LongMetric) +
|
|
|
|
(numGlyphs - mNumLongVMetrics) * sizeof(int16_t)) {
|
2014-10-01 23:25:48 +04:00
|
|
|
// metrics table is not large enough for the claimed
|
|
|
|
// number of entries: invalid, do not use.
|
|
|
|
hb_blob_destroy(mVmtxTable);
|
|
|
|
mVmtxTable = nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
|
|
|
|
// For CFF fonts only, load a VORG table if present.
|
|
|
|
if (entry->HasFontTable(TRUETYPE_TAG('C', 'F', 'F', ' '))) {
|
|
|
|
mVORGTable = entry->GetFontTable(TRUETYPE_TAG('V', 'O', 'R', 'G'));
|
|
|
|
if (mVORGTable) {
|
|
|
|
uint32_t len;
|
|
|
|
const VORG* vorg =
|
|
|
|
reinterpret_cast<const VORG*>(hb_blob_get_data(mVORGTable, &len));
|
|
|
|
if (len < sizeof(VORG) || uint16_t(vorg->majorVersion) != 1 ||
|
|
|
|
uint16_t(vorg->minorVersion) != 0 ||
|
|
|
|
len < sizeof(VORG) +
|
|
|
|
uint16_t(vorg->numVertOriginYMetrics) * sizeof(VORGrec)) {
|
|
|
|
// VORG table is an unknown version, or not large enough
|
|
|
|
// to be valid -- discard it.
|
|
|
|
NS_WARNING("discarding invalid VORG table");
|
|
|
|
hb_blob_destroy(mVORGTable);
|
|
|
|
mVORGTable = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
bool gfxHarfBuzzShaper::ShapeText(DrawTarget* aDrawTarget,
|
2014-04-23 17:57:42 +04:00
|
|
|
const char16_t* aText, uint32_t aOffset,
|
|
|
|
uint32_t aLength, Script aScript,
|
2017-04-03 19:49:17 +03:00
|
|
|
bool aVertical, RoundingFlags aRounding,
|
2014-04-23 17:57:42 +04:00
|
|
|
gfxShapedText* aShapedText) {
|
2015-05-22 10:40:04 +03:00
|
|
|
mUseVerticalPresentationForms = false;
|
2014-04-23 17:57:42 +04:00
|
|
|
|
|
|
|
if (!Initialize()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
if (aVertical) {
|
2018-02-16 15:40:43 +03:00
|
|
|
InitializeVertical();
|
2015-05-22 10:40:04 +03:00
|
|
|
if (!mFont->GetFontEntry()->SupportsOpenTypeFeature(
|
|
|
|
aScript, HB_TAG('v', 'e', 'r', 't'))) {
|
|
|
|
mUseVerticalPresentationForms = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
const gfxFontStyle* style = mFont->GetStyle();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-23 07:09:16 +04:00
|
|
|
// determine whether petite-caps falls back to small-caps
|
|
|
|
bool addSmallCaps = false;
|
|
|
|
if (style->variantCaps != NS_FONT_VARIANT_CAPS_NORMAL) {
|
|
|
|
switch (style->variantCaps) {
|
|
|
|
case NS_FONT_VARIANT_CAPS_ALLPETITE:
|
|
|
|
case NS_FONT_VARIANT_CAPS_PETITECAPS:
|
|
|
|
bool synLower, synUpper;
|
|
|
|
mFont->SupportsVariantCaps(aScript, style->variantCaps, addSmallCaps,
|
|
|
|
synLower, synUpper);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-22 09:41:02 +03:00
|
|
|
// insert any merged features into hb_feature array
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<hb_feature_t, 20> features;
|
2017-05-02 18:41:42 +03:00
|
|
|
MergeFontFeatures(style, entry->mFeatureSettings,
|
2015-01-22 09:41:02 +03:00
|
|
|
aShapedText->DisableLigatures(), entry->FamilyName(),
|
2017-05-02 18:41:42 +03:00
|
|
|
addSmallCaps, AddOpenTypeFeature, &features);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
bool isRightToLeft = aShapedText->IsRightToLeft();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_buffer_set_direction(
|
2014-10-01 23:25:48 +04:00
|
|
|
mBuffer, aVertical
|
|
|
|
? HB_DIRECTION_TTB
|
|
|
|
: (isRightToLeft ? HB_DIRECTION_RTL : HB_DIRECTION_LTR));
|
2014-01-30 19:59:16 +04:00
|
|
|
hb_script_t scriptTag;
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aShapedText->GetFlags() & gfx::ShapedTextFlags::TEXT_USE_MATH_SCRIPT) {
|
2014-01-30 19:59:16 +04:00
|
|
|
scriptTag = sMathScript;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2014-07-22 04:02:48 +04:00
|
|
|
scriptTag = GetHBScriptUsedForShaping(aScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_buffer_set_script(mBuffer, scriptTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
hb_language_t language;
|
|
|
|
if (style->languageOverride) {
|
|
|
|
language = hb_ot_tag_to_language(style->languageOverride);
|
2011-12-06 16:39:19 +04:00
|
|
|
} else if (entry->mLanguageOverride) {
|
|
|
|
language = hb_ot_tag_to_language(entry->mLanguageOverride);
|
2009-10-07 21:16:52 +04:00
|
|
|
} else if (style->explicitLanguage) {
|
2010-12-09 10:28:51 +03:00
|
|
|
nsCString langString;
|
|
|
|
style->language->ToUTF8String(langString);
|
2012-02-14 12:03:01 +04:00
|
|
|
language = hb_language_from_string(langString.get(), langString.Length());
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2014-12-23 15:50:10 +03:00
|
|
|
language = hb_ot_tag_to_language(HB_OT_TAG_DEFAULT_LANGUAGE);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_buffer_set_language(mBuffer, language);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t length = aLength;
|
2012-02-14 12:03:01 +04:00
|
|
|
hb_buffer_add_utf16(mBuffer, reinterpret_cast<const uint16_t*>(aText), length,
|
2011-12-06 16:39:19 +04:00
|
|
|
0, length);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_shape(mHBFont, mBuffer, features.Elements(), features.Length());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
if (isRightToLeft) {
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_buffer_reverse(mBuffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
nsresult rv = SetGlyphsFromRun(aShapedText, aOffset, aLength, aText,
|
2017-05-02 18:41:42 +03:00
|
|
|
aVertical, aRounding);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"failed to store glyphs into gfxShapedWord");
|
2017-05-02 18:41:42 +03:00
|
|
|
hb_buffer_clear_contents(mBuffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-07 20:25:19 +04:00
|
|
|
return NS_SUCCEEDED(rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
#define SMALL_GLYPH_RUN \
|
|
|
|
128 // some testing indicates that 90%+ of text runs
|
|
|
|
// will fit without requiring separate allocation
|
|
|
|
// for charToGlyphArray
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
nsresult gfxHarfBuzzShaper::SetGlyphsFromRun(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
|
|
|
bool aVertical,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding) {
|
2017-11-11 18:32:58 +03:00
|
|
|
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numGlyphs;
|
2017-05-02 18:41:42 +03:00
|
|
|
const hb_glyph_info_t* ginfo = hb_buffer_get_glyph_infos(mBuffer, &numGlyphs);
|
2011-12-06 16:39:19 +04:00
|
|
|
if (numGlyphs == 0) {
|
2009-10-07 21:16:52 +04:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<gfxTextRun::DetailedGlyph, 1> detailedGlyphs;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t wordLength = aLength;
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t NO_GLYPH = -1;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<int32_t, SMALL_GLYPH_RUN> charToGlyphArray;
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!charToGlyphArray.SetLength(wordLength, fallible)) {
|
2009-10-07 21:16:52 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* charToGlyph = charToGlyphArray.Elements();
|
|
|
|
for (uint32_t offset = 0; offset < wordLength; ++offset) {
|
2009-10-07 21:16:52 +04:00
|
|
|
charToGlyph[offset] = NO_GLYPH;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < numGlyphs; ++i) {
|
|
|
|
uint32_t loc = ginfo[i].cluster;
|
2011-12-06 16:39:19 +04:00
|
|
|
if (loc < wordLength) {
|
2009-10-07 21:16:52 +04:00
|
|
|
charToGlyph[loc] = i;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphStart = 0; // looking for a clump that starts at this glyph
|
|
|
|
int32_t charStart = 0; // and this char index within the range of the run
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-16 00:56:40 +03:00
|
|
|
bool roundI, roundB;
|
2014-10-01 23:25:48 +04:00
|
|
|
if (aVertical) {
|
2018-02-16 15:40:43 +03:00
|
|
|
roundI = bool(aRounding & RoundingFlags::kRoundY);
|
2017-04-03 19:49:17 +03:00
|
|
|
roundB = bool(aRounding & RoundingFlags::kRoundX);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-04-03 19:49:17 +03:00
|
|
|
roundI = bool(aRounding & RoundingFlags::kRoundX);
|
|
|
|
roundB = bool(aRounding & RoundingFlags::kRoundY);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-16 15:40:43 +03:00
|
|
|
int32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
|
2015-05-22 10:40:04 +03:00
|
|
|
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
// factor to convert 16.16 fixed-point pixels to app units
|
|
|
|
// (only used if not rounding)
|
|
|
|
double hb2appUnits = FixedToFloat(aShapedText->GetAppUnitsPerDevUnit());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
// Residual from rounding of previous advance, for use in rounding the
|
|
|
|
// subsequent offset or advance appropriately. 16.16 fixed-point
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2015-05-22 10:40:04 +03:00
|
|
|
// When rounding, the goal is to make the distance between glyphs and
|
2012-01-20 13:19:10 +04:00
|
|
|
// their base glyph equal to the integral number of pixels closest to that
|
|
|
|
// suggested by that shaper.
|
|
|
|
// i.e. posInfo[n].x_advance - posInfo[n].x_offset + posInfo[n+1].x_offset
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2012-01-20 13:19:10 +04:00
|
|
|
// The value of the residual is the part of the desired distance that has
|
|
|
|
// not been included in integer offsets.
|
2015-05-22 10:40:04 +03:00
|
|
|
hb_position_t residual = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
// keep track of y-position to set glyph offsets if needed
|
2014-10-01 23:25:48 +04:00
|
|
|
nscoord bPos = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-02-14 12:03:01 +04:00
|
|
|
const hb_glyph_position_t* posInfo =
|
2015-05-22 10:40:04 +03:00
|
|
|
hb_buffer_get_glyph_positions(mBuffer, nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
while (glyphStart < int32_t(numGlyphs)) {
|
2015-05-22 10:40:04 +03:00
|
|
|
int32_t charEnd = ginfo[glyphStart].cluster;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphEnd = glyphStart;
|
|
|
|
int32_t charLimit = wordLength;
|
2009-10-07 21:16:52 +04:00
|
|
|
while (charEnd < charLimit) {
|
2015-05-22 10:40:04 +03:00
|
|
|
// This is normally executed once for each iteration of the outer loop,
|
|
|
|
// but in unusual cases where the character/glyph association is complex,
|
2009-10-07 21:16:52 +04:00
|
|
|
// the initial character range might correspond to a non-contiguous
|
|
|
|
// glyph range with "holes" in it. If so, we will repeat this loop to
|
|
|
|
// extend the character range until we have a contiguous glyph sequence.
|
|
|
|
charEnd += 1;
|
|
|
|
while (charEnd != charLimit && charToGlyph[charEnd] == NO_GLYPH) {
|
|
|
|
charEnd += 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-22 10:40:04 +03:00
|
|
|
// find the maximum glyph index covered by the clump so far
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = charStart; i < charEnd; ++i) {
|
2009-10-07 21:16:52 +04:00
|
|
|
if (charToGlyph[i] != NO_GLYPH) {
|
2013-01-15 16:22:03 +04:00
|
|
|
glyphEnd = std::max(glyphEnd, charToGlyph[i] + 1);
|
2009-10-07 21:16:52 +04:00
|
|
|
// update extent of glyph range
|
2015-05-22 10:40:04 +03:00
|
|
|
}
|
2014-10-01 23:25:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
if (glyphEnd == glyphStart + 1) {
|
|
|
|
// for the common case of a single-glyph clump,
|
2014-06-23 07:09:16 +04:00
|
|
|
// we can skip the following checks
|
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
if (glyphEnd == glyphStart) {
|
2014-06-23 07:09:16 +04:00
|
|
|
// no glyphs, try to extend the clump
|
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-23 07:09:16 +04:00
|
|
|
// check whether all glyphs in the range are associated with the
|
|
|
|
// characters in our clump; if not, we have a discontinuous range, and
|
|
|
|
// should extend it unless we've reached the end of the text
|
|
|
|
bool allGlyphsAreWithinCluster = true;
|
|
|
|
for (int32_t i = glyphStart; i < glyphEnd; ++i) {
|
|
|
|
int32_t glyphCharIndex = ginfo[i].cluster;
|
|
|
|
if (glyphCharIndex < charStart || glyphCharIndex >= charEnd) {
|
|
|
|
allGlyphsAreWithinCluster = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-23 17:57:42 +04:00
|
|
|
if (allGlyphsAreWithinCluster) {
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:57:42 +04:00
|
|
|
NS_ASSERTION(glyphStart < glyphEnd,
|
|
|
|
"character/glyph clump contains no glyphs!");
|
|
|
|
NS_ASSERTION(charStart != charEnd,
|
2015-01-22 09:41:02 +03:00
|
|
|
"character/glyph clump contains no characters!");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-22 09:41:02 +03:00
|
|
|
// Now charStart..charEnd is a ligature clump, corresponding to
|
2016-02-02 18:36:30 +03:00
|
|
|
// glyphStart..glyphEnd; Set baseCharIndex to the char we'll actually attach
|
2015-01-22 09:41:02 +03:00
|
|
|
// the glyphs to (1st of ligature), and endCharIndex to the limit (position
|
2009-10-07 21:16:52 +04:00
|
|
|
// beyond the last char), adjusting for the offset of the stringRange
|
|
|
|
// relative to the textRun.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t baseCharIndex, endCharIndex;
|
2015-01-22 09:41:02 +03:00
|
|
|
while (charEnd < int32_t(wordLength) && charToGlyph[charEnd] == NO_GLYPH)
|
2009-10-07 21:16:52 +04:00
|
|
|
charEnd++;
|
|
|
|
baseCharIndex = charStart;
|
|
|
|
endCharIndex = charEnd;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
// Then we check if the clump falls outside our actual string range;
|
|
|
|
// if so, just go to the next.
|
2012-08-22 19:56:38 +04:00
|
|
|
if (baseCharIndex >= int32_t(wordLength)) {
|
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
2009-10-07 21:16:52 +04:00
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-22 09:41:02 +03:00
|
|
|
// Ensure we won't try to go beyond the valid length of the textRun's text
|
2013-01-15 16:22:03 +04:00
|
|
|
endCharIndex = std::min<int32_t>(endCharIndex, wordLength);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-22 09:41:02 +03:00
|
|
|
// Now we're ready to set the glyph info in the textRun
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphsInClump = glyphEnd - glyphStart;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-22 09:41:02 +03:00
|
|
|
// Check for default-ignorable char that didn't get filtered, combined,
|
|
|
|
// etc by the shaping process, and remove from the run.
|
|
|
|
// (This may be done within harfbuzz eventually.)
|
2013-01-04 22:35:37 +04:00
|
|
|
if (glyphsInClump == 1 && baseCharIndex + 1 == endCharIndex &&
|
2017-05-05 00:27:05 +03:00
|
|
|
aShapedText->FilterIfIgnorable(aOffset + baseCharIndex,
|
|
|
|
aText[baseCharIndex])) {
|
2012-08-22 19:56:38 +04:00
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
2009-10-07 21:16:52 +04:00
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
// HarfBuzz gives us physical x- and y-coordinates, but we will store
|
|
|
|
// them as logical inline- and block-direction values in the textrun.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
hb_position_t i_offset, i_advance; // inline-direction offset/advance
|
|
|
|
hb_position_t b_offset, b_advance; // block-direction offset/advance
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aVertical) {
|
2014-01-30 19:59:16 +04:00
|
|
|
// our coordinate directions are the opposite of harfbuzz's
|
|
|
|
// when doing top-to-bottom shaping
|
2017-09-21 16:15:02 +03:00
|
|
|
i_offset = -posInfo[glyphStart].y_offset;
|
|
|
|
i_advance = -posInfo[glyphStart].y_advance;
|
2014-01-30 19:59:16 +04:00
|
|
|
b_offset = -posInfo[glyphStart].x_offset;
|
2017-10-27 20:57:45 +03:00
|
|
|
b_advance = -posInfo[glyphStart].x_advance;
|
2014-01-30 19:59:16 +04:00
|
|
|
} else {
|
2014-07-22 04:02:48 +04:00
|
|
|
i_offset = posInfo[glyphStart].x_offset;
|
2014-10-01 23:25:48 +04:00
|
|
|
i_advance = posInfo[glyphStart].x_advance;
|
2017-05-02 18:41:42 +03:00
|
|
|
b_offset = posInfo[glyphStart].y_offset;
|
2010-12-09 10:28:51 +03:00
|
|
|
b_advance = posInfo[glyphStart].y_advance;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
nscoord iOffset, advance;
|
|
|
|
if (roundI) {
|
|
|
|
iOffset = appUnitsPerDevUnit * FixedToIntRound(i_offset + residual);
|
2012-02-14 12:03:01 +04:00
|
|
|
// Desired distance from the base glyph to the next reference point.
|
|
|
|
hb_position_t width = i_advance - i_offset;
|
|
|
|
int intWidth = FixedToIntRound(width);
|
|
|
|
residual = width - FloatToFixed(intWidth);
|
|
|
|
advance = appUnitsPerDevUnit * intWidth + iOffset;
|
2014-12-23 15:50:10 +03:00
|
|
|
} else {
|
|
|
|
iOffset = floor(hb2appUnits * i_offset + 0.5);
|
|
|
|
advance = floor(hb2appUnits * i_advance + 0.5);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
// Check if it's a simple one-to-one mapping
|
2017-04-03 19:49:17 +03:00
|
|
|
if (glyphsInClump == 1 &&
|
2017-11-11 18:32:58 +03:00
|
|
|
CompressedGlyph::IsSimpleGlyphID(ginfo[glyphStart].codepoint) &&
|
2016-02-02 18:36:30 +03:00
|
|
|
CompressedGlyph::IsSimpleAdvance(advance) &&
|
2012-08-22 19:56:38 +04:00
|
|
|
charGlyphs[baseCharIndex].IsClusterStart() && iOffset == 0 &&
|
|
|
|
b_offset == 0 && b_advance == 0 && bPos == 0) {
|
2009-10-07 21:16:52 +04:00
|
|
|
charGlyphs[baseCharIndex].SetSimpleGlyph(advance,
|
2012-08-22 19:56:38 +04:00
|
|
|
ginfo[glyphStart].codepoint);
|
2014-10-01 23:25:48 +04:00
|
|
|
} else {
|
2017-04-03 19:49:17 +03:00
|
|
|
// Collect all glyphs in a list to be assigned to the first char;
|
|
|
|
// there must be at least one in the clump, and we already measured
|
|
|
|
// its advance, hence the placement of the loop-exit test and the
|
2015-06-01 11:12:46 +03:00
|
|
|
// measurement of the next glyph.
|
2009-10-07 21:16:52 +04:00
|
|
|
while (1) {
|
2017-04-03 19:49:17 +03:00
|
|
|
gfxTextRun::DetailedGlyph* details = detailedGlyphs.AppendElement();
|
|
|
|
details->mGlyphID = ginfo[glyphStart].codepoint;
|
2011-12-06 16:39:19 +04:00
|
|
|
|
2012-01-20 13:19:10 +04:00
|
|
|
details->mAdvance = advance;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-01-20 13:19:10 +04:00
|
|
|
if (aVertical) {
|
|
|
|
details->mOffset.x =
|
2010-07-28 17:36:07 +04:00
|
|
|
bPos - (roundB ? appUnitsPerDevUnit * FixedToIntRound(b_offset)
|
2009-10-07 21:16:52 +04:00
|
|
|
: floor(hb2appUnits * b_offset + 0.5));
|
2012-08-22 19:56:38 +04:00
|
|
|
details->mOffset.y = iOffset;
|
2009-10-07 21:16:52 +04:00
|
|
|
} else {
|
|
|
|
details->mOffset.x = iOffset;
|
|
|
|
details->mOffset.y =
|
|
|
|
bPos - (roundB ? appUnitsPerDevUnit * FixedToIntRound(b_offset)
|
2012-08-22 19:56:38 +04:00
|
|
|
: floor(hb2appUnits * b_offset + 0.5));
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b_advance != 0) {
|
|
|
|
bPos -= roundB ? appUnitsPerDevUnit * FixedToIntRound(b_advance)
|
|
|
|
: floor(hb2appUnits * b_advance + 0.5);
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
if (++glyphStart >= glyphEnd) {
|
2009-10-07 21:16:52 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:48 +04:00
|
|
|
if (aVertical) {
|
2017-09-21 16:15:02 +03:00
|
|
|
i_offset = -posInfo[glyphStart].y_offset;
|
|
|
|
i_advance = -posInfo[glyphStart].y_advance;
|
2017-10-27 20:57:45 +03:00
|
|
|
b_offset = -posInfo[glyphStart].x_offset;
|
|
|
|
b_advance = -posInfo[glyphStart].x_advance;
|
2014-10-01 23:25:48 +04:00
|
|
|
} else {
|
|
|
|
i_offset = posInfo[glyphStart].x_offset;
|
|
|
|
i_advance = posInfo[glyphStart].x_advance;
|
|
|
|
b_offset = posInfo[glyphStart].y_offset;
|
|
|
|
b_advance = posInfo[glyphStart].y_advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (roundI) {
|
|
|
|
iOffset = appUnitsPerDevUnit * FixedToIntRound(i_offset + residual);
|
2012-01-20 13:19:10 +04:00
|
|
|
// Desired distance to the next reference point. The
|
|
|
|
// residual is considered here, and includes the residual
|
|
|
|
// from the base glyph offset and subsequent advances, so
|
|
|
|
// that the distance from the base glyph is optimized
|
2014-10-01 23:25:48 +04:00
|
|
|
// rather than the distance from combining marks.
|
|
|
|
i_advance += residual;
|
2012-01-20 13:19:10 +04:00
|
|
|
int intAdvance = FixedToIntRound(i_advance);
|
2014-10-01 23:25:48 +04:00
|
|
|
residual = i_advance - FloatToFixed(intAdvance);
|
|
|
|
advance = appUnitsPerDevUnit * intAdvance;
|
2012-01-20 13:19:10 +04:00
|
|
|
} else {
|
2017-10-30 17:55:42 +03:00
|
|
|
iOffset = floor(hb2appUnits * i_offset + 0.5);
|
2014-10-01 23:25:48 +04:00
|
|
|
advance = floor(hb2appUnits * i_advance + 0.5);
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
bool isClusterStart = charGlyphs[baseCharIndex].IsClusterStart();
|
2013-01-04 22:35:37 +04:00
|
|
|
aShapedText->SetGlyphs(aOffset + baseCharIndex,
|
2017-11-11 18:32:58 +03:00
|
|
|
CompressedGlyph::MakeComplex(
|
2013-01-04 22:35:37 +04:00
|
|
|
isClusterStart, true, detailedGlyphs.Length()),
|
|
|
|
detailedGlyphs.Elements());
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
detailedGlyphs.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// the rest of the chars in the group are ligature continuations,
|
|
|
|
// no associated glyphs
|
2010-12-05 21:38:12 +03:00
|
|
|
while (++baseCharIndex != endCharIndex &&
|
2012-08-22 19:56:38 +04:00
|
|
|
baseCharIndex < int32_t(wordLength)) {
|
2017-11-11 18:32:58 +03:00
|
|
|
CompressedGlyph& g = charGlyphs[baseCharIndex];
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
|
2017-11-11 18:32:58 +03:00
|
|
|
g.SetComplex(g.IsClusterStart(), false, 0);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|