2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2016-06-10 01:53:22 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-12-10 02:32:29 +04:00
|
|
|
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "gfxGraphiteShaper.h"
|
2011-12-10 02:32:29 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxContext.h"
|
2014-06-23 07:09:16 +04:00
|
|
|
#include "gfxFontConstants.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
#include "graphite2/Font.h"
|
|
|
|
#include "graphite2/Segment.h"
|
|
|
|
|
2012-04-22 01:24:39 +04:00
|
|
|
#include "harfbuzz/hb.h"
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
#define FloatToFixed(f) (65536 * (f))
|
|
|
|
#define FixedToFloat(f) ((f) * (1.0 / 65536.0))
|
|
|
|
// 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))
|
|
|
|
|
|
|
|
using namespace mozilla; // for AutoSwap_* types
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creation and destruction; on deletion, release any font tables we're holding
|
|
|
|
*/
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
gfxGraphiteShaper::gfxGraphiteShaper(gfxFont* aFont)
|
2011-12-10 02:32:29 +04:00
|
|
|
: gfxFontShaper(aFont),
|
2013-05-16 20:29:20 +04:00
|
|
|
mGrFace(mFont->GetFontEntry()->GetGrFace()),
|
2014-06-23 07:09:16 +04:00
|
|
|
mGrFont(nullptr),
|
|
|
|
mFallbackToSmallCaps(false) {
|
2018-04-13 16:01:28 +03:00
|
|
|
mCallbackData.mFont = aFont;
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxGraphiteShaper::~gfxGraphiteShaper() {
|
|
|
|
if (mGrFont) {
|
|
|
|
gr_font_destroy(mGrFont);
|
|
|
|
}
|
2013-05-16 20:29:20 +04:00
|
|
|
mFont->GetFontEntry()->ReleaseGrFace(mGrFace);
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
2019-05-01 11:47:10 +03:00
|
|
|
float gfxGraphiteShaper::GrGetAdvance(const void* appFontHandle,
|
2019-02-26 01:07:19 +03:00
|
|
|
uint16_t glyphid) {
|
2019-05-01 11:47:10 +03:00
|
|
|
const CallbackData* cb = static_cast<const CallbackData*>(appFontHandle);
|
2018-12-31 14:43:27 +03:00
|
|
|
return FixedToFloat(cb->mFont->GetGlyphWidth(glyphid));
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static inline uint32_t MakeGraphiteLangTag(uint32_t aTag) {
|
|
|
|
uint32_t grLangTag = aTag;
|
2011-12-10 02:32:29 +04:00
|
|
|
// replace trailing space-padding with NULs for graphite
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mask = 0x000000FF;
|
2011-12-10 02:32:29 +04:00
|
|
|
while ((grLangTag & mask) == ' ') {
|
|
|
|
grLangTag &= ~mask;
|
|
|
|
mask <<= 8;
|
|
|
|
}
|
|
|
|
return grLangTag;
|
|
|
|
}
|
|
|
|
|
2012-04-26 10:26:03 +04:00
|
|
|
struct GrFontFeatures {
|
2019-05-01 11:47:10 +03:00
|
|
|
gr_face* mFace;
|
|
|
|
gr_feature_val* mFeatures;
|
2012-04-26 10:26:03 +04:00
|
|
|
};
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
static void AddFeature(const uint32_t& aTag, uint32_t& aValue, void* aUserArg) {
|
|
|
|
GrFontFeatures* f = static_cast<GrFontFeatures*>(aUserArg);
|
2012-04-26 10:26:03 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const gr_feature_ref* fref = gr_face_find_fref(f->mFace, aTag);
|
2012-04-26 10:26:03 +04:00
|
|
|
if (fref) {
|
|
|
|
gr_fref_set_feature_value(fref, aValue, f->mFeatures);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool gfxGraphiteShaper::ShapeText(DrawTarget* aDrawTarget,
|
|
|
|
const char16_t* aText, uint32_t aOffset,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aLength, Script aScript,
|
2017-04-03 19:49:17 +03:00
|
|
|
bool aVertical, RoundingFlags aRounding,
|
2019-05-01 11:47:10 +03:00
|
|
|
gfxShapedText* aShapedText) {
|
2011-12-10 02:32:29 +04:00
|
|
|
// some font back-ends require this in order to get proper hinted metrics
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!mFont->SetupCairoFont(aDrawTarget)) {
|
2012-04-17 12:50:26 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
const gfxFontStyle* style = mFont->GetStyle();
|
2013-01-21 13:24:24 +04:00
|
|
|
|
|
|
|
if (!mGrFont) {
|
|
|
|
if (!mGrFace) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
if (mFont->ProvidesGlyphWidths()) {
|
|
|
|
gr_font_ops ops = {
|
2013-01-21 13:24:24 +04:00
|
|
|
sizeof(gr_font_ops), &GrGetAdvance,
|
2011-12-10 02:32:29 +04:00
|
|
|
nullptr // vertical text not yet implemented
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2013-01-21 13:24:24 +04:00
|
|
|
mGrFont = gr_make_font_with_ops(mFont->GetAdjustedSize(), &mCallbackData,
|
2011-12-10 02:32:29 +04:00
|
|
|
&ops, mGrFace);
|
|
|
|
} else {
|
2013-01-21 13:24:24 +04:00
|
|
|
mGrFont = gr_make_font(mFont->GetAdjustedSize(), mGrFace);
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
2014-06-23 07:09:16 +04:00
|
|
|
|
|
|
|
if (!mGrFont) {
|
|
|
|
return false;
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
// determine whether petite-caps falls back to small-caps
|
2011-12-10 02:32:29 +04:00
|
|
|
if (style->variantCaps != NS_FONT_VARIANT_CAPS_NORMAL) {
|
2014-12-23 15:50:10 +03:00
|
|
|
switch (style->variantCaps) {
|
|
|
|
case NS_FONT_VARIANT_CAPS_ALLPETITE:
|
2012-09-02 06:35:17 +04:00
|
|
|
case NS_FONT_VARIANT_CAPS_PETITECAPS:
|
|
|
|
bool synLower, synUpper;
|
2011-12-10 02:32:29 +04:00
|
|
|
mFont->SupportsVariantCaps(aScript, style->variantCaps,
|
|
|
|
mFallbackToSmallCaps, synLower, synUpper);
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
2011-12-10 02:32:29 +04:00
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
gfxFontEntry* entry = mFont->GetFontEntry();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t grLang = 0;
|
2011-12-10 02:32:29 +04:00
|
|
|
if (style->languageOverride) {
|
|
|
|
grLang = MakeGraphiteLangTag(style->languageOverride);
|
2011-12-06 16:39:19 +04:00
|
|
|
} else if (entry->mLanguageOverride) {
|
|
|
|
grLang = MakeGraphiteLangTag(entry->mLanguageOverride);
|
|
|
|
} else if (style->explicitLanguage) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString langString;
|
2011-12-10 02:32:29 +04:00
|
|
|
style->language->ToUTF8String(langString);
|
|
|
|
grLang = GetGraphiteTagForLang(langString);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-05-01 11:47:10 +03:00
|
|
|
gr_feature_val* grFeatures = gr_face_featureval_for_lang(mGrFace, grLang);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-22 09:41:02 +03:00
|
|
|
// insert any merged features into Graphite feature list
|
|
|
|
GrFontFeatures f = {mGrFace, grFeatures};
|
|
|
|
MergeFontFeatures(style, mFont->GetFontEntry()->mFeatureSettings,
|
|
|
|
aShapedText->DisableLigatures(),
|
|
|
|
mFont->GetFontEntry()->FamilyName(), mFallbackToSmallCaps,
|
|
|
|
AddFeature, &f);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-10 01:53:22 +03:00
|
|
|
// Graphite shaping doesn't map U+00a0 (nbsp) to space if it is missing
|
|
|
|
// from the font, so check for that possibility. (Most fonts double-map
|
|
|
|
// the space glyph to both 0x20 and 0xA0, so this won't often be needed;
|
|
|
|
// so we don't copy the text until we know it's required.)
|
|
|
|
nsAutoString transformed;
|
|
|
|
const char16_t NO_BREAK_SPACE = 0x00a0;
|
|
|
|
if (!entry->HasCharacter(NO_BREAK_SPACE)) {
|
|
|
|
nsDependentSubstring src(aText, aLength);
|
|
|
|
if (src.FindChar(NO_BREAK_SPACE) != kNotFound) {
|
|
|
|
transformed = src;
|
|
|
|
transformed.ReplaceChar(NO_BREAK_SPACE, ' ');
|
|
|
|
aText = transformed.BeginReading();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-06-10 01:53:22 +03:00
|
|
|
|
2013-02-14 03:40:24 +04:00
|
|
|
size_t numChars =
|
|
|
|
gr_count_unicode_characters(gr_utf16, aText, aText + aLength, nullptr);
|
2015-09-11 14:32:00 +03:00
|
|
|
gr_bidirtl grBidi = gr_bidirtl(
|
|
|
|
aShapedText->IsRightToLeft() ? (gr_rtl | gr_nobidi) : gr_nobidi);
|
2019-05-01 11:47:10 +03:00
|
|
|
gr_segment* seg = gr_make_seg(mGrFont, mGrFace, 0, grFeatures, gr_utf16,
|
2015-09-11 14:32:00 +03:00
|
|
|
aText, numChars, grBidi);
|
2012-04-26 10:26:03 +04:00
|
|
|
|
|
|
|
gr_featureval_destroy(grFeatures);
|
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
if (!seg) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
nsresult rv = SetGlyphsFromSegment(aShapedText, aOffset, aLength, aText, seg,
|
|
|
|
aRounding);
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
gr_seg_destroy(seg);
|
|
|
|
|
|
|
|
return NS_SUCCEEDED(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SMALL_GLYPH_RUN \
|
|
|
|
256 // avoid heap allocation of per-glyph data arrays
|
|
|
|
// for short (typical) runs up to this length
|
|
|
|
|
|
|
|
struct Cluster {
|
2013-02-14 03:40:24 +04:00
|
|
|
uint32_t baseChar; // in UTF16 code units, not Unicode character indices
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t baseGlyph;
|
2013-02-14 03:40:24 +04:00
|
|
|
uint32_t nChars; // UTF16 code units
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nGlyphs;
|
2011-12-10 02:32:29 +04:00
|
|
|
Cluster() : baseChar(0), baseGlyph(0), nChars(0), nGlyphs(0) {}
|
|
|
|
};
|
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
nsresult gfxGraphiteShaper::SetGlyphsFromSegment(
|
2019-05-01 11:47:10 +03:00
|
|
|
gfxShapedText* aShapedText, uint32_t aOffset, uint32_t aLength,
|
|
|
|
const char16_t* aText, gr_segment* aSegment, RoundingFlags aRounding) {
|
2017-11-11 18:32:58 +03:00
|
|
|
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
int32_t dev2appUnits = aShapedText->GetAppUnitsPerDevUnit();
|
|
|
|
bool rtl = aShapedText->IsRightToLeft();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t glyphCount = gr_seg_n_slots(aSegment);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
// identify clusters; graphite may have reordered/expanded/ligated glyphs.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<Cluster, SMALL_GLYPH_RUN> clusters;
|
|
|
|
AutoTArray<uint16_t, SMALL_GLYPH_RUN> gids;
|
|
|
|
AutoTArray<float, SMALL_GLYPH_RUN> xLocs;
|
|
|
|
AutoTArray<float, SMALL_GLYPH_RUN> yLocs;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!clusters.SetLength(aLength, fallible) ||
|
|
|
|
!gids.SetLength(glyphCount, fallible) ||
|
|
|
|
!xLocs.SetLength(glyphCount, fallible) ||
|
|
|
|
!yLocs.SetLength(glyphCount, fallible)) {
|
2011-12-10 02:32:29 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 23:50:35 +03:00
|
|
|
// walk through the glyph slots and check which original character
|
|
|
|
// each is associated with
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t gIndex = 0; // glyph slot index
|
|
|
|
uint32_t cIndex = 0; // current cluster index
|
2019-05-01 11:47:10 +03:00
|
|
|
for (const gr_slot* slot = gr_seg_first_slot(aSegment); slot != nullptr;
|
2015-05-18 23:50:35 +03:00
|
|
|
slot = gr_slot_next_in_segment(slot), gIndex++) {
|
2013-02-14 03:40:24 +04:00
|
|
|
uint32_t before =
|
2015-05-18 23:50:35 +03:00
|
|
|
gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_before(slot)));
|
2013-02-14 03:40:24 +04:00
|
|
|
uint32_t after = gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_after(slot)));
|
2011-12-10 02:32:29 +04:00
|
|
|
gids[gIndex] = gr_slot_gid(slot);
|
|
|
|
xLocs[gIndex] = gr_slot_origin_X(slot);
|
2015-05-18 23:50:35 +03:00
|
|
|
yLocs[gIndex] = gr_slot_origin_Y(slot);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-18 23:50:35 +03:00
|
|
|
// if this glyph has a "before" character index that precedes the
|
2011-12-10 02:32:29 +04:00
|
|
|
// current cluster's char index, we need to merge preceding
|
|
|
|
// clusters until it gets included
|
|
|
|
while (before < clusters[cIndex].baseChar && cIndex > 0) {
|
|
|
|
clusters[cIndex - 1].nChars += clusters[cIndex].nChars;
|
|
|
|
clusters[cIndex - 1].nGlyphs += clusters[cIndex].nGlyphs;
|
|
|
|
--cIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there's a gap between the current cluster's base character and
|
|
|
|
// this glyph's, extend the cluster to include the intervening chars
|
|
|
|
if (gr_slot_can_insert_before(slot) && clusters[cIndex].nChars &&
|
|
|
|
before >= clusters[cIndex].baseChar + clusters[cIndex].nChars) {
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(cIndex < aLength - 1, "cIndex at end of word");
|
2019-05-01 11:47:10 +03:00
|
|
|
Cluster& c = clusters[cIndex + 1];
|
2011-12-10 02:32:29 +04:00
|
|
|
c.baseChar = clusters[cIndex].baseChar + clusters[cIndex].nChars;
|
|
|
|
c.nChars = before - c.baseChar;
|
|
|
|
c.baseGlyph = gIndex;
|
|
|
|
c.nGlyphs = 0;
|
|
|
|
++cIndex;
|
|
|
|
}
|
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
// increment cluster's glyph count to include current slot
|
|
|
|
NS_ASSERTION(cIndex < aLength, "cIndex beyond word length");
|
|
|
|
++clusters[cIndex].nGlyphs;
|
2013-01-04 22:35:37 +04:00
|
|
|
|
2016-03-31 18:48:01 +03:00
|
|
|
// bump |after| index if it falls in the middle of a surrogate pair
|
|
|
|
if (NS_IS_HIGH_SURROGATE(aText[after]) && after < aLength - 1 &&
|
|
|
|
NS_IS_LOW_SURROGATE(aText[after + 1])) {
|
2018-11-30 13:46:48 +03:00
|
|
|
after++;
|
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
// extend cluster if necessary to reach the glyph's "after" index
|
|
|
|
if (clusters[cIndex].baseChar + clusters[cIndex].nChars < after + 1) {
|
|
|
|
clusters[cIndex].nChars = after + 1 - clusters[cIndex].baseChar;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
bool roundX = bool(aRounding & RoundingFlags::kRoundX);
|
|
|
|
bool roundY = bool(aRounding & RoundingFlags::kRoundY);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
// now put glyphs into the textrun, one cluster at a time
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i <= cIndex; ++i) {
|
2019-05-01 11:47:10 +03:00
|
|
|
const Cluster& c = clusters[i];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
float adv; // total advance of the cluster
|
|
|
|
if (rtl) {
|
|
|
|
if (i == 0) {
|
|
|
|
adv = gr_seg_advance_X(aSegment) - xLocs[c.baseGlyph];
|
|
|
|
} else {
|
|
|
|
adv = xLocs[clusters[i - 1].baseGlyph] - xLocs[c.baseGlyph];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i == cIndex) {
|
|
|
|
adv = gr_seg_advance_X(aSegment) - xLocs[c.baseGlyph];
|
|
|
|
} else {
|
|
|
|
adv = xLocs[clusters[i + 1].baseGlyph] - xLocs[c.baseGlyph];
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
// Check for default-ignorable char that didn't get filtered, combined,
|
|
|
|
// etc by the shaping process, and skip it.
|
2013-02-14 03:40:24 +04:00
|
|
|
uint32_t offs = c.baseChar;
|
|
|
|
NS_ASSERTION(offs < aLength, "unexpected offset");
|
2011-12-10 02:32:29 +04:00
|
|
|
if (c.nGlyphs == 1 && c.nChars == 1 &&
|
2013-01-04 22:35:37 +04:00
|
|
|
aShapedText->FilterIfIgnorable(aOffset + offs, aText[offs])) {
|
2011-12-10 02:32:29 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
uint32_t appAdvance = roundX ? NSToIntRound(adv) * dev2appUnits
|
|
|
|
: NSToIntRound(adv * dev2appUnits);
|
2017-11-11 18:32:58 +03:00
|
|
|
if (c.nGlyphs == 1 && CompressedGlyph::IsSimpleGlyphID(gids[c.baseGlyph]) &&
|
|
|
|
CompressedGlyph::IsSimpleAdvance(appAdvance) &&
|
2013-01-23 20:41:32 +04:00
|
|
|
charGlyphs[offs].IsClusterStart() && yLocs[c.baseGlyph] == 0) {
|
2013-01-04 22:35:37 +04:00
|
|
|
charGlyphs[offs].SetSimpleGlyph(appAdvance, gids[c.baseGlyph]);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2011-12-10 02:32:29 +04:00
|
|
|
// not a one-to-one mapping with simple metrics: use DetailedGlyph
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<gfxShapedText::DetailedGlyph, 8> details;
|
2011-12-10 02:32:29 +04:00
|
|
|
float clusterLoc;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = c.baseGlyph; j < c.baseGlyph + c.nGlyphs; ++j) {
|
2019-05-01 11:47:10 +03:00
|
|
|
gfxShapedText::DetailedGlyph* d = details.AppendElement();
|
2011-12-10 02:32:29 +04:00
|
|
|
d->mGlyphID = gids[j];
|
2017-10-30 17:55:42 +03:00
|
|
|
d->mOffset.y = roundY ? NSToIntRound(-yLocs[j]) * dev2appUnits
|
|
|
|
: -yLocs[j] * dev2appUnits;
|
2011-12-10 02:32:29 +04:00
|
|
|
if (j == c.baseGlyph) {
|
|
|
|
d->mAdvance = appAdvance;
|
|
|
|
clusterLoc = xLocs[j];
|
|
|
|
} else {
|
2013-01-21 13:24:08 +04:00
|
|
|
float dx =
|
|
|
|
rtl ? (xLocs[j] - clusterLoc) : (xLocs[j] - clusterLoc - adv);
|
2017-10-30 17:55:42 +03:00
|
|
|
d->mOffset.x =
|
|
|
|
roundX ? NSToIntRound(dx) * dev2appUnits : dx * dev2appUnits;
|
2011-12-10 02:32:29 +04:00
|
|
|
d->mAdvance = 0;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-11 18:32:58 +03:00
|
|
|
bool isClusterStart = charGlyphs[offs].IsClusterStart();
|
|
|
|
aShapedText->SetGlyphs(
|
|
|
|
aOffset + offs,
|
|
|
|
CompressedGlyph::MakeComplex(isClusterStart, true, details.Length()),
|
|
|
|
details.Elements());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = c.baseChar + 1; j < c.baseChar + c.nChars; ++j) {
|
2013-02-14 03:40:24 +04:00
|
|
|
NS_ASSERTION(j < aLength, "unexpected offset");
|
2019-05-01 11:47:10 +03:00
|
|
|
CompressedGlyph& g = charGlyphs[j];
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
|
|
|
|
g.SetComplex(g.IsClusterStart(), false, 0);
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-27 17:03:04 +04:00
|
|
|
#undef SMALL_GLYPH_RUN
|
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
// for language tag validation - include list of tags from the IANA registry
|
|
|
|
#include "gfxLanguageTagList.cpp"
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsTHashtable<nsUint32HashKey>* gfxGraphiteShaper::sLanguageTags;
|
2011-12-10 02:32:29 +04:00
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
2019-05-01 11:47:10 +03:00
|
|
|
uint32_t gfxGraphiteShaper::GetGraphiteTagForLang(const nsCString& aLang) {
|
2011-12-10 02:32:29 +04:00
|
|
|
int len = aLang.Length();
|
|
|
|
if (len < 2) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
// convert primary language subtag to a left-packed, NUL-padded integer
|
|
|
|
// for the Graphite API
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t grLang = 0;
|
2011-12-10 02:32:29 +04:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
grLang <<= 8;
|
|
|
|
if (i < len) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t ch = aLang[i];
|
2011-12-10 02:32:29 +04:00
|
|
|
if (ch == '-') {
|
|
|
|
// found end of primary language subtag, truncate here
|
|
|
|
len = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch < 'a' || ch > 'z') {
|
|
|
|
// invalid character in tag, so ignore it completely
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
grLang += ch;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
// valid tags must have length = 2 or 3
|
|
|
|
if (len < 2 || len > 3) {
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
if (!sLanguageTags) {
|
2011-12-10 02:32:29 +04:00
|
|
|
// store the registered IANA tags in a hash for convenient validation
|
2013-09-02 12:41:57 +04:00
|
|
|
sLanguageTags =
|
|
|
|
new nsTHashtable<nsUint32HashKey>(ArrayLength(sLanguageTagList));
|
2019-05-01 11:47:10 +03:00
|
|
|
for (const uint32_t* tag = sLanguageTagList; *tag != 0; ++tag) {
|
2013-09-02 12:41:57 +04:00
|
|
|
sLanguageTags->PutEntry(*tag);
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-10 02:32:29 +04:00
|
|
|
|
|
|
|
// only accept tags known in the IANA registry
|
2013-09-02 12:41:57 +04:00
|
|
|
if (sLanguageTags->GetEntry(grLang)) {
|
2011-12-10 02:32:29 +04:00
|
|
|
return grLang;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
|
|
|
void gfxGraphiteShaper::Shutdown() {
|
2011-12-10 02:32:29 +04:00
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
2013-09-02 12:41:57 +04:00
|
|
|
if (sLanguageTags) {
|
|
|
|
sLanguageTags->Clear();
|
|
|
|
delete sLanguageTags;
|
|
|
|
sLanguageTags = nullptr;
|
2011-12-10 02:32:29 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|