2011-12-09 14:32:29 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2011-12-09 14:32:29 -08:00
|
|
|
|
2013-10-07 16:15:59 -07:00
|
|
|
#include "gfxGraphiteShaper.h"
|
2011-12-09 14:32:29 -08:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxContext.h"
|
2014-06-22 20:09:16 -07:00
|
|
|
#include "gfxFontConstants.h"
|
2014-09-16 02:58:12 -07:00
|
|
|
#include "gfxTextRun.h"
|
2011-12-09 14:32:29 -08:00
|
|
|
|
|
|
|
#include "graphite2/Font.h"
|
|
|
|
#include "graphite2/Segment.h"
|
|
|
|
|
2012-04-21 14:24:39 -07:00
|
|
|
#include "harfbuzz/hb.h"
|
2011-12-09 14:32:29 -08: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
gfxGraphiteShaper::gfxGraphiteShaper(gfxFont *aFont)
|
|
|
|
: gfxFontShaper(aFont),
|
2013-05-16 09:29:20 -07:00
|
|
|
mGrFace(mFont->GetFontEntry()->GetGrFace()),
|
2014-06-22 20:09:16 -07:00
|
|
|
mGrFont(nullptr), mFallbackToSmallCaps(false)
|
2011-12-09 14:32:29 -08:00
|
|
|
{
|
|
|
|
mCallbackData.mFont = aFont;
|
|
|
|
mCallbackData.mShaper = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxGraphiteShaper::~gfxGraphiteShaper()
|
|
|
|
{
|
|
|
|
if (mGrFont) {
|
|
|
|
gr_font_destroy(mGrFont);
|
|
|
|
}
|
2013-05-16 09:29:20 -07:00
|
|
|
mFont->GetFontEntry()->ReleaseGrFace(mGrFace);
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
|
2013-05-16 09:29:20 -07:00
|
|
|
/*static*/ float
|
|
|
|
gfxGraphiteShaper::GrGetAdvance(const void* appFontHandle, uint16_t glyphid)
|
2011-12-09 14:32:29 -08:00
|
|
|
{
|
2013-05-16 09:29:20 -07:00
|
|
|
const CallbackData *cb =
|
|
|
|
static_cast<const CallbackData*>(appFontHandle);
|
2014-11-10 13:41:41 -08:00
|
|
|
return FixedToFloat(cb->mFont->GetGlyphWidth(*cb->mContext->GetDrawTarget(),
|
|
|
|
glyphid));
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static inline uint32_t
|
|
|
|
MakeGraphiteLangTag(uint32_t aTag)
|
2011-12-09 14:32:29 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t grLangTag = aTag;
|
2011-12-09 14:32:29 -08:00
|
|
|
// replace trailing space-padding with NULs for graphite
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mask = 0x000000FF;
|
2011-12-09 14:32:29 -08:00
|
|
|
while ((grLangTag & mask) == ' ') {
|
|
|
|
grLangTag &= ~mask;
|
|
|
|
mask <<= 8;
|
|
|
|
}
|
|
|
|
return grLangTag;
|
|
|
|
}
|
|
|
|
|
2012-04-25 23:26:03 -07:00
|
|
|
struct GrFontFeatures {
|
|
|
|
gr_face *mFace;
|
|
|
|
gr_feature_val *mFeatures;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2012-08-22 08:56:38 -07:00
|
|
|
AddFeature(const uint32_t& aTag, uint32_t& aValue, void *aUserArg)
|
2012-04-25 23:26:03 -07:00
|
|
|
{
|
|
|
|
GrFontFeatures *f = static_cast<GrFontFeatures*>(aUserArg);
|
|
|
|
|
|
|
|
const gr_feature_ref* fref = gr_face_find_fref(f->mFace, aTag);
|
|
|
|
if (fref) {
|
|
|
|
gr_fref_set_feature_value(fref, aValue, f->mFeatures);
|
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
bool
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxGraphiteShaper::ShapeText(gfxContext *aContext,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aText,
|
2013-01-04 10:35:37 -08:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 12:25:48 -07:00
|
|
|
bool aVertical,
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText *aShapedText)
|
2011-12-09 14:32:29 -08:00
|
|
|
{
|
|
|
|
// some font back-ends require this in order to get proper hinted metrics
|
2012-04-17 01:50:26 -07:00
|
|
|
if (!mFont->SetupCairoFont(aContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-09 14:32:29 -08:00
|
|
|
|
|
|
|
mCallbackData.mContext = aContext;
|
|
|
|
|
2014-06-22 20:09:16 -07:00
|
|
|
const gfxFontStyle *style = mFont->GetStyle();
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
if (!mGrFont) {
|
|
|
|
if (!mGrFace) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 01:24:24 -08:00
|
|
|
|
|
|
|
if (mFont->ProvidesGlyphWidths()) {
|
|
|
|
gr_font_ops ops = {
|
|
|
|
sizeof(gr_font_ops),
|
|
|
|
&GrGetAdvance,
|
|
|
|
nullptr // vertical text not yet implemented
|
|
|
|
};
|
|
|
|
mGrFont = gr_make_font_with_ops(mFont->GetAdjustedSize(),
|
|
|
|
&mCallbackData, &ops, mGrFace);
|
|
|
|
} else {
|
|
|
|
mGrFont = gr_make_font(mFont->GetAdjustedSize(), mGrFace);
|
|
|
|
}
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
if (!mGrFont) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-22 20:09:16 -07:00
|
|
|
|
|
|
|
// determine whether petite-caps falls back to small-caps
|
|
|
|
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,
|
|
|
|
mFallbackToSmallCaps, synLower,
|
|
|
|
synUpper);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
|
2011-12-06 04:39:19 -08:00
|
|
|
gfxFontEntry *entry = mFont->GetFontEntry();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t grLang = 0;
|
2011-12-09 14:32:29 -08:00
|
|
|
if (style->languageOverride) {
|
|
|
|
grLang = MakeGraphiteLangTag(style->languageOverride);
|
2011-12-06 04:39:19 -08:00
|
|
|
} else if (entry->mLanguageOverride) {
|
|
|
|
grLang = MakeGraphiteLangTag(entry->mLanguageOverride);
|
2014-12-23 04:50:10 -08:00
|
|
|
} else if (style->explicitLanguage) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString langString;
|
2011-12-09 14:32:29 -08:00
|
|
|
style->language->ToUTF8String(langString);
|
|
|
|
grLang = GetGraphiteTagForLang(langString);
|
|
|
|
}
|
|
|
|
gr_feature_val *grFeatures = gr_face_featureval_for_lang(mGrFace, grLang);
|
|
|
|
|
2014-06-22 20:09:16 -07:00
|
|
|
// if style contains font-specific features
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDataHashtable<nsUint32HashKey,uint32_t> mergedFeatures;
|
2011-12-09 14:32:29 -08:00
|
|
|
|
2013-05-19 19:59:20 -07:00
|
|
|
if (MergeFontFeatures(style,
|
|
|
|
mFont->GetFontEntry()->mFeatureSettings,
|
|
|
|
aShapedText->DisableLigatures(),
|
|
|
|
mFont->GetFontEntry()->FamilyName(),
|
2014-06-22 20:09:16 -07:00
|
|
|
mFallbackToSmallCaps,
|
2013-05-19 19:59:20 -07:00
|
|
|
mergedFeatures))
|
|
|
|
{
|
2012-04-25 23:26:03 -07:00
|
|
|
// enumerate result and insert into Graphite feature list
|
|
|
|
GrFontFeatures f = {mGrFace, grFeatures};
|
|
|
|
mergedFeatures.Enumerate(AddFeature, &f);
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:40:24 -08:00
|
|
|
size_t numChars = gr_count_unicode_characters(gr_utf16,
|
|
|
|
aText, aText + aLength,
|
|
|
|
nullptr);
|
2011-12-09 14:32:29 -08:00
|
|
|
gr_segment *seg = gr_make_seg(mGrFont, mGrFace, 0, grFeatures,
|
2013-02-13 15:40:24 -08:00
|
|
|
gr_utf16, aText, numChars,
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->IsRightToLeft());
|
2012-04-25 23:26:03 -07:00
|
|
|
|
|
|
|
gr_featureval_destroy(grFeatures);
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
if (!seg) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 01:24:08 -08:00
|
|
|
nsresult rv = SetGlyphsFromSegment(aContext, aShapedText, aOffset, aLength,
|
2013-01-04 10:35:37 -08:00
|
|
|
aText, seg);
|
2011-12-09 14:32:29 -08: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-13 15:40:24 -08:00
|
|
|
uint32_t baseChar; // in UTF16 code units, not Unicode character indices
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t baseGlyph;
|
2013-02-13 15:40:24 -08:00
|
|
|
uint32_t nChars; // UTF16 code units
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nGlyphs;
|
2011-12-09 14:32:29 -08:00
|
|
|
Cluster() : baseChar(0), baseGlyph(0), nChars(0), nGlyphs(0) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2013-01-21 01:24:08 -08:00
|
|
|
gfxGraphiteShaper::SetGlyphsFromSegment(gfxContext *aContext,
|
|
|
|
gfxShapedText *aShapedText,
|
2013-01-04 10:35:37 -08:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aText,
|
2013-01-04 10:35:37 -08:00
|
|
|
gr_segment *aSegment)
|
2011-12-09 14:32:29 -08:00
|
|
|
{
|
2013-01-04 10:35:37 -08:00
|
|
|
int32_t dev2appUnits = aShapedText->GetAppUnitsPerDevUnit();
|
|
|
|
bool rtl = aShapedText->IsRightToLeft();
|
2011-12-09 14:32:29 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t glyphCount = gr_seg_n_slots(aSegment);
|
2011-12-09 14:32:29 -08:00
|
|
|
|
|
|
|
// identify clusters; graphite may have reordered/expanded/ligated glyphs.
|
2014-02-08 10:10:07 -08:00
|
|
|
AutoFallibleTArray<Cluster,SMALL_GLYPH_RUN> clusters;
|
|
|
|
AutoFallibleTArray<uint16_t,SMALL_GLYPH_RUN> gids;
|
|
|
|
AutoFallibleTArray<float,SMALL_GLYPH_RUN> xLocs;
|
|
|
|
AutoFallibleTArray<float,SMALL_GLYPH_RUN> yLocs;
|
2011-12-09 14:32:29 -08:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
if (!clusters.SetLength(aLength) ||
|
2011-12-09 14:32:29 -08:00
|
|
|
!gids.SetLength(glyphCount) ||
|
|
|
|
!xLocs.SetLength(glyphCount) ||
|
|
|
|
!yLocs.SetLength(glyphCount))
|
|
|
|
{
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk through the glyph slots and check which original character
|
|
|
|
// each is associated with
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t gIndex = 0; // glyph slot index
|
|
|
|
uint32_t cIndex = 0; // current cluster index
|
2011-12-09 14:32:29 -08:00
|
|
|
for (const gr_slot *slot = gr_seg_first_slot(aSegment);
|
2012-07-30 07:20:58 -07:00
|
|
|
slot != nullptr;
|
2011-12-09 14:32:29 -08:00
|
|
|
slot = gr_slot_next_in_segment(slot), gIndex++)
|
|
|
|
{
|
2013-02-13 15:40:24 -08:00
|
|
|
uint32_t before =
|
|
|
|
gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_before(slot)));
|
|
|
|
uint32_t after =
|
|
|
|
gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_after(slot)));
|
2011-12-09 14:32:29 -08:00
|
|
|
gids[gIndex] = gr_slot_gid(slot);
|
|
|
|
xLocs[gIndex] = gr_slot_origin_X(slot);
|
|
|
|
yLocs[gIndex] = gr_slot_origin_Y(slot);
|
|
|
|
|
|
|
|
// if this glyph has a "before" character index that precedes the
|
|
|
|
// 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 10:35:37 -08:00
|
|
|
NS_ASSERTION(cIndex < aLength - 1, "cIndex at end of word");
|
2011-12-09 14:32:29 -08:00
|
|
|
Cluster& c = clusters[cIndex + 1];
|
|
|
|
c.baseChar = clusters[cIndex].baseChar + clusters[cIndex].nChars;
|
|
|
|
c.nChars = before - c.baseChar;
|
|
|
|
c.baseGlyph = gIndex;
|
|
|
|
c.nGlyphs = 0;
|
|
|
|
++cIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// increment cluster's glyph count to include current slot
|
2013-01-04 10:35:37 -08:00
|
|
|
NS_ASSERTION(cIndex < aLength, "cIndex beyond word length");
|
2011-12-09 14:32:29 -08:00
|
|
|
++clusters[cIndex].nGlyphs;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 01:24:08 -08:00
|
|
|
bool roundX;
|
|
|
|
bool roundY;
|
|
|
|
aContext->GetRoundOffsetsToPixels(&roundX, &roundY);
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph *charGlyphs =
|
|
|
|
aShapedText->GetCharacterGlyphs() + aOffset;
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
// now put glyphs into the textrun, one cluster at a time
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i <= cIndex; ++i) {
|
2011-12-09 14:32:29 -08:00
|
|
|
const Cluster& c = clusters[i];
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for default-ignorable char that didn't get filtered, combined,
|
|
|
|
// etc by the shaping process, and skip it.
|
2013-02-13 15:40:24 -08:00
|
|
|
uint32_t offs = c.baseChar;
|
|
|
|
NS_ASSERTION(offs < aLength, "unexpected offset");
|
2011-12-09 14:32:29 -08:00
|
|
|
if (c.nGlyphs == 1 && c.nChars == 1 &&
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->FilterIfIgnorable(aOffset + offs, aText[offs])) {
|
2011-12-09 14:32:29 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-21 01:24:08 -08:00
|
|
|
uint32_t appAdvance = roundX ? NSToIntRound(adv) * dev2appUnits :
|
|
|
|
NSToIntRound(adv * dev2appUnits);
|
2011-12-09 14:32:29 -08:00
|
|
|
if (c.nGlyphs == 1 &&
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph::IsSimpleGlyphID(gids[c.baseGlyph]) &&
|
|
|
|
gfxShapedText::CompressedGlyph::IsSimpleAdvance(appAdvance) &&
|
2013-01-23 08:41:32 -08:00
|
|
|
charGlyphs[offs].IsClusterStart() &&
|
2011-12-09 14:32:29 -08:00
|
|
|
yLocs[c.baseGlyph] == 0)
|
|
|
|
{
|
2013-01-04 10:35:37 -08:00
|
|
|
charGlyphs[offs].SetSimpleGlyph(appAdvance, gids[c.baseGlyph]);
|
2011-12-09 14:32:29 -08:00
|
|
|
} else {
|
|
|
|
// not a one-to-one mapping with simple metrics: use DetailedGlyph
|
2013-01-04 10:35:37 -08:00
|
|
|
nsAutoTArray<gfxShapedText::DetailedGlyph,8> details;
|
2011-12-09 14:32:29 -08:00
|
|
|
float clusterLoc;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t j = c.baseGlyph; j < c.baseGlyph + c.nGlyphs; ++j) {
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::DetailedGlyph* d = details.AppendElement();
|
2011-12-09 14:32:29 -08:00
|
|
|
d->mGlyphID = gids[j];
|
2013-01-21 01:24:08 -08:00
|
|
|
d->mYOffset = roundY ? NSToIntRound(-yLocs[j]) * dev2appUnits :
|
|
|
|
-yLocs[j] * dev2appUnits;
|
2011-12-09 14:32:29 -08:00
|
|
|
if (j == c.baseGlyph) {
|
|
|
|
d->mXOffset = 0;
|
|
|
|
d->mAdvance = appAdvance;
|
|
|
|
clusterLoc = xLocs[j];
|
|
|
|
} else {
|
2013-01-21 01:24:08 -08:00
|
|
|
float dx = rtl ? (xLocs[j] - clusterLoc) :
|
|
|
|
(xLocs[j] - clusterLoc - adv);
|
|
|
|
d->mXOffset = roundX ? NSToIntRound(dx) * dev2appUnits :
|
|
|
|
dx * dev2appUnits;
|
2011-12-09 14:32:29 -08:00
|
|
|
d->mAdvance = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph g;
|
|
|
|
g.SetComplex(charGlyphs[offs].IsClusterStart(),
|
2011-12-09 14:32:29 -08:00
|
|
|
true, details.Length());
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->SetGlyphs(aOffset + offs, g, details.Elements());
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t j = c.baseChar + 1; j < c.baseChar + c.nChars; ++j) {
|
2013-02-13 15:40:24 -08:00
|
|
|
NS_ASSERTION(j < aLength, "unexpected offset");
|
|
|
|
gfxShapedText::CompressedGlyph &g = charGlyphs[j];
|
2013-01-04 10:35:37 -08:00
|
|
|
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
|
|
|
|
g.SetComplex(g.IsClusterStart(), false, 0);
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-27 05:03:04 -08:00
|
|
|
#undef SMALL_GLYPH_RUN
|
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
// for language tag validation - include list of tags from the IANA registry
|
|
|
|
#include "gfxLanguageTagList.cpp"
|
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
nsTHashtable<nsUint32HashKey> *gfxGraphiteShaper::sLanguageTags;
|
2011-12-09 14:32:29 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/*static*/ uint32_t
|
2011-12-09 14:32:29 -08:00
|
|
|
gfxGraphiteShaper::GetGraphiteTagForLang(const nsCString& aLang)
|
|
|
|
{
|
|
|
|
int len = aLang.Length();
|
|
|
|
if (len < 2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert primary language subtag to a left-packed, NUL-padded integer
|
|
|
|
// for the Graphite API
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t grLang = 0;
|
2011-12-09 14:32:29 -08:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
grLang <<= 8;
|
|
|
|
if (i < len) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t ch = aLang[i];
|
2011-12-09 14:32:29 -08: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;
|
|
|
|
}
|
|
|
|
grLang += ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// valid tags must have length = 2 or 3
|
|
|
|
if (len < 2 || len > 3) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-02 01:41:57 -07:00
|
|
|
if (!sLanguageTags) {
|
2011-12-09 14:32:29 -08:00
|
|
|
// store the registered IANA tags in a hash for convenient validation
|
2013-09-02 01:41:57 -07:00
|
|
|
sLanguageTags = new nsTHashtable<nsUint32HashKey>(ArrayLength(sLanguageTagList));
|
2012-08-22 08:56:38 -07:00
|
|
|
for (const uint32_t *tag = sLanguageTagList; *tag != 0; ++tag) {
|
2013-09-02 01:41:57 -07:00
|
|
|
sLanguageTags->PutEntry(*tag);
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only accept tags known in the IANA registry
|
2013-09-02 01:41:57 -07:00
|
|
|
if (sLanguageTags->GetEntry(grLang)) {
|
2011-12-09 14:32:29 -08:00
|
|
|
return grLang;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
gfxGraphiteShaper::Shutdown()
|
|
|
|
{
|
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
2013-09-02 01:41:57 -07:00
|
|
|
if (sLanguageTags) {
|
|
|
|
sLanguageTags->Clear();
|
|
|
|
delete sLanguageTags;
|
|
|
|
sLanguageTags = nullptr;
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|