2015-11-28 03:56:33 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 et sw=4 tw=80: */
|
2014-09-16 13:58:12 +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/. */
|
|
|
|
|
|
|
|
#include "gfxTextRun.h"
|
|
|
|
#include "gfxGlyphExtents.h"
|
|
|
|
#include "gfxPlatformFontList.h"
|
|
|
|
#include "gfxUserFontSet.h"
|
2014-10-28 17:40:51 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2016-12-16 06:16:31 +03:00
|
|
|
#include "mozilla/SizePrintfMacros.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxFontConstants.h"
|
|
|
|
#include "gfxFontMissingGlyphs.h"
|
|
|
|
#include "gfxScriptItemizer.h"
|
|
|
|
#include "nsUnicodeProperties.h"
|
|
|
|
#include "nsUnicodeRange.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
#include "gfx2DGlue.h"
|
2015-08-05 05:03:41 +03:00
|
|
|
#include "mozilla/gfx/Logging.h" // for gfxCriticalError
|
2015-10-20 20:13:35 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2015-08-13 09:04:25 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "cairo.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-10-28 17:40:51 +03:00
|
|
|
using namespace mozilla::gfx;
|
2014-09-16 13:58:12 +04:00
|
|
|
using namespace mozilla::unicode;
|
2014-12-22 19:35:54 +03:00
|
|
|
using mozilla::services::GetObserverService;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
static const char16_t kEllipsisChar[] = { 0x2026, 0x0 };
|
|
|
|
static const char16_t kASCIIPeriodsChar[] = { '.', '.', '.', 0x0 };
|
|
|
|
|
|
|
|
#ifdef DEBUG_roc
|
|
|
|
#define DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
extern uint32_t gTextRunStorageHighWaterMark;
|
|
|
|
extern uint32_t gTextRunStorage;
|
|
|
|
extern uint32_t gFontCount;
|
|
|
|
extern uint32_t gGlyphExtentsCount;
|
|
|
|
extern uint32_t gGlyphExtentsWidthsTotalSize;
|
|
|
|
extern uint32_t gGlyphExtentsSetupEagerSimple;
|
|
|
|
extern uint32_t gGlyphExtentsSetupEagerTight;
|
|
|
|
extern uint32_t gGlyphExtentsSetupLazyTight;
|
|
|
|
extern uint32_t gGlyphExtentsSetupFallBackToTight;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
2017-05-02 13:14:53 +03:00
|
|
|
gfxTextRun::GlyphRunIterator::NextRun()
|
|
|
|
{
|
|
|
|
uint32_t glyphRunCount;
|
|
|
|
if (mTextRun->mHasGlyphRunArray) {
|
|
|
|
glyphRunCount = mTextRun->mGlyphRunArray.Length();
|
|
|
|
if (mNextIndex >= glyphRunCount) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mGlyphRun = &mTextRun->mGlyphRunArray[mNextIndex];
|
|
|
|
} else {
|
|
|
|
if (mNextIndex > 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
glyphRunCount = 1;
|
|
|
|
mGlyphRun = &mTextRun->mSingleGlyphRun;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mGlyphRun->mCharacterOffset >= mEndOffset) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return false;
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
mStringStart = std::max(mStartOffset, mGlyphRun->mCharacterOffset);
|
2017-05-02 13:14:53 +03:00
|
|
|
uint32_t last = mNextIndex + 1 < glyphRunCount
|
|
|
|
? mTextRun->mGlyphRunArray[mNextIndex + 1].mCharacterOffset
|
|
|
|
: mTextRun->GetLength();
|
2014-09-16 13:58:12 +04:00
|
|
|
mStringEnd = std::min(mEndOffset, last);
|
|
|
|
|
|
|
|
++mNextIndex;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
static void
|
|
|
|
AccountStorageForTextRun(gfxTextRun *aTextRun, int32_t aSign)
|
|
|
|
{
|
|
|
|
// Ignores detailed glyphs... we don't know when those have been constructed
|
|
|
|
// Also ignores gfxSkipChars dynamic storage (which won't be anything
|
|
|
|
// for preformatted text)
|
|
|
|
// Also ignores GlyphRun array, again because it hasn't been constructed
|
|
|
|
// by the time this gets called. If there's only one glyphrun that's stored
|
|
|
|
// directly in the textrun anyway so no additional overhead.
|
|
|
|
uint32_t length = aTextRun->GetLength();
|
|
|
|
int32_t bytes = length * sizeof(gfxTextRun::CompressedGlyph);
|
|
|
|
bytes += sizeof(gfxTextRun);
|
|
|
|
gTextRunStorage += bytes*aSign;
|
|
|
|
gTextRunStorageHighWaterMark = std::max(gTextRunStorageHighWaterMark, gTextRunStorage);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool
|
|
|
|
NeedsGlyphExtents(gfxTextRun *aTextRun)
|
|
|
|
{
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aTextRun->GetFlags() & gfx::ShapedTextFlags::TEXT_NEED_BOUNDING_BOX)
|
2014-09-16 13:58:12 +04:00
|
|
|
return true;
|
|
|
|
uint32_t numRuns;
|
|
|
|
const gfxTextRun::GlyphRun *glyphRuns = aTextRun->GetGlyphRuns(&numRuns);
|
|
|
|
for (uint32_t i = 0; i < numRuns; ++i) {
|
|
|
|
if (glyphRuns[i].mFont->GetFontEntry()->IsUserFont())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper for textRun creation to preallocate storage for glyph records;
|
|
|
|
// this function returns a pointer to the newly-allocated glyph storage.
|
|
|
|
// Returns nullptr if allocation fails.
|
|
|
|
void *
|
|
|
|
gfxTextRun::AllocateStorageForTextRun(size_t aSize, uint32_t aLength)
|
|
|
|
{
|
|
|
|
// Allocate the storage we need, returning nullptr on failure rather than
|
|
|
|
// throwing an exception (because web content can create huge runs).
|
2015-02-19 07:51:06 +03:00
|
|
|
void *storage = malloc(aSize + aLength * sizeof(CompressedGlyph));
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!storage) {
|
|
|
|
NS_WARNING("failed to allocate storage for text run!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the glyph storage (beyond aSize) to zero
|
|
|
|
memset(reinterpret_cast<char*>(storage) + aSize, 0,
|
|
|
|
aLength * sizeof(CompressedGlyph));
|
|
|
|
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRun::Create(const gfxTextRunFactory::Parameters *aParams,
|
2017-05-05 00:25:16 +03:00
|
|
|
uint32_t aLength, gfxFontGroup *aFontGroup,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
void *storage = AllocateStorageForTextRun(sizeof(gfxTextRun), aLength);
|
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> result = new (storage) gfxTextRun(aParams, aLength,
|
2017-05-05 00:25:16 +03:00
|
|
|
aFontGroup,
|
|
|
|
aFlags, aFlags2);
|
2016-08-19 15:14:22 +03:00
|
|
|
return result.forget();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::gfxTextRun(const gfxTextRunFactory::Parameters *aParams,
|
2017-05-05 00:25:16 +03:00
|
|
|
uint32_t aLength, gfxFontGroup *aFontGroup,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
: gfxShapedText(aLength, aFlags, aParams->mAppUnitsPerDevUnit)
|
2017-05-02 13:14:53 +03:00
|
|
|
, mSingleGlyphRun()
|
2014-09-16 13:58:12 +04:00
|
|
|
, mUserData(aParams->mUserData)
|
|
|
|
, mFontGroup(aFontGroup)
|
2017-05-05 00:25:16 +03:00
|
|
|
, mFlags2(aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
, mReleasedFontGroup(false)
|
2017-05-02 13:14:53 +03:00
|
|
|
, mHasGlyphRunArray(false)
|
2014-09-16 13:58:12 +04:00
|
|
|
, mShapingState(eShapingState_Normal)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mAppUnitsPerDevUnit > 0, "Invalid app unit scale");
|
|
|
|
NS_ADDREF(mFontGroup);
|
|
|
|
|
2016-10-08 12:14:49 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextPerfMetrics *tp = aFontGroup->GetTextPerfMetrics();
|
|
|
|
if (tp) {
|
|
|
|
tp->current.textrunConst++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mCharacterGlyphs = reinterpret_cast<CompressedGlyph*>(this + 1);
|
|
|
|
|
|
|
|
if (aParams->mSkipChars) {
|
|
|
|
mSkipChars.TakeFrom(aParams->mSkipChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
AccountStorageForTextRun(this, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mSkipDrawing = mFontGroup->ShouldSkipDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::~gfxTextRun()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
AccountStorageForTextRun(this, -1);
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Make it easy to detect a dead text run
|
2017-05-05 00:27:05 +03:00
|
|
|
mFlags = ~gfx::ShapedTextFlags();
|
|
|
|
mFlags2 = ~nsTextFrameUtils::Flags();
|
2014-09-16 13:58:12 +04:00
|
|
|
#endif
|
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
if (mHasGlyphRunArray) {
|
|
|
|
mGlyphRunArray.~nsTArray<GlyphRun>();
|
|
|
|
} else {
|
|
|
|
mSingleGlyphRun.mFont = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// The cached ellipsis textrun (if any) in a fontgroup will have already
|
|
|
|
// been told to release its reference to the group, so we mustn't do that
|
|
|
|
// again here.
|
|
|
|
if (!mReleasedFontGroup) {
|
2016-10-08 12:14:49 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextPerfMetrics *tp = mFontGroup->GetTextPerfMetrics();
|
|
|
|
if (tp) {
|
|
|
|
tp->current.textrunDestr++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
NS_RELEASE(mFontGroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxTextRun::ReleaseFontGroup()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mReleasedFontGroup, "doubly released!");
|
|
|
|
NS_RELEASE(mFontGroup);
|
|
|
|
mReleasedFontGroup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-10-11 15:47:11 +03:00
|
|
|
gfxTextRun::SetPotentialLineBreaks(Range aRange, const uint8_t* aBreakBefore)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aRange.end <= GetLength(), "Overflow");
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
uint32_t changed = 0;
|
2016-10-11 15:47:11 +03:00
|
|
|
CompressedGlyph* cg = mCharacterGlyphs + aRange.start;
|
|
|
|
const CompressedGlyph* const end = cg + aRange.Length();
|
|
|
|
while (cg < end) {
|
|
|
|
uint8_t canBreak = *aBreakBefore++;
|
|
|
|
if (canBreak && !cg->IsClusterStart()) {
|
|
|
|
// XXX If we replace the line-breaker with one based more closely
|
|
|
|
// on UAX#14 (e.g. using ICU), this may not be needed any more.
|
|
|
|
// Avoid possible breaks inside a cluster, EXCEPT when the previous
|
|
|
|
// character was a space (compare UAX#14 rules LB9, LB10).
|
|
|
|
if (cg == mCharacterGlyphs || !(cg - 1)->CharIsSpace()) {
|
|
|
|
canBreak = CompressedGlyph::FLAG_BREAK_TYPE_NONE;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2016-10-11 15:47:11 +03:00
|
|
|
changed |= cg->SetCanBreakBefore(canBreak);
|
|
|
|
++cg;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
return changed != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::LigatureData
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::ComputeLigatureData(Range aPartRange,
|
|
|
|
PropertyProvider *aProvider) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aPartRange.start < aPartRange.end,
|
|
|
|
"Computing ligature data for empty range");
|
|
|
|
NS_ASSERTION(aPartRange.end <= GetLength(), "Character length overflow");
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
LigatureData result;
|
2016-06-27 19:41:55 +03:00
|
|
|
const CompressedGlyph *charGlyphs = mCharacterGlyphs;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
uint32_t i;
|
2016-03-08 10:56:18 +03:00
|
|
|
for (i = aPartRange.start; !charGlyphs[i].IsLigatureGroupStart(); --i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
NS_ASSERTION(i > 0, "Ligature at the start of the run??");
|
|
|
|
}
|
2016-03-08 10:56:18 +03:00
|
|
|
result.mRange.start = i;
|
|
|
|
for (i = aPartRange.start + 1;
|
|
|
|
i < GetLength() && !charGlyphs[i].IsLigatureGroupStart(); ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2016-03-08 10:56:18 +03:00
|
|
|
result.mRange.end = i;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
int32_t ligatureWidth = GetAdvanceForGlyphs(result.mRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
// Count the number of started clusters we have seen
|
|
|
|
uint32_t totalClusterCount = 0;
|
|
|
|
uint32_t partClusterIndex = 0;
|
|
|
|
uint32_t partClusterCount = 0;
|
2016-03-08 10:56:18 +03:00
|
|
|
for (i = result.mRange.start; i < result.mRange.end; ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// Treat the first character of the ligature as the start of a
|
|
|
|
// cluster for our purposes of allocating ligature width to its
|
|
|
|
// characters.
|
2016-03-08 10:56:18 +03:00
|
|
|
if (i == result.mRange.start || charGlyphs[i].IsClusterStart()) {
|
2014-09-16 13:58:12 +04:00
|
|
|
++totalClusterCount;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (i < aPartRange.start) {
|
2014-09-16 13:58:12 +04:00
|
|
|
++partClusterIndex;
|
2016-03-08 10:56:18 +03:00
|
|
|
} else if (i < aPartRange.end) {
|
2014-09-16 13:58:12 +04:00
|
|
|
++partClusterCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(totalClusterCount > 0, "Ligature involving no clusters??");
|
|
|
|
result.mPartAdvance = partClusterIndex * (ligatureWidth / totalClusterCount);
|
|
|
|
result.mPartWidth = partClusterCount * (ligatureWidth / totalClusterCount);
|
|
|
|
|
|
|
|
// Any rounding errors are apportioned to the final part of the ligature,
|
|
|
|
// so that measuring all parts of a ligature and summing them is equal to
|
|
|
|
// the ligature width.
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aPartRange.end == result.mRange.end) {
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat allParts = totalClusterCount * (ligatureWidth / totalClusterCount);
|
|
|
|
result.mPartWidth += ligatureWidth - allParts;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (partClusterCount == 0) {
|
|
|
|
// nothing to draw
|
|
|
|
result.mClipBeforePart = result.mClipAfterPart = true;
|
|
|
|
} else {
|
|
|
|
// Determine whether we should clip before or after this part when
|
|
|
|
// drawing its slice of the ligature.
|
|
|
|
// We need to clip before the part if any cluster is drawn before
|
|
|
|
// this part.
|
|
|
|
result.mClipBeforePart = partClusterIndex > 0;
|
|
|
|
// We need to clip after the part if any cluster is drawn after
|
|
|
|
// this part.
|
|
|
|
result.mClipAfterPart = partClusterIndex + partClusterCount < totalClusterCount;
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aProvider && (mFlags & gfx::ShapedTextFlags::TEXT_ENABLE_SPACING)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont::Spacing spacing;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aPartRange.start == result.mRange.start) {
|
|
|
|
aProvider->GetSpacing(
|
|
|
|
Range(aPartRange.start, aPartRange.start + 1), &spacing);
|
2014-09-16 13:58:12 +04:00
|
|
|
result.mPartWidth += spacing.mBefore;
|
|
|
|
}
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aPartRange.end == result.mRange.end) {
|
|
|
|
aProvider->GetSpacing(
|
|
|
|
Range(aPartRange.end - 1, aPartRange.end), &spacing);
|
2014-09-16 13:58:12 +04:00
|
|
|
result.mPartWidth += spacing.mAfter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::ComputePartialLigatureWidth(Range aPartRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider *aProvider) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aPartRange.start >= aPartRange.end)
|
2014-09-16 13:58:12 +04:00
|
|
|
return 0;
|
2016-03-08 10:56:18 +03:00
|
|
|
LigatureData data = ComputeLigatureData(aPartRange, aProvider);
|
2014-09-16 13:58:12 +04:00
|
|
|
return data.mPartWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::GetAdvanceForGlyphs(Range aRange) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
int32_t advance = 0;
|
2016-03-08 10:56:18 +03:00
|
|
|
for (auto i = aRange.start; i < aRange.end; ++i) {
|
2015-11-28 03:56:33 +03:00
|
|
|
advance += GetAdvanceForGlyph(i);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
return advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-27 19:41:55 +03:00
|
|
|
GetAdjustedSpacing(const gfxTextRun *aTextRun, gfxTextRun::Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRun::PropertyProvider *aProvider,
|
|
|
|
gfxTextRun::PropertyProvider::Spacing *aSpacing)
|
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aRange.start >= aRange.end)
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
aProvider->GetSpacing(aRange, aSpacing);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Check to see if we have spacing inside ligatures
|
|
|
|
|
|
|
|
const gfxTextRun::CompressedGlyph *charGlyphs = aTextRun->GetCharacterGlyphs();
|
|
|
|
uint32_t i;
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
for (i = aRange.start; i < aRange.end; ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!charGlyphs[i].IsLigatureGroupStart()) {
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(i == aRange.start ||
|
|
|
|
aSpacing[i - aRange.start].mBefore == 0,
|
2014-09-16 13:58:12 +04:00
|
|
|
"Before-spacing inside a ligature!");
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(i - 1 <= aRange.start ||
|
|
|
|
aSpacing[i - 1 - aRange.start].mAfter == 0,
|
2014-09-16 13:58:12 +04:00
|
|
|
"After-spacing inside a ligature!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::GetAdjustedSpacingArray(Range aRange, PropertyProvider *aProvider,
|
|
|
|
Range aSpacingRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
nsTArray<PropertyProvider::Spacing>*
|
|
|
|
aSpacing) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-05-05 00:27:05 +03:00
|
|
|
if (!aProvider || !(mFlags & gfx::ShapedTextFlags::TEXT_ENABLE_SPACING))
|
2014-09-16 13:58:12 +04:00
|
|
|
return false;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (!aSpacing->AppendElements(aRange.Length()))
|
2014-09-16 13:58:12 +04:00
|
|
|
return false;
|
2016-03-08 10:56:18 +03:00
|
|
|
auto spacingOffset = aSpacingRange.start - aRange.start;
|
|
|
|
memset(aSpacing->Elements(), 0, sizeof(gfxFont::Spacing) * spacingOffset);
|
|
|
|
GetAdjustedSpacing(this, aSpacingRange, aProvider,
|
|
|
|
aSpacing->Elements() + spacingOffset);
|
|
|
|
memset(aSpacing->Elements() + aSpacingRange.end - aRange.start, 0,
|
|
|
|
sizeof(gfxFont::Spacing) * (aRange.end - aSpacingRange.end));
|
2014-09-16 13:58:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::ShrinkToLigatureBoundaries(Range* aRange) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aRange->start >= aRange->end)
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
const CompressedGlyph *charGlyphs = mCharacterGlyphs;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
while (aRange->start < aRange->end &&
|
|
|
|
!charGlyphs[aRange->start].IsLigatureGroupStart()) {
|
|
|
|
++aRange->start;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aRange->end < GetLength()) {
|
|
|
|
while (aRange->end > aRange->start &&
|
|
|
|
!charGlyphs[aRange->end].IsLigatureGroupStart()) {
|
|
|
|
--aRange->end;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::DrawGlyphs(gfxFont *aFont, Range aRange, gfxPoint *aPt,
|
|
|
|
PropertyProvider *aProvider, Range aSpacingRange,
|
2017-05-05 00:27:05 +03:00
|
|
|
TextRunDrawParams& aParams,
|
|
|
|
gfx::ShapedTextFlags aOrientation) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<PropertyProvider::Spacing,200> spacingBuffer;
|
2016-03-08 10:56:18 +03:00
|
|
|
bool haveSpacing = GetAdjustedSpacingArray(aRange, aProvider,
|
|
|
|
aSpacingRange, &spacingBuffer);
|
2014-09-16 13:58:12 +04:00
|
|
|
aParams.spacing = haveSpacing ? spacingBuffer.Elements() : nullptr;
|
2016-03-08 10:56:18 +03:00
|
|
|
aFont->Draw(this, aRange.start, aRange.end, aPt, aParams, aOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-01 23:25:49 +04:00
|
|
|
ClipPartialLigature(const gfxTextRun* aTextRun,
|
|
|
|
gfxFloat *aStart, gfxFloat *aEnd,
|
|
|
|
gfxFloat aOrigin,
|
|
|
|
gfxTextRun::LigatureData *aLigature)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
if (aLigature->mClipBeforePart) {
|
|
|
|
if (aTextRun->IsRightToLeft()) {
|
2014-10-01 23:25:49 +04:00
|
|
|
*aEnd = std::min(*aEnd, aOrigin);
|
2014-09-16 13:58:12 +04:00
|
|
|
} else {
|
2014-10-01 23:25:49 +04:00
|
|
|
*aStart = std::max(*aStart, aOrigin);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aLigature->mClipAfterPart) {
|
2014-10-01 23:25:49 +04:00
|
|
|
gfxFloat endEdge =
|
|
|
|
aOrigin + aTextRun->GetDirection() * aLigature->mPartWidth;
|
2014-09-16 13:58:12 +04:00
|
|
|
if (aTextRun->IsRightToLeft()) {
|
2014-10-01 23:25:49 +04:00
|
|
|
*aStart = std::max(*aStart, endEdge);
|
2014-09-16 13:58:12 +04:00
|
|
|
} else {
|
2014-10-01 23:25:49 +04:00
|
|
|
*aEnd = std::min(*aEnd, endEdge);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2017-01-04 18:55:16 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::DrawPartialLigature(gfxFont *aFont, Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxPoint *aPt, PropertyProvider *aProvider,
|
2016-06-27 19:41:55 +03:00
|
|
|
TextRunDrawParams& aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aOrientation) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aRange.start >= aRange.end) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
2014-10-01 23:25:49 +04:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// Draw partial ligature. We hack this by clipping the ligature.
|
2016-03-08 10:56:18 +03:00
|
|
|
LigatureData data = ComputeLigatureData(aRange, aProvider);
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxRect clipExtents = aParams.context->GetClipExtents();
|
2014-10-01 23:25:49 +04:00
|
|
|
gfxFloat start, end;
|
|
|
|
if (aParams.isVerticalRun) {
|
|
|
|
start = clipExtents.Y() * mAppUnitsPerDevUnit;
|
|
|
|
end = clipExtents.YMost() * mAppUnitsPerDevUnit;
|
|
|
|
ClipPartialLigature(this, &start, &end, aPt->y, &data);
|
|
|
|
} else {
|
|
|
|
start = clipExtents.X() * mAppUnitsPerDevUnit;
|
|
|
|
end = clipExtents.XMost() * mAppUnitsPerDevUnit;
|
|
|
|
ClipPartialLigature(this, &start, &end, aPt->x, &data);
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
// use division here to ensure that when the rect is aligned on multiples
|
|
|
|
// of mAppUnitsPerDevUnit, we clip to true device unit boundaries.
|
|
|
|
// Also, make sure we snap the rectangle to device pixels.
|
2014-10-28 17:40:51 +03:00
|
|
|
Rect clipRect = aParams.isVerticalRun ?
|
|
|
|
Rect(clipExtents.X(), start / mAppUnitsPerDevUnit,
|
|
|
|
clipExtents.Width(), (end - start) / mAppUnitsPerDevUnit) :
|
|
|
|
Rect(start / mAppUnitsPerDevUnit, clipExtents.Y(),
|
|
|
|
(end - start) / mAppUnitsPerDevUnit, clipExtents.Height());
|
|
|
|
MaybeSnapToDevicePixels(clipRect, *aParams.dt, true);
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
aParams.context->Save();
|
2014-10-28 17:40:51 +03:00
|
|
|
aParams.context->Clip(clipRect);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2014-10-01 23:25:49 +04:00
|
|
|
gfxPoint pt;
|
|
|
|
if (aParams.isVerticalRun) {
|
|
|
|
pt = gfxPoint(aPt->x, aPt->y - aParams.direction * data.mPartAdvance);
|
|
|
|
} else {
|
|
|
|
pt = gfxPoint(aPt->x - aParams.direction * data.mPartAdvance, aPt->y);
|
|
|
|
}
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawGlyphs(aFont, data.mRange, &pt,
|
|
|
|
aProvider, aRange, aParams, aOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
aParams.context->Restore();
|
|
|
|
|
2014-10-01 23:25:49 +04:00
|
|
|
if (aParams.isVerticalRun) {
|
|
|
|
aPt->y += aParams.direction * data.mPartWidth;
|
|
|
|
} else {
|
|
|
|
aPt->x += aParams.direction * data.mPartWidth;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-01-20 11:50:43 +03:00
|
|
|
// Returns true if a glyph run is using a font with synthetic bolding enabled,
|
|
|
|
// or a color font (COLR/SVG/sbix/CBDT), false otherwise. This is used to
|
|
|
|
// check whether the text run needs to be explicitly composited in order to
|
|
|
|
// support opacity.
|
2014-09-16 13:58:12 +04:00
|
|
|
static bool
|
2016-06-27 19:41:55 +03:00
|
|
|
HasSyntheticBoldOrColor(const gfxTextRun *aRun, gfxTextRun::Range aRange)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::GlyphRunIterator iter(aRun, aRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFont *font = iter.GetGlyphRun()->mFont;
|
2016-01-20 11:50:43 +03:00
|
|
|
if (font) {
|
|
|
|
if (font->IsSyntheticBold()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
gfxFontEntry* fe = font->GetFontEntry();
|
|
|
|
if (fe->TryGetSVGData(font) || fe->TryGetColorGlyphs()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#if defined(XP_MACOSX) // sbix fonts only supported via Core Text
|
|
|
|
if (fe->HasFontTable(TRUETYPE_TAG('s', 'b', 'i', 'x'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-28 23:20:06 +03:00
|
|
|
// Returns true if color is neither opaque nor transparent (i.e. alpha is not 0
|
|
|
|
// or 1), and false otherwise. If true, aCurrentColorOut is set on output.
|
2014-09-16 13:58:12 +04:00
|
|
|
static bool
|
2015-09-28 23:20:06 +03:00
|
|
|
HasNonOpaqueNonTransparentColor(gfxContext *aContext, Color& aCurrentColorOut)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2015-09-24 09:36:15 +03:00
|
|
|
if (aContext->GetDeviceColor(aCurrentColorOut)) {
|
2015-09-28 23:20:06 +03:00
|
|
|
if (0.f < aCurrentColorOut.a && aCurrentColorOut.a < 1.f) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper class for double-buffering drawing with non-opaque color
|
|
|
|
struct BufferAlphaColor {
|
|
|
|
explicit BufferAlphaColor(gfxContext *aContext)
|
|
|
|
: mContext(aContext)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~BufferAlphaColor() {}
|
|
|
|
|
2015-09-24 09:36:15 +03:00
|
|
|
void PushSolidColor(const gfxRect& aBounds, const Color& aAlphaColor, uint32_t appsPerDevUnit)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
mContext->Save();
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->Rectangle(gfxRect(aBounds.X() / appsPerDevUnit,
|
|
|
|
aBounds.Y() / appsPerDevUnit,
|
|
|
|
aBounds.Width() / appsPerDevUnit,
|
|
|
|
aBounds.Height() / appsPerDevUnit), true);
|
|
|
|
mContext->Clip();
|
2015-09-24 09:42:58 +03:00
|
|
|
mContext->SetColor(Color(aAlphaColor.r, aAlphaColor.g, aAlphaColor.b));
|
2015-11-11 18:15:39 +03:00
|
|
|
mContext->PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, aAlphaColor.a);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopAlpha()
|
|
|
|
{
|
|
|
|
// pop the text, using the color alpha as the opacity
|
2015-11-11 18:15:39 +03:00
|
|
|
mContext->PopGroupAndBlend();
|
2014-09-16 13:58:12 +04:00
|
|
|
mContext->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxContext *mContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::Draw(Range aRange, gfxPoint aPt, const DrawParams& aParams) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range");
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aParams.drawMode == DrawMode::GLYPH_PATH ||
|
2016-04-21 18:27:39 +03:00
|
|
|
!(aParams.drawMode & DrawMode::GLYPH_PATH),
|
2014-09-16 13:58:12 +04:00
|
|
|
"GLYPH_PATH cannot be used with GLYPH_FILL, GLYPH_STROKE or GLYPH_STROKE_UNDERNEATH");
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aParams.drawMode == DrawMode::GLYPH_PATH || !aParams.callbacks,
|
2014-09-16 13:58:12 +04:00
|
|
|
"callback must not be specified unless using GLYPH_PATH");
|
|
|
|
|
|
|
|
bool skipDrawing = mSkipDrawing;
|
2016-04-22 20:40:39 +03:00
|
|
|
if (aParams.drawMode & DrawMode::GLYPH_FILL) {
|
2015-09-24 09:36:15 +03:00
|
|
|
Color currentColor;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aParams.context->GetDeviceColor(currentColor) &&
|
|
|
|
currentColor.a == 0) {
|
2014-09-16 13:58:12 +04:00
|
|
|
skipDrawing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat direction = GetDirection();
|
|
|
|
|
|
|
|
if (skipDrawing) {
|
|
|
|
// We don't need to draw anything;
|
|
|
|
// but if the caller wants advance width, we need to compute it here
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aParams.advanceWidth) {
|
|
|
|
gfxTextRun::Metrics metrics = MeasureText(
|
|
|
|
aRange, gfxFont::LOOSE_INK_EXTENTS,
|
|
|
|
aParams.context->GetDrawTarget(), aParams.provider);
|
|
|
|
*aParams.advanceWidth = metrics.mAdvanceWidth * direction;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// return without drawing
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// synthetic bolding draws glyphs twice ==> colors with opacity won't draw
|
|
|
|
// correctly unless first drawn without alpha
|
2016-03-08 10:56:18 +03:00
|
|
|
BufferAlphaColor syntheticBoldBuffer(aParams.context);
|
2015-09-24 09:36:15 +03:00
|
|
|
Color currentColor;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool needToRestore = false;
|
|
|
|
|
2016-04-22 20:40:39 +03:00
|
|
|
if (aParams.drawMode & DrawMode::GLYPH_FILL &&
|
2016-03-08 10:56:18 +03:00
|
|
|
HasNonOpaqueNonTransparentColor(aParams.context, currentColor) &&
|
2016-03-08 10:56:18 +03:00
|
|
|
HasSyntheticBoldOrColor(this, aRange)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
needToRestore = true;
|
2017-02-23 02:10:29 +03:00
|
|
|
// Measure text; use the bounding box to determine the area we need
|
|
|
|
// to buffer.
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::Metrics metrics = MeasureText(
|
|
|
|
aRange, gfxFont::LOOSE_INK_EXTENTS,
|
|
|
|
aParams.context->GetDrawTarget(), aParams.provider);
|
2017-02-23 02:10:29 +03:00
|
|
|
if (IsRightToLeft()) {
|
|
|
|
metrics.mBoundingBox.MoveBy(gfxPoint(aPt.x - metrics.mAdvanceWidth,
|
|
|
|
aPt.y));
|
|
|
|
} else {
|
|
|
|
metrics.mBoundingBox.MoveBy(aPt);
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
syntheticBoldBuffer.PushSolidColor(metrics.mBoundingBox, currentColor,
|
|
|
|
GetAppUnitsPerDevUnit());
|
|
|
|
}
|
|
|
|
|
2015-06-22 05:45:39 +03:00
|
|
|
// Set up parameters that will be constant across all glyph runs we need
|
|
|
|
// to draw, regardless of the font used.
|
|
|
|
TextRunDrawParams params;
|
2016-03-08 10:56:18 +03:00
|
|
|
params.context = aParams.context;
|
2015-06-22 05:45:39 +03:00
|
|
|
params.devPerApp = 1.0 / double(GetAppUnitsPerDevUnit());
|
|
|
|
params.isVerticalRun = IsVertical();
|
|
|
|
params.isRTL = IsRightToLeft();
|
|
|
|
params.direction = direction;
|
2016-07-14 03:00:00 +03:00
|
|
|
params.strokeOpts = aParams.strokeOpts;
|
2016-04-22 20:40:39 +03:00
|
|
|
params.textStrokeColor = aParams.textStrokeColor;
|
2016-07-14 03:00:00 +03:00
|
|
|
params.textStrokePattern = aParams.textStrokePattern;
|
|
|
|
params.drawOpts = aParams.drawOpts;
|
2016-03-08 10:56:18 +03:00
|
|
|
params.drawMode = aParams.drawMode;
|
|
|
|
params.callbacks = aParams.callbacks;
|
|
|
|
params.runContextPaint = aParams.contextPaint;
|
|
|
|
params.paintSVGGlyphs = !aParams.callbacks ||
|
|
|
|
aParams.callbacks->mShouldPaintSVGGlyphs;
|
|
|
|
params.dt = aParams.context->GetDrawTarget();
|
|
|
|
params.fontSmoothingBGColor =
|
|
|
|
aParams.context->GetFontSmoothingBackgroundColor();
|
2015-06-22 05:45:39 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
GlyphRunIterator iter(this, aRange);
|
2014-10-01 23:25:49 +04:00
|
|
|
gfxFloat advance = 0.0;
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFont *font = iter.GetGlyphRun()->mFont;
|
|
|
|
uint32_t start = iter.GetStringStart();
|
|
|
|
uint32_t end = iter.GetStringEnd();
|
2016-03-08 10:56:18 +03:00
|
|
|
Range ligatureRange(start, end);
|
|
|
|
ShrinkToLigatureBoundaries(&ligatureRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-04-22 20:40:39 +03:00
|
|
|
bool drawPartial = (aParams.drawMode & DrawMode::GLYPH_FILL) ||
|
2016-03-08 10:56:18 +03:00
|
|
|
(aParams.drawMode == DrawMode::GLYPH_PATH &&
|
|
|
|
aParams.callbacks);
|
2014-10-01 23:25:49 +04:00
|
|
|
gfxPoint origPt = aPt;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
if (drawPartial) {
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawPartialLigature(font, Range(start, ligatureRange.start),
|
2016-03-08 10:56:18 +03:00
|
|
|
&aPt, aParams.provider, params,
|
2014-10-01 23:25:48 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawGlyphs(font, ligatureRange, &aPt,
|
2016-03-08 10:56:18 +03:00
|
|
|
aParams.provider, ligatureRange, params,
|
2014-10-01 23:25:48 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
if (drawPartial) {
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawPartialLigature(font, Range(ligatureRange.end, end),
|
2016-03-08 10:56:18 +03:00
|
|
|
&aPt, aParams.provider, params,
|
2014-10-01 23:25:48 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2014-10-01 23:25:49 +04:00
|
|
|
|
|
|
|
if (params.isVerticalRun) {
|
|
|
|
advance += (aPt.y - origPt.y) * params.direction;
|
|
|
|
} else {
|
|
|
|
advance += (aPt.x - origPt.x) * params.direction;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// composite result when synthetic bolding used
|
|
|
|
if (needToRestore) {
|
|
|
|
syntheticBoldBuffer.PopAlpha();
|
|
|
|
}
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aParams.advanceWidth) {
|
|
|
|
*aParams.advanceWidth = advance;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
// This method is mostly parallel to Draw().
|
|
|
|
void
|
|
|
|
gfxTextRun::DrawEmphasisMarks(gfxContext *aContext, gfxTextRun* aMark,
|
|
|
|
gfxFloat aMarkAdvance, gfxPoint aPt,
|
2016-06-27 19:41:55 +03:00
|
|
|
Range aRange, PropertyProvider* aProvider) const
|
2015-11-28 03:56:33 +03:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
MOZ_ASSERT(aRange.end <= GetLength());
|
2015-11-28 03:56:33 +03:00
|
|
|
|
|
|
|
EmphasisMarkDrawParams params;
|
|
|
|
params.context = aContext;
|
|
|
|
params.mark = aMark;
|
|
|
|
params.advance = aMarkAdvance;
|
|
|
|
params.direction = GetDirection();
|
|
|
|
params.isVertical = IsVertical();
|
|
|
|
|
|
|
|
gfxFloat& inlineCoord = params.isVertical ? aPt.y : aPt.x;
|
|
|
|
gfxFloat direction = params.direction;
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
GlyphRunIterator iter(this, aRange);
|
2015-11-28 03:56:33 +03:00
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFont* font = iter.GetGlyphRun()->mFont;
|
|
|
|
uint32_t start = iter.GetStringStart();
|
|
|
|
uint32_t end = iter.GetStringEnd();
|
2016-03-08 10:56:18 +03:00
|
|
|
Range ligatureRange(start, end);
|
|
|
|
ShrinkToLigatureBoundaries(&ligatureRange);
|
2015-11-28 03:56:33 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
inlineCoord += direction * ComputePartialLigatureWidth(
|
|
|
|
Range(start, ligatureRange.start), aProvider);
|
2015-11-28 03:56:33 +03:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<PropertyProvider::Spacing, 200> spacingBuffer;
|
2015-11-28 03:56:33 +03:00
|
|
|
bool haveSpacing = GetAdjustedSpacingArray(
|
2016-03-08 10:56:18 +03:00
|
|
|
ligatureRange, aProvider, ligatureRange, &spacingBuffer);
|
2015-11-28 03:56:33 +03:00
|
|
|
params.spacing = haveSpacing ? spacingBuffer.Elements() : nullptr;
|
2016-03-08 10:56:18 +03:00
|
|
|
font->DrawEmphasisMarks(this, &aPt, ligatureRange.start,
|
|
|
|
ligatureRange.Length(), params);
|
2015-11-28 03:56:33 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
inlineCoord += direction * ComputePartialLigatureWidth(
|
|
|
|
Range(ligatureRange.end, end), aProvider);
|
2015-11-28 03:56:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::AccumulateMetricsForRun(gfxFont *aFont, Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aRefDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
PropertyProvider *aProvider,
|
2016-03-08 10:56:18 +03:00
|
|
|
Range aSpacingRange,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aOrientation,
|
2016-06-27 19:41:55 +03:00
|
|
|
Metrics *aMetrics) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<PropertyProvider::Spacing,200> spacingBuffer;
|
2016-03-08 10:56:18 +03:00
|
|
|
bool haveSpacing = GetAdjustedSpacingArray(aRange, aProvider,
|
|
|
|
aSpacingRange, &spacingBuffer);
|
|
|
|
Metrics metrics = aFont->Measure(this, aRange.start, aRange.end,
|
|
|
|
aBoundingBoxType, aRefDrawTarget,
|
2014-10-16 12:40:19 +04:00
|
|
|
haveSpacing ? spacingBuffer.Elements() : nullptr,
|
|
|
|
aOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
aMetrics->CombineWith(metrics, IsRightToLeft());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::AccumulatePartialLigatureMetrics(gfxFont *aFont, Range aRange,
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType, DrawTarget* aRefDrawTarget,
|
2017-05-05 00:27:05 +03:00
|
|
|
PropertyProvider *aProvider, gfx::ShapedTextFlags aOrientation,
|
2016-06-27 19:41:55 +03:00
|
|
|
Metrics *aMetrics) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
if (aRange.start >= aRange.end)
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Measure partial ligature. We hack this by clipping the metrics in the
|
|
|
|
// same way we clip the drawing.
|
2016-03-08 10:56:18 +03:00
|
|
|
LigatureData data = ComputeLigatureData(aRange, aProvider);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// First measure the complete ligature
|
|
|
|
Metrics metrics;
|
2016-03-08 10:56:18 +03:00
|
|
|
AccumulateMetricsForRun(aFont, data.mRange,
|
2015-12-16 00:56:41 +03:00
|
|
|
aBoundingBoxType, aRefDrawTarget,
|
2016-03-08 10:56:18 +03:00
|
|
|
aProvider, aRange, aOrientation, &metrics);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// Clip the bounding box to the ligature part
|
|
|
|
gfxFloat bboxLeft = metrics.mBoundingBox.X();
|
|
|
|
gfxFloat bboxRight = metrics.mBoundingBox.XMost();
|
|
|
|
// Where we are going to start "drawing" relative to our left baseline origin
|
|
|
|
gfxFloat origin = IsRightToLeft() ? metrics.mAdvanceWidth - data.mPartAdvance : 0;
|
|
|
|
ClipPartialLigature(this, &bboxLeft, &bboxRight, origin, &data);
|
|
|
|
metrics.mBoundingBox.x = bboxLeft;
|
|
|
|
metrics.mBoundingBox.width = bboxRight - bboxLeft;
|
|
|
|
|
|
|
|
// mBoundingBox is now relative to the left baseline origin for the entire
|
|
|
|
// ligature. Shift it left.
|
|
|
|
metrics.mBoundingBox.x -=
|
|
|
|
IsRightToLeft() ? metrics.mAdvanceWidth - (data.mPartAdvance + data.mPartWidth)
|
2017-01-04 18:55:16 +03:00
|
|
|
: data.mPartAdvance;
|
2014-09-16 13:58:12 +04:00
|
|
|
metrics.mAdvanceWidth = data.mPartWidth;
|
|
|
|
|
|
|
|
aMetrics->CombineWith(metrics, IsRightToLeft());
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::Metrics
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::MeasureText(Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aRefDrawTarget,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider *aProvider) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range");
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
Metrics accumulatedMetrics;
|
2016-03-08 10:56:18 +03:00
|
|
|
GlyphRunIterator iter(this, aRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFont *font = iter.GetGlyphRun()->mFont;
|
|
|
|
uint32_t start = iter.GetStringStart();
|
|
|
|
uint32_t end = iter.GetStringEnd();
|
2016-03-08 10:56:18 +03:00
|
|
|
Range ligatureRange(start, end);
|
|
|
|
ShrinkToLigatureBoundaries(&ligatureRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
AccumulatePartialLigatureMetrics(
|
|
|
|
font, Range(start, ligatureRange.start),
|
2015-12-16 00:56:41 +03:00
|
|
|
aBoundingBoxType, aRefDrawTarget, aProvider,
|
2014-10-16 12:40:19 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// XXX This sucks. We have to get glyph extents just so we can detect
|
|
|
|
// glyphs outside the font box, even when aBoundingBoxType is LOOSE,
|
|
|
|
// even though in almost all cases we could get correct results just
|
|
|
|
// by getting some ascent/descent from the font and using our stored
|
|
|
|
// advance widths.
|
|
|
|
AccumulateMetricsForRun(font,
|
2016-03-08 10:56:18 +03:00
|
|
|
ligatureRange, aBoundingBoxType,
|
|
|
|
aRefDrawTarget, aProvider, ligatureRange,
|
2014-10-16 12:40:19 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
AccumulatePartialLigatureMetrics(
|
|
|
|
font, Range(ligatureRange.end, end),
|
2015-12-16 00:56:41 +03:00
|
|
|
aBoundingBoxType, aRefDrawTarget, aProvider,
|
2014-10-16 12:40:19 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation, &accumulatedMetrics);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return accumulatedMetrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MEASUREMENT_BUFFER_SIZE 100
|
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
void
|
|
|
|
gfxTextRun::ClassifyAutoHyphenations(uint32_t aStart, Range aRange,
|
|
|
|
nsTArray<HyphenType>& aHyphenBuffer,
|
|
|
|
HyphenationState* aWordState)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRange.end - aStart <= aHyphenBuffer.Length() &&
|
|
|
|
aRange.start >= aStart, "Range out of bounds");
|
|
|
|
MOZ_ASSERT(aWordState->mostRecentBoundary >= aStart,
|
|
|
|
"Unexpected aMostRecentWordBoundary!!");
|
|
|
|
|
|
|
|
uint32_t start = std::min<uint32_t>(aRange.start, aWordState->mostRecentBoundary);
|
|
|
|
|
|
|
|
for (uint32_t i = start; i < aRange.end; ++i) {
|
|
|
|
if (aHyphenBuffer[i - aStart] == HyphenType::Explicit &&
|
|
|
|
!aWordState->hasExplicitHyphen) {
|
|
|
|
aWordState->hasExplicitHyphen = true;
|
|
|
|
}
|
|
|
|
if (!aWordState->hasManualHyphen &&
|
|
|
|
(aHyphenBuffer[i - aStart] == HyphenType::Soft ||
|
|
|
|
aHyphenBuffer[i - aStart] == HyphenType::Explicit)) {
|
|
|
|
aWordState->hasManualHyphen = true;
|
|
|
|
// This is the first manual hyphen in the current word. We can only
|
|
|
|
// know if the current word has a manual hyphen until now. So, we need
|
|
|
|
// to run a sub loop to update the auto hyphens between the start of
|
|
|
|
// the current word and this manual hyphen.
|
|
|
|
if (aWordState->hasAutoHyphen) {
|
|
|
|
for (uint32_t j = aWordState->mostRecentBoundary; j < i; j++) {
|
|
|
|
if (aHyphenBuffer[j - aStart] == HyphenType::AutoWithoutManualInSameWord) {
|
|
|
|
aHyphenBuffer[j - aStart] = HyphenType::AutoWithManualInSameWord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aHyphenBuffer[i - aStart] == HyphenType::AutoWithoutManualInSameWord) {
|
|
|
|
if (!aWordState->hasAutoHyphen) {
|
|
|
|
aWordState->hasAutoHyphen = true;
|
|
|
|
}
|
|
|
|
if (aWordState->hasManualHyphen) {
|
|
|
|
aHyphenBuffer[i - aStart] = HyphenType::AutoWithManualInSameWord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're at the word boundary, clear/reset couple states.
|
|
|
|
if (mCharacterGlyphs[i].CharIsSpace() ||
|
|
|
|
mCharacterGlyphs[i].CharIsTab() ||
|
|
|
|
mCharacterGlyphs[i].CharIsNewline() ||
|
|
|
|
// Since we will not have a boundary in the end of the string, let's
|
|
|
|
// call the end of the string a special case for word boundary.
|
|
|
|
i == GetLength() - 1) {
|
|
|
|
// We can only get to know whether we should raise/clear an explicit
|
|
|
|
// manual hyphen until we get to the end of a word, because this depends
|
|
|
|
// on whether there exists at least one auto hyphen in the same word.
|
|
|
|
if (!aWordState->hasAutoHyphen && aWordState->hasExplicitHyphen) {
|
|
|
|
for (uint32_t j = aWordState->mostRecentBoundary; j <= i; j++) {
|
|
|
|
if (aHyphenBuffer[j - aStart] == HyphenType::Explicit) {
|
|
|
|
aHyphenBuffer[j - aStart] = HyphenType::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aWordState->mostRecentBoundary = i;
|
|
|
|
aWordState->hasManualHyphen = false;
|
|
|
|
aWordState->hasAutoHyphen = false;
|
|
|
|
aWordState->hasExplicitHyphen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t
|
|
|
|
gfxTextRun::BreakAndMeasureText(uint32_t aStart, uint32_t aMaxLength,
|
|
|
|
bool aLineBreakBefore, gfxFloat aWidth,
|
|
|
|
PropertyProvider *aProvider,
|
2014-12-22 07:17:55 +03:00
|
|
|
SuppressBreak aSuppressBreak,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat *aTrimWhitespace,
|
2016-03-21 00:54:00 +03:00
|
|
|
bool aWhitespaceCanHang,
|
2014-09-16 13:58:12 +04:00
|
|
|
Metrics *aMetrics,
|
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aRefDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
bool *aUsedHyphenation,
|
|
|
|
uint32_t *aLastBreak,
|
|
|
|
bool aCanWordWrap,
|
|
|
|
gfxBreakPriority *aBreakPriority)
|
|
|
|
{
|
|
|
|
aMaxLength = std::min(aMaxLength, GetLength() - aStart);
|
|
|
|
|
|
|
|
NS_ASSERTION(aStart + aMaxLength <= GetLength(), "Substring out of range");
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
Range bufferRange(aStart, aStart +
|
|
|
|
std::min<uint32_t>(aMaxLength, MEASUREMENT_BUFFER_SIZE));
|
2014-09-16 13:58:12 +04:00
|
|
|
PropertyProvider::Spacing spacingBuffer[MEASUREMENT_BUFFER_SIZE];
|
2017-05-05 00:27:05 +03:00
|
|
|
bool haveSpacing = aProvider &&
|
|
|
|
!!(mFlags & gfx::ShapedTextFlags::TEXT_ENABLE_SPACING);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (haveSpacing) {
|
2016-03-08 10:56:18 +03:00
|
|
|
GetAdjustedSpacing(this, bufferRange, aProvider, spacingBuffer);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2017-03-13 07:54:05 +03:00
|
|
|
AutoTArray<HyphenType, 4096> hyphenBuffer;
|
2017-03-13 07:54:05 +03:00
|
|
|
HyphenationState wordState;
|
|
|
|
wordState.mostRecentBoundary = aStart;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool haveHyphenation = aProvider &&
|
2017-01-04 18:55:16 +03:00
|
|
|
(aProvider->GetHyphensOption() == StyleHyphens::Auto ||
|
|
|
|
(aProvider->GetHyphensOption() == StyleHyphens::Manual &&
|
2017-05-05 00:27:05 +03:00
|
|
|
!!(mFlags & gfx::ShapedTextFlags::TEXT_ENABLE_HYPHEN_BREAKS)));
|
2014-09-16 13:58:12 +04:00
|
|
|
if (haveHyphenation) {
|
2017-03-13 07:54:04 +03:00
|
|
|
if (hyphenBuffer.AppendElements(bufferRange.Length(), fallible)) {
|
|
|
|
aProvider->GetHyphenationBreaks(bufferRange, hyphenBuffer.Elements());
|
2017-03-13 07:54:05 +03:00
|
|
|
if (aProvider->GetHyphensOption() == StyleHyphens::Auto) {
|
|
|
|
ClassifyAutoHyphenations(aStart, bufferRange, hyphenBuffer,
|
|
|
|
&wordState);
|
|
|
|
}
|
2017-03-13 07:54:04 +03:00
|
|
|
} else {
|
|
|
|
haveHyphenation = false;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat width = 0;
|
|
|
|
gfxFloat advance = 0;
|
2016-03-21 00:54:00 +03:00
|
|
|
// The number of space characters that can be trimmed or hang at a soft-wrap
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t trimmableChars = 0;
|
|
|
|
// The amount of space removed by ignoring trimmableChars
|
|
|
|
gfxFloat trimmableAdvance = 0;
|
|
|
|
int32_t lastBreak = -1;
|
|
|
|
int32_t lastBreakTrimmableChars = -1;
|
|
|
|
gfxFloat lastBreakTrimmableAdvance = -1;
|
2017-03-13 07:54:05 +03:00
|
|
|
// Cache the last candidate break
|
|
|
|
int32_t lastCandidateBreak = -1;
|
|
|
|
int32_t lastCandidateBreakTrimmableChars = -1;
|
|
|
|
gfxFloat lastCandidateBreakTrimmableAdvance = -1;
|
|
|
|
bool lastCandidateBreakUsedHyphenation = false;
|
|
|
|
gfxBreakPriority lastCandidateBreakPriority = gfxBreakPriority::eNoBreak;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool aborted = false;
|
|
|
|
uint32_t end = aStart + aMaxLength;
|
|
|
|
bool lastBreakUsedHyphenation = false;
|
2016-03-08 10:56:18 +03:00
|
|
|
Range ligatureRange(aStart, end);
|
|
|
|
ShrinkToLigatureBoundaries(&ligatureRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
// We may need to move `i` backwards in the following loop, and re-scan
|
|
|
|
// part of the textrun; we'll use `rescanLimit` so we can tell when that
|
|
|
|
// is happening: if `i < rescanLimit` then we're rescanning.
|
|
|
|
uint32_t rescanLimit = aStart;
|
|
|
|
for (uint32_t i = aStart; i < end; ++i) {
|
2016-03-08 10:56:18 +03:00
|
|
|
if (i >= bufferRange.end) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// Fetch more spacing and hyphenation data
|
2017-03-13 07:54:04 +03:00
|
|
|
uint32_t oldHyphenBufferLength = hyphenBuffer.Length();
|
2016-03-08 10:56:18 +03:00
|
|
|
bufferRange.start = i;
|
|
|
|
bufferRange.end = std::min(aStart + aMaxLength,
|
|
|
|
i + MEASUREMENT_BUFFER_SIZE);
|
2017-03-13 07:54:04 +03:00
|
|
|
// For spacing, we always overwrite the old data with the newly
|
|
|
|
// fetched one. However, for hyphenation, hyphenation data sometimes
|
|
|
|
// depends on the context in every word (if "hyphens: auto" is set).
|
|
|
|
// To ensure we get enough information between neighboring buffers,
|
|
|
|
// we grow the hyphenBuffer instead of overwrite it.
|
|
|
|
// NOTE that this means bufferRange does not correspond to the
|
|
|
|
// entire hyphenBuffer, but only to the most recently added portion.
|
|
|
|
// Therefore, we need to add the old length to hyphenBuffer.Elements()
|
|
|
|
// when getting more data.
|
2014-09-16 13:58:12 +04:00
|
|
|
if (haveSpacing) {
|
2016-03-08 10:56:18 +03:00
|
|
|
GetAdjustedSpacing(this, bufferRange, aProvider, spacingBuffer);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
if (haveHyphenation) {
|
2017-03-13 07:54:04 +03:00
|
|
|
if (hyphenBuffer.AppendElements(bufferRange.Length(), fallible)) {
|
|
|
|
aProvider->GetHyphenationBreaks(
|
|
|
|
bufferRange, hyphenBuffer.Elements() + oldHyphenBufferLength);
|
2017-03-13 07:54:05 +03:00
|
|
|
if (aProvider->GetHyphensOption() == StyleHyphens::Auto) {
|
|
|
|
uint32_t prevMostRecentWordBoundary = wordState.mostRecentBoundary;
|
|
|
|
ClassifyAutoHyphenations(aStart, bufferRange, hyphenBuffer,
|
|
|
|
&wordState);
|
|
|
|
// If the buffer boundary is in the middle of a word,
|
|
|
|
// we need to go back to the start of the current word.
|
|
|
|
// So, we can correct the wrong candidates that we set
|
|
|
|
// in the previous runs of the loop.
|
|
|
|
if (prevMostRecentWordBoundary < oldHyphenBufferLength) {
|
|
|
|
rescanLimit = i;
|
|
|
|
i = prevMostRecentWordBoundary - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 07:54:04 +03:00
|
|
|
} else {
|
|
|
|
haveHyphenation = false;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// There can't be a word-wrap break opportunity at the beginning of the
|
2017-01-04 18:55:16 +03:00
|
|
|
// line: if the width is too small for even one character to fit, it
|
2014-09-16 13:58:12 +04:00
|
|
|
// could be the first and last break opportunity on the line, and that
|
|
|
|
// would trigger an infinite loop.
|
2014-12-22 07:17:55 +03:00
|
|
|
if (aSuppressBreak != eSuppressAllBreaks &&
|
|
|
|
(aSuppressBreak != eSuppressInitialBreak || i > aStart)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
bool atNaturalBreak = mCharacterGlyphs[i].CanBreakBefore() == 1;
|
2017-03-13 07:54:05 +03:00
|
|
|
bool atHyphenationBreak = !atNaturalBreak && haveHyphenation &&
|
|
|
|
hyphenBuffer[i - aStart] != HyphenType::None;
|
2017-03-13 07:54:05 +03:00
|
|
|
bool atAutoHyphenWithManualHyphenInSameWord = atHyphenationBreak &&
|
|
|
|
hyphenBuffer[i - aStart] == HyphenType::AutoWithManualInSameWord;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool atBreak = atNaturalBreak || atHyphenationBreak;
|
|
|
|
bool wordWrapping =
|
|
|
|
aCanWordWrap && mCharacterGlyphs[i].IsClusterStart() &&
|
|
|
|
*aBreakPriority <= gfxBreakPriority::eWordWrapBreak;
|
|
|
|
|
|
|
|
if (atBreak || wordWrapping) {
|
|
|
|
gfxFloat hyphenatedAdvance = advance;
|
|
|
|
if (atHyphenationBreak) {
|
|
|
|
hyphenatedAdvance += aProvider->GetHyphenWidth();
|
|
|
|
}
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
if (lastBreak < 0 ||
|
|
|
|
width + hyphenatedAdvance - trimmableAdvance <= aWidth) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// We can break here.
|
|
|
|
lastBreak = i;
|
|
|
|
lastBreakTrimmableChars = trimmableChars;
|
|
|
|
lastBreakTrimmableAdvance = trimmableAdvance;
|
|
|
|
lastBreakUsedHyphenation = atHyphenationBreak;
|
|
|
|
*aBreakPriority = atBreak ? gfxBreakPriority::eNormalBreak
|
|
|
|
: gfxBreakPriority::eWordWrapBreak;
|
|
|
|
}
|
|
|
|
|
|
|
|
width += advance;
|
|
|
|
advance = 0;
|
|
|
|
if (width - trimmableAdvance > aWidth) {
|
|
|
|
// No more text fits. Abort
|
|
|
|
aborted = true;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-13 07:54:05 +03:00
|
|
|
// There are various kinds of break opportunities:
|
|
|
|
// 1. word wrap break,
|
|
|
|
// 2. natural break,
|
|
|
|
// 3. manual hyphenation break,
|
|
|
|
// 4. auto hyphenation break without any manual hyphenation
|
|
|
|
// in the same word,
|
|
|
|
// 5. auto hyphenation break with another manual hyphenation
|
|
|
|
// in the same word.
|
|
|
|
// Allow all of them except the last one to be a candidate.
|
|
|
|
// So, we can ensure that we don't use an automatic
|
|
|
|
// hyphenation opportunity within a word that contains another
|
|
|
|
// manual hyphenation, unless it is the only choice.
|
|
|
|
if (wordWrapping ||
|
|
|
|
!atAutoHyphenWithManualHyphenInSameWord) {
|
|
|
|
lastCandidateBreak = lastBreak;
|
|
|
|
lastCandidateBreakTrimmableChars = lastBreakTrimmableChars;
|
|
|
|
lastCandidateBreakTrimmableAdvance = lastBreakTrimmableAdvance;
|
|
|
|
lastCandidateBreakUsedHyphenation = lastBreakUsedHyphenation;
|
|
|
|
lastCandidateBreakPriority = *aBreakPriority;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
// If we're re-scanning part of a word (to re-process potential
|
|
|
|
// hyphenation types) then we don't want to accumulate widths again
|
|
|
|
// for the characters that were already added to `advance`.
|
|
|
|
if (i < rescanLimit) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat charAdvance;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (i >= ligatureRange.start && i < ligatureRange.end) {
|
|
|
|
charAdvance = GetAdvanceForGlyphs(Range(i, i + 1));
|
2014-09-16 13:58:12 +04:00
|
|
|
if (haveSpacing) {
|
2016-03-08 10:56:18 +03:00
|
|
|
PropertyProvider::Spacing *space =
|
|
|
|
&spacingBuffer[i - bufferRange.start];
|
2014-09-16 13:58:12 +04:00
|
|
|
charAdvance += space->mBefore + space->mAfter;
|
|
|
|
}
|
|
|
|
} else {
|
2016-03-08 10:56:18 +03:00
|
|
|
charAdvance =
|
|
|
|
ComputePartialLigatureWidth(Range(i, i + 1), aProvider);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
advance += charAdvance;
|
2016-03-21 00:54:00 +03:00
|
|
|
if (aTrimWhitespace || aWhitespaceCanHang) {
|
2014-09-16 13:58:12 +04:00
|
|
|
if (mCharacterGlyphs[i].CharIsSpace()) {
|
|
|
|
++trimmableChars;
|
|
|
|
trimmableAdvance += charAdvance;
|
|
|
|
} else {
|
|
|
|
trimmableAdvance = 0;
|
|
|
|
trimmableChars = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aborted) {
|
|
|
|
width += advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are three possibilities:
|
|
|
|
// 1) all the text fit (width <= aWidth)
|
|
|
|
// 2) some of the text fit up to a break opportunity (width > aWidth && lastBreak >= 0)
|
|
|
|
// 3) none of the text fits before a break opportunity (width > aWidth && lastBreak < 0)
|
|
|
|
uint32_t charsFit;
|
|
|
|
bool usedHyphenation = false;
|
|
|
|
if (width - trimmableAdvance <= aWidth) {
|
|
|
|
charsFit = aMaxLength;
|
|
|
|
} else if (lastBreak >= 0) {
|
2017-03-13 07:54:05 +03:00
|
|
|
if (lastCandidateBreak >= 0 && lastCandidateBreak != lastBreak) {
|
|
|
|
lastBreak = lastCandidateBreak;
|
|
|
|
lastBreakTrimmableChars = lastCandidateBreakTrimmableChars;
|
|
|
|
lastBreakTrimmableAdvance = lastCandidateBreakTrimmableAdvance;
|
|
|
|
lastBreakUsedHyphenation = lastCandidateBreakUsedHyphenation;
|
|
|
|
*aBreakPriority = lastCandidateBreakPriority;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
charsFit = lastBreak - aStart;
|
|
|
|
trimmableChars = lastBreakTrimmableChars;
|
|
|
|
trimmableAdvance = lastBreakTrimmableAdvance;
|
|
|
|
usedHyphenation = lastBreakUsedHyphenation;
|
|
|
|
} else {
|
|
|
|
charsFit = aMaxLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMetrics) {
|
2016-03-08 10:56:18 +03:00
|
|
|
auto fitEnd = aStart + charsFit;
|
2016-03-21 00:54:00 +03:00
|
|
|
// Initially, measure everything, so that our bounding box includes
|
|
|
|
// any trimmable or hanging whitespace.
|
|
|
|
*aMetrics = MeasureText(Range(aStart, fitEnd),
|
|
|
|
aBoundingBoxType, aRefDrawTarget,
|
|
|
|
aProvider);
|
|
|
|
if (aTrimWhitespace || aWhitespaceCanHang) {
|
|
|
|
// Measure trailing whitespace that is to be trimmed/hung.
|
|
|
|
Metrics trimOrHangMetrics =
|
2016-08-26 12:30:45 +03:00
|
|
|
MeasureText(Range(fitEnd - trimmableChars, fitEnd),
|
2016-03-21 00:54:00 +03:00
|
|
|
aBoundingBoxType, aRefDrawTarget,
|
|
|
|
aProvider);
|
|
|
|
if (aTrimWhitespace) {
|
|
|
|
aMetrics->mAdvanceWidth -= trimOrHangMetrics.mAdvanceWidth;
|
|
|
|
} else if (aMetrics->mAdvanceWidth > aWidth) {
|
|
|
|
// Restrict width of hanging whitespace so it doesn't overflow.
|
|
|
|
aMetrics->mAdvanceWidth =
|
|
|
|
std::max(aWidth, aMetrics->mAdvanceWidth -
|
|
|
|
trimOrHangMetrics.mAdvanceWidth);
|
|
|
|
}
|
2015-04-01 16:45:16 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
if (aTrimWhitespace) {
|
|
|
|
*aTrimWhitespace = trimmableAdvance;
|
|
|
|
}
|
|
|
|
if (aUsedHyphenation) {
|
|
|
|
*aUsedHyphenation = usedHyphenation;
|
|
|
|
}
|
|
|
|
if (aLastBreak && charsFit == aMaxLength) {
|
|
|
|
if (lastBreak < 0) {
|
|
|
|
*aLastBreak = UINT32_MAX;
|
|
|
|
} else {
|
|
|
|
*aLastBreak = lastBreak - aStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return charsFit;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::GetAdvanceWidth(Range aRange, PropertyProvider *aProvider,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider::Spacing* aSpacing) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aRange.end <= GetLength(), "Substring out of range");
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
Range ligatureRange = aRange;
|
|
|
|
ShrinkToLigatureBoundaries(&ligatureRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxFloat result =
|
|
|
|
ComputePartialLigatureWidth(Range(aRange.start, ligatureRange.start),
|
|
|
|
aProvider) +
|
|
|
|
ComputePartialLigatureWidth(Range(ligatureRange.end, aRange.end),
|
|
|
|
aProvider);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2014-11-10 04:25:09 +03:00
|
|
|
if (aSpacing) {
|
|
|
|
aSpacing->mBefore = aSpacing->mAfter = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Account for all remaining spacing here. This is more efficient than
|
|
|
|
// processing it along with the glyphs.
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aProvider && (mFlags & gfx::ShapedTextFlags::TEXT_ENABLE_SPACING)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t i;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<PropertyProvider::Spacing,200> spacingBuffer;
|
2016-03-08 10:56:18 +03:00
|
|
|
if (spacingBuffer.AppendElements(aRange.Length())) {
|
|
|
|
GetAdjustedSpacing(this, ligatureRange, aProvider,
|
2014-09-16 13:58:12 +04:00
|
|
|
spacingBuffer.Elements());
|
2016-03-08 10:56:18 +03:00
|
|
|
for (i = 0; i < ligatureRange.Length(); ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
PropertyProvider::Spacing *space = &spacingBuffer[i];
|
|
|
|
result += space->mBefore + space->mAfter;
|
|
|
|
}
|
2014-11-10 04:25:09 +03:00
|
|
|
if (aSpacing) {
|
|
|
|
aSpacing->mBefore = spacingBuffer[0].mBefore;
|
|
|
|
aSpacing->mAfter = spacingBuffer.LastElement().mAfter;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
return result + GetAdvanceForGlyphs(ligatureRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::SetLineBreaks(Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
bool aLineBreakBefore, bool aLineBreakAfter,
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFloat *aAdvanceWidthDelta)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
// Do nothing because our shaping does not currently take linebreaks into
|
|
|
|
// account. There is no change in advance width.
|
|
|
|
if (aAdvanceWidthDelta) {
|
|
|
|
*aAdvanceWidthDelta = 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::FindFirstGlyphRunContaining(uint32_t aOffset) const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aOffset <= GetLength(), "Bad offset looking for glyphrun");
|
2017-05-02 13:14:53 +03:00
|
|
|
NS_ASSERTION(GetLength() == 0 ||
|
|
|
|
(!mHasGlyphRunArray && mSingleGlyphRun.mFont) ||
|
|
|
|
(mHasGlyphRunArray && mGlyphRunArray.Length() > 0),
|
2014-09-16 13:58:12 +04:00
|
|
|
"non-empty text but no glyph runs present!");
|
2017-05-02 13:14:53 +03:00
|
|
|
if (!mHasGlyphRunArray) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (aOffset == GetLength()) {
|
|
|
|
return mGlyphRunArray.Length();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t start = 0;
|
2017-05-02 13:14:53 +03:00
|
|
|
uint32_t end = mGlyphRunArray.Length();
|
2014-09-16 13:58:12 +04:00
|
|
|
while (end - start > 1) {
|
|
|
|
uint32_t mid = (start + end)/2;
|
2017-05-02 13:14:53 +03:00
|
|
|
if (mGlyphRunArray[mid].mCharacterOffset <= aOffset) {
|
2014-09-16 13:58:12 +04:00
|
|
|
start = mid;
|
|
|
|
} else {
|
|
|
|
end = mid;
|
|
|
|
}
|
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
NS_ASSERTION(mGlyphRunArray[start].mCharacterOffset <= aOffset,
|
2014-09-16 13:58:12 +04:00
|
|
|
"Hmm, something went wrong, aOffset should have been found");
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxTextRun::AddGlyphRun(gfxFont *aFont, uint8_t aMatchType,
|
2014-09-16 15:25:45 +04:00
|
|
|
uint32_t aUTF16Offset, bool aForceNewRun,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFont, "adding glyph run for null font!");
|
2017-05-05 00:27:05 +03:00
|
|
|
NS_ASSERTION(aOrientation != gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED,
|
2014-09-16 15:25:45 +04:00
|
|
|
"mixed orientation should have been resolved");
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!aFont) {
|
|
|
|
return NS_OK;
|
2017-01-04 18:55:16 +03:00
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
if (!mHasGlyphRunArray) {
|
|
|
|
// We don't currently have an array.
|
|
|
|
if (!mSingleGlyphRun.mFont) {
|
|
|
|
// This is the first glyph run: just store it directly.
|
|
|
|
mSingleGlyphRun.mFont = aFont;
|
|
|
|
mSingleGlyphRun.mMatchType = aMatchType;
|
|
|
|
mSingleGlyphRun.mOrientation = aOrientation;
|
|
|
|
mSingleGlyphRun.mCharacterOffset = aUTF16Offset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t numGlyphRuns = mHasGlyphRunArray ? mGlyphRunArray.Length() : 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!aForceNewRun && numGlyphRuns > 0) {
|
2017-05-02 13:14:53 +03:00
|
|
|
GlyphRun* lastGlyphRun =
|
|
|
|
mHasGlyphRunArray ? &mGlyphRunArray[numGlyphRuns - 1]
|
|
|
|
: &mSingleGlyphRun;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(lastGlyphRun->mCharacterOffset <= aUTF16Offset,
|
|
|
|
"Glyph runs out of order (and run not forced)");
|
|
|
|
|
|
|
|
// Don't append a run if the font is already the one we want
|
|
|
|
if (lastGlyphRun->mFont == aFont &&
|
2014-09-16 15:25:45 +04:00
|
|
|
lastGlyphRun->mMatchType == aMatchType &&
|
|
|
|
lastGlyphRun->mOrientation == aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the offset has not changed, avoid leaving a zero-length run
|
|
|
|
// by overwriting the last entry instead of appending...
|
|
|
|
if (lastGlyphRun->mCharacterOffset == aUTF16Offset) {
|
|
|
|
|
|
|
|
// ...except that if the run before the last entry had the same
|
|
|
|
// font as the new one wants, merge with it instead of creating
|
|
|
|
// adjacent runs with the same font
|
|
|
|
if (numGlyphRuns > 1 &&
|
2017-05-02 13:14:53 +03:00
|
|
|
mGlyphRunArray[numGlyphRuns - 2].mFont == aFont &&
|
|
|
|
mGlyphRunArray[numGlyphRuns - 2].mMatchType == aMatchType &&
|
|
|
|
mGlyphRunArray[numGlyphRuns - 2].mOrientation == aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-05-02 13:14:53 +03:00
|
|
|
mGlyphRunArray.TruncateLength(numGlyphRuns - 1);
|
|
|
|
if (mGlyphRunArray.Length() == 1) {
|
|
|
|
ConvertFromGlyphRunArray();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastGlyphRun->mFont = aFont;
|
|
|
|
lastGlyphRun->mMatchType = aMatchType;
|
2014-09-16 15:25:45 +04:00
|
|
|
lastGlyphRun->mOrientation = aOrientation;
|
2014-09-16 13:58:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aForceNewRun || numGlyphRuns > 0 || aUTF16Offset == 0,
|
|
|
|
"First run doesn't cover the first character (and run not forced)?");
|
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
if (!mHasGlyphRunArray) {
|
|
|
|
ConvertToGlyphRunArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
GlyphRun* glyphRun = mGlyphRunArray.AppendElement();
|
|
|
|
if (!glyphRun) {
|
|
|
|
if (mGlyphRunArray.Length() == 1) {
|
|
|
|
ConvertFromGlyphRunArray();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
glyphRun->mFont = aFont;
|
|
|
|
glyphRun->mCharacterOffset = aUTF16Offset;
|
|
|
|
glyphRun->mMatchType = aMatchType;
|
2014-09-16 15:25:45 +04:00
|
|
|
glyphRun->mOrientation = aOrientation;
|
2017-05-02 13:14:53 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxTextRun::SortGlyphRuns()
|
|
|
|
{
|
2017-05-02 13:14:53 +03:00
|
|
|
if (!mHasGlyphRunArray) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We should never have an empty or one-element array here; if there's only
|
|
|
|
// one glyphrun, it should be stored directly in the textrun without using
|
|
|
|
// an array at all.
|
|
|
|
MOZ_ASSERT(mGlyphRunArray.Length() > 1);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
AutoTArray<GlyphRun,16> runs(Move(mGlyphRunArray));
|
2014-09-16 13:58:12 +04:00
|
|
|
GlyphRunOffsetComparator comp;
|
|
|
|
runs.Sort(comp);
|
|
|
|
|
|
|
|
// Now copy back, coalescing adjacent glyph runs that have the same font
|
2017-05-02 13:14:53 +03:00
|
|
|
mGlyphRunArray.Clear();
|
|
|
|
gfxFont* prevFont = nullptr;
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags prevOrient = gfx::ShapedTextFlags();
|
2017-05-02 13:14:53 +03:00
|
|
|
DebugOnly<uint32_t> prevOffset = 0;
|
|
|
|
for (auto& run : runs) {
|
2014-09-16 15:25:45 +04:00
|
|
|
// a GlyphRun with the same font and orientation as the previous can
|
|
|
|
// just be skipped; the last GlyphRun will cover its character range.
|
2017-05-02 13:14:53 +03:00
|
|
|
MOZ_ASSERT(run.mFont != nullptr);
|
|
|
|
if (prevFont == nullptr ||
|
|
|
|
run.mFont != prevFont || run.mOrientation != prevOrient) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// If two fonts have the same character offset, Sort() will have
|
|
|
|
// randomized the order.
|
2017-05-02 13:14:53 +03:00
|
|
|
MOZ_ASSERT(prevFont == nullptr ||
|
|
|
|
run.mCharacterOffset != prevOffset,
|
|
|
|
"Two fonts for the same run, glyph indices unreliable");
|
|
|
|
prevFont = run.mFont;
|
|
|
|
prevOrient = run.mOrientation;
|
|
|
|
#ifdef DEBUG
|
|
|
|
prevOffset = run.mCharacterOffset;
|
|
|
|
#endif
|
|
|
|
if (!mGlyphRunArray.AppendElement(Move(run))) {
|
|
|
|
NS_WARNING("Failed to append glyph run!");
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mGlyphRunArray.Length() > 0);
|
|
|
|
if (mGlyphRunArray.Length() == 1) {
|
|
|
|
ConvertFromGlyphRunArray();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note that SanitizeGlyphRuns scans all glyph runs in the textrun;
|
|
|
|
// therefore we only call it once, at the end of textrun construction,
|
|
|
|
// NOT incrementally as each glyph run is added (bug 680402).
|
|
|
|
void
|
|
|
|
gfxTextRun::SanitizeGlyphRuns()
|
|
|
|
{
|
2017-05-02 13:14:53 +03:00
|
|
|
if (!mHasGlyphRunArray) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mGlyphRunArray.Length() > 1);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// If any glyph run starts with ligature-continuation characters, we need to advance it
|
|
|
|
// to the first "real" character to avoid drawing partial ligature glyphs from wrong font
|
|
|
|
// (seen with U+FEFF in reftest 474417-1, as Core Text eliminates the glyph, which makes
|
|
|
|
// it appear as if a ligature has been formed)
|
2017-05-02 13:14:53 +03:00
|
|
|
int32_t i, lastRunIndex = mGlyphRunArray.Length() - 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
const CompressedGlyph *charGlyphs = mCharacterGlyphs;
|
|
|
|
for (i = lastRunIndex; i >= 0; --i) {
|
2017-05-02 13:14:53 +03:00
|
|
|
GlyphRun& run = mGlyphRunArray[i];
|
2014-09-16 13:58:12 +04:00
|
|
|
while (charGlyphs[run.mCharacterOffset].IsLigatureContinuation() &&
|
|
|
|
run.mCharacterOffset < GetLength()) {
|
|
|
|
run.mCharacterOffset++;
|
|
|
|
}
|
|
|
|
// if the run has become empty, eliminate it
|
|
|
|
if ((i < lastRunIndex &&
|
2017-05-02 13:14:53 +03:00
|
|
|
run.mCharacterOffset >= mGlyphRunArray[i+1].mCharacterOffset) ||
|
2014-09-16 13:58:12 +04:00
|
|
|
(i == lastRunIndex && run.mCharacterOffset == GetLength())) {
|
2017-05-02 13:14:53 +03:00
|
|
|
mGlyphRunArray.RemoveElementAt(i);
|
2014-09-16 13:58:12 +04:00
|
|
|
--lastRunIndex;
|
|
|
|
}
|
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mGlyphRunArray.Length() > 0);
|
|
|
|
if (mGlyphRunArray.Length() == 1) {
|
|
|
|
ConvertFromGlyphRunArray();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun::CountMissingGlyphs() const
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
uint32_t count = 0;
|
|
|
|
for (i = 0; i < GetLength(); ++i) {
|
|
|
|
if (mCharacterGlyphs[i].IsMissing()) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxTextRun::CopyGlyphDataFrom(gfxShapedWord *aShapedWord, uint32_t aOffset)
|
|
|
|
{
|
|
|
|
uint32_t wordLen = aShapedWord->GetLength();
|
|
|
|
NS_ASSERTION(aOffset + wordLen <= GetLength(),
|
|
|
|
"word overruns end of textrun!");
|
|
|
|
|
|
|
|
CompressedGlyph *charGlyphs = GetCharacterGlyphs();
|
|
|
|
const CompressedGlyph *wordGlyphs = aShapedWord->GetCharacterGlyphs();
|
|
|
|
if (aShapedWord->HasDetailedGlyphs()) {
|
|
|
|
for (uint32_t i = 0; i < wordLen; ++i, ++aOffset) {
|
|
|
|
const CompressedGlyph& g = wordGlyphs[i];
|
|
|
|
if (g.IsSimpleGlyph()) {
|
|
|
|
charGlyphs[aOffset] = g;
|
|
|
|
} else {
|
|
|
|
const DetailedGlyph *details =
|
|
|
|
g.GetGlyphCount() > 0 ?
|
|
|
|
aShapedWord->GetDetailedGlyphs(i) : nullptr;
|
|
|
|
SetGlyphs(aOffset, g, details);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(charGlyphs + aOffset, wordGlyphs,
|
|
|
|
wordLen * sizeof(CompressedGlyph));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxTextRun::CopyGlyphDataFrom(gfxTextRun *aSource, Range aRange, uint32_t aDest)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aRange.end <= aSource->GetLength(),
|
2014-09-16 13:58:12 +04:00
|
|
|
"Source substring out of range");
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aDest + aRange.Length() <= GetLength(),
|
2014-09-16 13:58:12 +04:00
|
|
|
"Destination substring out of range");
|
|
|
|
|
|
|
|
if (aSource->mSkipDrawing) {
|
|
|
|
mSkipDrawing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy base glyph data, and DetailedGlyph data where present
|
2016-03-08 10:56:18 +03:00
|
|
|
const CompressedGlyph *srcGlyphs = aSource->mCharacterGlyphs + aRange.start;
|
2014-09-16 13:58:12 +04:00
|
|
|
CompressedGlyph *dstGlyphs = mCharacterGlyphs + aDest;
|
2016-03-08 10:56:18 +03:00
|
|
|
for (uint32_t i = 0; i < aRange.Length(); ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
CompressedGlyph g = srcGlyphs[i];
|
|
|
|
g.SetCanBreakBefore(!g.IsClusterStart() ?
|
|
|
|
CompressedGlyph::FLAG_BREAK_TYPE_NONE :
|
|
|
|
dstGlyphs[i].CanBreakBefore());
|
|
|
|
if (!g.IsSimpleGlyph()) {
|
|
|
|
uint32_t count = g.GetGlyphCount();
|
|
|
|
if (count > 0) {
|
|
|
|
DetailedGlyph *dst = AllocateDetailedGlyphs(i + aDest, count);
|
|
|
|
if (dst) {
|
2016-03-08 10:56:18 +03:00
|
|
|
DetailedGlyph *src =
|
|
|
|
aSource->GetDetailedGlyphs(i + aRange.start);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (src) {
|
|
|
|
::memcpy(dst, src, count * sizeof(DetailedGlyph));
|
|
|
|
} else {
|
|
|
|
g.SetMissing(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g.SetMissing(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dstGlyphs[i] = g;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy glyph runs
|
2016-03-08 10:56:18 +03:00
|
|
|
GlyphRunIterator iter(aSource, aRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
#ifdef DEBUG
|
2016-06-27 19:41:55 +03:00
|
|
|
const GlyphRun *prevRun = nullptr;
|
2014-09-16 13:58:12 +04:00
|
|
|
#endif
|
|
|
|
while (iter.NextRun()) {
|
|
|
|
gfxFont *font = iter.GetGlyphRun()->mFont;
|
2015-03-23 14:43:38 +03:00
|
|
|
NS_ASSERTION(!prevRun || prevRun->mFont != iter.GetGlyphRun()->mFont ||
|
|
|
|
prevRun->mMatchType != iter.GetGlyphRun()->mMatchType ||
|
|
|
|
prevRun->mOrientation != iter.GetGlyphRun()->mOrientation,
|
|
|
|
"Glyphruns not coalesced?");
|
2014-09-16 13:58:12 +04:00
|
|
|
#ifdef DEBUG
|
2015-03-23 14:43:38 +03:00
|
|
|
prevRun = iter.GetGlyphRun();
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t end = iter.GetStringEnd();
|
|
|
|
#endif
|
|
|
|
uint32_t start = iter.GetStringStart();
|
|
|
|
|
|
|
|
// These used to be NS_ASSERTION()s, but WARNING is more appropriate.
|
|
|
|
// Although it's unusual (and not desirable), it's possible for us to assign
|
|
|
|
// different fonts to a base character and a following diacritic.
|
|
|
|
// Example on OSX 10.5/10.6 with default fonts installed:
|
|
|
|
// data:text/html,<p style="font-family:helvetica, arial, sans-serif;">
|
|
|
|
// &%23x043E;&%23x0486;&%23x20;&%23x043E;&%23x0486;
|
|
|
|
// This means the rendering of the cluster will probably not be very good,
|
|
|
|
// but it's the best we can do for now if the specified font only covered the
|
|
|
|
// initial base character and not its applied marks.
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
aSource->IsClusterStart(start),
|
|
|
|
"Started font run in the middle of a cluster");
|
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
end == aSource->GetLength() || aSource->IsClusterStart(end),
|
|
|
|
"Ended font run in the middle of a cluster");
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
nsresult rv = AddGlyphRun(font, iter.GetGlyphRun()->mMatchType,
|
2016-03-08 10:56:18 +03:00
|
|
|
start - aRange.start + aDest, false,
|
2014-09-16 15:25:45 +04:00
|
|
|
iter.GetGlyphRun()->mOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxTextRun::ClearGlyphsAndCharacters()
|
|
|
|
{
|
|
|
|
ResetGlyphRuns();
|
|
|
|
memset(reinterpret_cast<char*>(mCharacterGlyphs), 0,
|
|
|
|
mLength * sizeof(CompressedGlyph));
|
|
|
|
mDetailedGlyphs = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxTextRun::SetSpaceGlyph(gfxFont* aFont, DrawTarget* aDrawTarget,
|
2017-05-05 00:27:05 +03:00
|
|
|
uint32_t aCharIndex,
|
|
|
|
gfx::ShapedTextFlags aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2015-12-07 01:13:25 +03:00
|
|
|
if (SetSpaceGlyphIfSimple(aFont, aCharIndex, ' ', aOrientation)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aFont->InitWordCache();
|
|
|
|
static const uint8_t space = ' ';
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags
|
|
|
|
flags = gfx::ShapedTextFlags::TEXT_IS_8BIT |
|
|
|
|
gfx::ShapedTextFlags::TEXT_IS_PERSISTENT |
|
|
|
|
aOrientation;
|
2014-10-01 23:25:48 +04:00
|
|
|
bool vertical =
|
2017-05-05 00:27:05 +03:00
|
|
|
!!(GetFlags() & gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT);
|
2017-04-03 19:49:17 +03:00
|
|
|
gfxFontShaper::RoundingFlags roundingFlags =
|
|
|
|
aFont->GetRoundOffsetsToPixels(aDrawTarget);
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxShapedWord* sw = aFont->GetShapedWord(aDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
&space, 1,
|
2017-01-04 18:55:16 +03:00
|
|
|
gfxShapedWord::HashMix(0, ' '),
|
2016-04-21 20:58:59 +03:00
|
|
|
Script::LATIN,
|
2014-10-01 23:25:48 +04:00
|
|
|
vertical,
|
2014-09-16 13:58:12 +04:00
|
|
|
mAppUnitsPerDevUnit,
|
2014-09-16 15:25:45 +04:00
|
|
|
flags,
|
2017-04-03 19:49:17 +03:00
|
|
|
roundingFlags,
|
2014-09-16 13:58:12 +04:00
|
|
|
nullptr);
|
|
|
|
if (sw) {
|
2014-09-16 15:25:45 +04:00
|
|
|
AddGlyphRun(aFont, gfxTextRange::kFontGroup, aCharIndex, false,
|
|
|
|
aOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
CopyGlyphDataFrom(sw, aCharIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-12-07 01:13:25 +03:00
|
|
|
gfxTextRun::SetSpaceGlyphIfSimple(gfxFont* aFont, uint32_t aCharIndex,
|
2017-05-05 00:27:05 +03:00
|
|
|
char16_t aSpaceChar,
|
|
|
|
gfx::ShapedTextFlags aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
uint32_t spaceGlyph = aFont->GetSpaceGlyph();
|
|
|
|
if (!spaceGlyph || !CompressedGlyph::IsSimpleGlyphID(spaceGlyph)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-30 10:38:26 +04:00
|
|
|
gfxFont::Orientation fontOrientation =
|
2017-05-05 00:27:05 +03:00
|
|
|
(aOrientation & gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT) ?
|
2014-09-30 10:38:26 +04:00
|
|
|
gfxFont::eVertical : gfxFont::eHorizontal;
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t spaceWidthAppUnits =
|
2014-09-30 10:38:26 +04:00
|
|
|
NS_lroundf(aFont->GetMetrics(fontOrientation).spaceWidth *
|
|
|
|
mAppUnitsPerDevUnit);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!CompressedGlyph::IsSimpleAdvance(spaceWidthAppUnits)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-16 15:25:45 +04:00
|
|
|
AddGlyphRun(aFont, gfxTextRange::kFontGroup, aCharIndex, false,
|
|
|
|
aOrientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
CompressedGlyph g;
|
|
|
|
g.SetSimpleGlyph(spaceWidthAppUnits, spaceGlyph);
|
|
|
|
if (aSpaceChar == ' ') {
|
|
|
|
g.SetIsSpace();
|
|
|
|
}
|
|
|
|
GetCharacterGlyphs()[aCharIndex] = g;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxTextRun::FetchGlyphExtents(DrawTarget* aRefDrawTarget)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
bool needsGlyphExtents = NeedsGlyphExtents(this);
|
|
|
|
if (!needsGlyphExtents && !mDetailedGlyphs)
|
|
|
|
return;
|
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
uint32_t runCount;
|
|
|
|
const GlyphRun* glyphRuns = GetGlyphRuns(&runCount);
|
2014-09-16 13:58:12 +04:00
|
|
|
CompressedGlyph *charGlyphs = mCharacterGlyphs;
|
2017-05-02 13:14:53 +03:00
|
|
|
for (uint32_t i = 0; i < runCount; ++i) {
|
|
|
|
const GlyphRun& run = glyphRuns[i];
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont *font = run.mFont;
|
2015-04-21 09:10:40 +03:00
|
|
|
if (MOZ_UNLIKELY(font->GetStyle()->size == 0) ||
|
|
|
|
MOZ_UNLIKELY(font->GetStyle()->sizeAdjust == 0.0f)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t start = run.mCharacterOffset;
|
|
|
|
uint32_t end = i + 1 < runCount ?
|
2017-05-02 13:14:53 +03:00
|
|
|
glyphRuns[i + 1].mCharacterOffset : GetLength();
|
2014-09-16 13:58:12 +04:00
|
|
|
bool fontIsSetup = false;
|
|
|
|
uint32_t j;
|
|
|
|
gfxGlyphExtents *extents = font->GetOrCreateGlyphExtents(mAppUnitsPerDevUnit);
|
2017-01-04 18:55:16 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
for (j = start; j < end; ++j) {
|
|
|
|
const gfxTextRun::CompressedGlyph *glyphData = &charGlyphs[j];
|
|
|
|
if (glyphData->IsSimpleGlyph()) {
|
|
|
|
// If we're in speed mode, don't set up glyph extents here; we'll
|
|
|
|
// just return "optimistic" glyph bounds later
|
|
|
|
if (needsGlyphExtents) {
|
|
|
|
uint32_t glyphIndex = glyphData->GetSimpleGlyph();
|
|
|
|
if (!extents->IsGlyphKnown(glyphIndex)) {
|
|
|
|
if (!fontIsSetup) {
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!font->SetupCairoFont(aRefDrawTarget)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
NS_WARNING("failed to set up font for glyph extents");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fontIsSetup = true;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
++gGlyphExtentsSetupEagerSimple;
|
|
|
|
#endif
|
2015-12-16 00:56:41 +03:00
|
|
|
font->SetupGlyphExtents(aRefDrawTarget,
|
2014-09-30 10:38:26 +04:00
|
|
|
glyphIndex, false, extents);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!glyphData->IsMissing()) {
|
|
|
|
uint32_t glyphCount = glyphData->GetGlyphCount();
|
|
|
|
if (glyphCount == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const gfxTextRun::DetailedGlyph *details = GetDetailedGlyphs(j);
|
|
|
|
if (!details) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (uint32_t k = 0; k < glyphCount; ++k, ++details) {
|
|
|
|
uint32_t glyphIndex = details->mGlyphID;
|
|
|
|
if (!extents->IsGlyphKnownWithTightExtents(glyphIndex)) {
|
|
|
|
if (!fontIsSetup) {
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!font->SetupCairoFont(aRefDrawTarget)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
NS_WARNING("failed to set up font for glyph extents");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fontIsSetup = true;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_TEXT_RUN_STORAGE_METRICS
|
|
|
|
++gGlyphExtentsSetupEagerTight;
|
|
|
|
#endif
|
2015-12-16 00:56:41 +03:00
|
|
|
font->SetupGlyphExtents(aRefDrawTarget,
|
2014-09-30 10:38:26 +04:00
|
|
|
glyphIndex, true, extents);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
gfxTextRun::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
|
|
|
|
{
|
|
|
|
// The second arg is how much gfxTextRun::AllocateStorage would have
|
|
|
|
// allocated.
|
2017-05-02 13:14:53 +03:00
|
|
|
size_t total = mHasGlyphRunArray
|
|
|
|
? mGlyphRunArray.ShallowSizeOfExcludingThis(aMallocSizeOf)
|
|
|
|
: 0;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
if (mDetailedGlyphs) {
|
|
|
|
total += mDetailedGlyphs->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
gfxTextRun::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
gfxTextRun::Dump(FILE* aOutput) {
|
|
|
|
if (!aOutput) {
|
|
|
|
aOutput = stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('[', aOutput);
|
2017-05-02 13:14:53 +03:00
|
|
|
uint32_t numGlyphRuns;
|
|
|
|
const GlyphRun* glyphRuns = GetGlyphRuns(&numGlyphRuns);
|
|
|
|
for (uint32_t i = 0; i < numGlyphRuns; ++i) {
|
2014-09-16 13:58:12 +04:00
|
|
|
if (i > 0) {
|
|
|
|
fputc(',', aOutput);
|
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
gfxFont* font = glyphRuns[i].mFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
const gfxFontStyle* style = font->GetStyle();
|
|
|
|
NS_ConvertUTF16toUTF8 fontName(font->GetName());
|
|
|
|
nsAutoCString lang;
|
|
|
|
style->language->ToUTF8String(lang);
|
2017-05-02 13:14:53 +03:00
|
|
|
fprintf(aOutput, "%d: %s %f/%d/%d/%s", glyphRuns[i].mCharacterOffset,
|
2014-09-16 13:58:12 +04:00
|
|
|
fontName.get(), style->size,
|
|
|
|
style->weight, style->style, lang.get());
|
|
|
|
}
|
|
|
|
fputc(']', aOutput);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gfxFontGroup::gfxFontGroup(const FontFamilyList& aFontFamilyList,
|
|
|
|
const gfxFontStyle *aStyle,
|
2015-09-11 07:24:33 +03:00
|
|
|
gfxTextPerfMetrics* aTextPerf,
|
2015-11-20 16:01:12 +03:00
|
|
|
gfxUserFontSet *aUserFontSet,
|
|
|
|
gfxFloat aDevToCssSize)
|
2014-09-16 13:58:12 +04:00
|
|
|
: mFamilyList(aFontFamilyList)
|
|
|
|
, mStyle(*aStyle)
|
|
|
|
, mUnderlineOffset(UNDERLINE_OFFSET_NOT_SET)
|
|
|
|
, mHyphenWidth(-1)
|
2015-11-20 16:01:12 +03:00
|
|
|
, mDevToCssSize(aDevToCssSize)
|
2014-09-16 13:58:12 +04:00
|
|
|
, mUserFontSet(aUserFontSet)
|
2015-09-11 07:24:33 +03:00
|
|
|
, mTextPerf(aTextPerf)
|
2015-12-15 08:58:00 +03:00
|
|
|
, mLastPrefLang(eFontPrefLang_Western)
|
2015-09-29 04:51:28 +03:00
|
|
|
, mPageLang(gfxPlatformFontList::GetFontPrefLangFor(aStyle->language))
|
2015-12-15 08:58:00 +03:00
|
|
|
, mLastPrefFirstFont(false)
|
2014-09-16 13:58:12 +04:00
|
|
|
, mSkipDrawing(false)
|
|
|
|
{
|
|
|
|
// We don't use SetUserFontSet() here, as we want to unconditionally call
|
2014-09-25 07:16:54 +04:00
|
|
|
// BuildFontList() rather than only do UpdateUserFonts() if it changed.
|
2014-09-16 13:58:12 +04:00
|
|
|
mCurrGeneration = GetGeneration();
|
|
|
|
BuildFontList();
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFontGroup::~gfxFontGroup()
|
|
|
|
{
|
2017-04-08 01:49:44 +03:00
|
|
|
// Should not be dropped by stylo
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void
|
2015-09-29 04:51:28 +03:00
|
|
|
gfxFontGroup::BuildFontList()
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
// initialize fonts in the font family list
|
2016-04-12 09:06:22 +03:00
|
|
|
AutoTArray<gfxFontFamily*,10> fonts;
|
2015-09-29 04:51:28 +03:00
|
|
|
gfxPlatformFontList *pfl = gfxPlatformFontList::PlatformFontList();
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// lookup fonts in the fontlist
|
2015-09-29 04:51:29 +03:00
|
|
|
for (const FontFamilyName& name : mFamilyList.GetFontlist()) {
|
2014-09-16 13:58:12 +04:00
|
|
|
if (name.IsNamed()) {
|
2015-09-29 04:51:29 +03:00
|
|
|
AddPlatformFont(name.mName, fonts);
|
2014-09-16 13:58:12 +04:00
|
|
|
} else {
|
2015-09-29 04:51:29 +03:00
|
|
|
pfl->AddGenericFonts(name.mType, mStyle.language, fonts);
|
2015-09-29 04:51:28 +03:00
|
|
|
if (mTextPerf) {
|
|
|
|
mTextPerf->current.genericLookups++;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if necessary, append default generic onto the end
|
|
|
|
if (mFamilyList.GetDefaultFontType() != eFamily_none &&
|
|
|
|
!mFamilyList.HasDefaultGeneric()) {
|
2015-09-29 04:51:29 +03:00
|
|
|
pfl->AddGenericFonts(mFamilyList.GetDefaultFontType(),
|
|
|
|
mStyle.language, fonts);
|
2015-09-29 04:51:28 +03:00
|
|
|
if (mTextPerf) {
|
|
|
|
mTextPerf->current.genericLookups++;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-09-29 04:51:28 +03:00
|
|
|
// build the fontlist from the specified families
|
2015-09-29 04:51:29 +03:00
|
|
|
for (gfxFontFamily* fontFamily : fonts) {
|
|
|
|
AddFamilyToFontList(fontFamily);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-09-29 04:51:29 +03:00
|
|
|
void
|
|
|
|
gfxFontGroup::AddPlatformFont(const nsAString& aName,
|
|
|
|
nsTArray<gfxFontFamily*>& aFamilyList)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2015-09-29 04:51:29 +03:00
|
|
|
// First, look up in the user font set...
|
|
|
|
// If the fontSet matches the family, we must not look for a platform
|
|
|
|
// font of the same name, even if we fail to actually get a fontEntry
|
|
|
|
// here; we'll fall back to the next name in the CSS font-family list.
|
|
|
|
if (mUserFontSet) {
|
|
|
|
// Add userfonts to the fontlist whether already loaded
|
|
|
|
// or not. Loading is initiated during font matching.
|
2016-04-12 09:06:22 +03:00
|
|
|
gfxFontFamily* family = mUserFontSet->LookupFamily(aName);
|
|
|
|
if (family) {
|
|
|
|
aFamilyList.AppendElement(family);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not known in the user font set ==> check system fonts
|
2016-04-12 09:06:22 +03:00
|
|
|
gfxPlatformFontList::PlatformFontList()
|
|
|
|
->FindAndAddFamilies(aName, &aFamilyList, &mStyle, mDevToCssSize);
|
2015-09-29 04:51:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFamily, "trying to add a null font family to fontlist");
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<gfxFontEntry*,4> fontEntryList;
|
2015-09-29 04:51:28 +03:00
|
|
|
bool needsBold;
|
|
|
|
aFamily->FindAllFontsForStyle(mStyle, fontEntryList, needsBold);
|
|
|
|
// add these to the fontlist
|
2015-09-29 04:51:29 +03:00
|
|
|
for (gfxFontEntry* fe : fontEntryList) {
|
2015-09-29 04:51:28 +03:00
|
|
|
if (!HasFont(fe)) {
|
|
|
|
FamilyFace ff(aFamily, fe, needsBold);
|
|
|
|
if (fe->mIsUserFontContainer) {
|
|
|
|
ff.CheckState(mSkipDrawing);
|
2015-07-02 04:44:14 +03:00
|
|
|
}
|
2015-09-29 04:51:28 +03:00
|
|
|
mFonts.AppendElement(ff);
|
2015-07-02 04:44:14 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2015-11-11 15:13:33 +03:00
|
|
|
// for a family marked as "check fallback faces", only mark the last
|
|
|
|
// entry so that fallbacks for a family are only checked once
|
|
|
|
if (aFamily->CheckForFallbackFaces() &&
|
|
|
|
!fontEntryList.IsEmpty() && !mFonts.IsEmpty()) {
|
|
|
|
mFonts.LastElement().SetCheckForFallbackFaces();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gfxFontGroup::HasFont(const gfxFontEntry *aFontEntry)
|
|
|
|
{
|
|
|
|
uint32_t count = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2014-09-25 07:16:52 +04:00
|
|
|
if (mFonts[i].FontEntry() == aFontEntry) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return true;
|
2014-09-25 07:16:52 +04:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFont*
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFontGroup::GetFontAt(int32_t i, uint32_t aCh)
|
2014-09-25 07:16:54 +04:00
|
|
|
{
|
|
|
|
if (uint32_t(i) >= mFonts.Length()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FamilyFace& ff = mFonts[i];
|
|
|
|
if (ff.IsInvalid() || ff.IsLoading()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font = ff.Font();
|
2014-09-25 07:16:54 +04:00
|
|
|
if (!font) {
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFontEntry* fe = mFonts[i].FontEntry();
|
|
|
|
gfxCharacterMap* unicodeRangeMap = nullptr;
|
2014-09-25 07:16:54 +04:00
|
|
|
if (fe->mIsUserFontContainer) {
|
|
|
|
gfxUserFontEntry* ufe = static_cast<gfxUserFontEntry*>(fe);
|
2014-11-06 07:42:50 +03:00
|
|
|
if (ufe->LoadState() == gfxUserFontEntry::STATUS_NOT_LOADED &&
|
|
|
|
ufe->CharacterInUnicodeRange(aCh) &&
|
|
|
|
!FontLoadingForFamily(ff.Family(), aCh)) {
|
2014-09-25 07:16:54 +04:00
|
|
|
ufe->Load();
|
2014-11-06 07:42:50 +03:00
|
|
|
ff.CheckState(mSkipDrawing);
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
|
|
|
fe = ufe->GetPlatformFontEntry();
|
|
|
|
if (!fe) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-11-06 07:42:50 +03:00
|
|
|
unicodeRangeMap = ufe->GetUnicodeRangeMap();
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
2014-11-06 07:42:50 +03:00
|
|
|
font = fe->FindOrMakeFont(&mStyle, mFonts[i].NeedsBold(),
|
|
|
|
unicodeRangeMap);
|
2014-12-23 13:01:11 +03:00
|
|
|
if (!font || !font->Valid()) {
|
2014-09-25 07:16:54 +04:00
|
|
|
ff.SetInvalid();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mFonts[i].SetFont(font);
|
|
|
|
}
|
|
|
|
return font.get();
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
void
|
|
|
|
gfxFontGroup::FamilyFace::CheckState(bool& aSkipDrawing)
|
|
|
|
{
|
|
|
|
gfxFontEntry* fe = FontEntry();
|
|
|
|
if (fe->mIsUserFontContainer) {
|
|
|
|
gfxUserFontEntry* ufe = static_cast<gfxUserFontEntry*>(fe);
|
|
|
|
gfxUserFontEntry::UserFontLoadState state = ufe->LoadState();
|
|
|
|
switch (state) {
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
case gfxUserFontEntry::STATUS_LOAD_PENDING:
|
2014-11-06 07:42:50 +03:00
|
|
|
case gfxUserFontEntry::STATUS_LOADING:
|
|
|
|
SetLoading(true);
|
|
|
|
break;
|
|
|
|
case gfxUserFontEntry::STATUS_FAILED:
|
|
|
|
SetInvalid();
|
|
|
|
// fall-thru to the default case
|
2015-10-17 23:28:05 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2014-11-06 07:42:50 +03:00
|
|
|
default:
|
|
|
|
SetLoading(false);
|
|
|
|
}
|
|
|
|
if (ufe->WaitForUserFont()) {
|
|
|
|
aSkipDrawing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
bool
|
|
|
|
gfxFontGroup::FamilyFace::EqualsUserFont(const gfxUserFontEntry* aUserFont) const
|
|
|
|
{
|
|
|
|
gfxFontEntry* fe = FontEntry();
|
|
|
|
// if there's a font, the entry is the underlying platform font
|
|
|
|
if (mFontCreated) {
|
|
|
|
gfxFontEntry* pfe = aUserFont->GetPlatformFontEntry();
|
|
|
|
if (pfe == fe) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (fe == aUserFont) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
bool
|
|
|
|
gfxFontGroup::FontLoadingForFamily(gfxFontFamily* aFamily, uint32_t aCh) const
|
|
|
|
{
|
|
|
|
uint32_t count = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
const FamilyFace& ff = mFonts[i];
|
|
|
|
if (ff.IsLoading() && ff.Family() == aFamily) {
|
|
|
|
const gfxUserFontEntry* ufe =
|
|
|
|
static_cast<gfxUserFontEntry*>(ff.FontEntry());
|
|
|
|
if (ufe->CharacterInUnicodeRange(aCh)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFont*
|
|
|
|
gfxFontGroup::GetDefaultFont()
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2014-09-25 07:16:54 +04:00
|
|
|
if (mDefaultFont) {
|
|
|
|
return mDefaultFont.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsBold;
|
|
|
|
gfxPlatformFontList *pfl = gfxPlatformFontList::PlatformFontList();
|
|
|
|
gfxFontFamily *defaultFamily = pfl->GetDefaultFont(&mStyle);
|
|
|
|
NS_ASSERTION(defaultFamily,
|
|
|
|
"invalid default font returned by GetDefaultFont");
|
|
|
|
|
|
|
|
if (defaultFamily) {
|
|
|
|
gfxFontEntry *fe = defaultFamily->FindFontForStyle(mStyle,
|
|
|
|
needsBold);
|
|
|
|
if (fe) {
|
|
|
|
mDefaultFont = fe->FindOrMakeFont(&mStyle, needsBold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 05:03:41 +03:00
|
|
|
uint32_t numInits, loaderState;
|
|
|
|
pfl->GetFontlistInitInfo(numInits, loaderState);
|
|
|
|
NS_ASSERTION(numInits != 0,
|
|
|
|
"must initialize system fontlist before getting default font!");
|
|
|
|
|
|
|
|
uint32_t numFonts = 0;
|
2014-09-25 07:16:54 +04:00
|
|
|
if (!mDefaultFont) {
|
|
|
|
// Try for a "font of last resort...."
|
|
|
|
// Because an empty font list would be Really Bad for later code
|
|
|
|
// that assumes it will be able to get valid metrics for layout,
|
|
|
|
// just look for the first usable font and put in the list.
|
|
|
|
// (see bug 554544)
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<gfxFontFamily>,200> familyList;
|
2015-09-12 06:30:14 +03:00
|
|
|
pfl->GetFontFamilyList(familyList);
|
|
|
|
numFonts = familyList.Length();
|
2015-08-05 05:03:41 +03:00
|
|
|
for (uint32_t i = 0; i < numFonts; ++i) {
|
2015-09-12 06:30:14 +03:00
|
|
|
gfxFontEntry *fe = familyList[i]->FindFontForStyle(mStyle,
|
|
|
|
needsBold);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (fe) {
|
|
|
|
mDefaultFont = fe->FindOrMakeFont(&mStyle, needsBold);
|
2015-07-21 21:22:25 +03:00
|
|
|
if (mDefaultFont) {
|
|
|
|
break;
|
|
|
|
}
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDefaultFont) {
|
|
|
|
// an empty font list at this point is fatal; we're not going to
|
|
|
|
// be able to do even the most basic layout operations
|
2015-08-05 05:03:41 +03:00
|
|
|
|
|
|
|
// annotate crash report with fontlist info
|
|
|
|
nsAutoCString fontInitInfo;
|
|
|
|
fontInitInfo.AppendPrintf("no fonts - init: %d fonts: %d loader: %d",
|
|
|
|
numInits, numFonts, loaderState);
|
2015-08-13 09:04:25 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
bool dwriteEnabled = gfxWindowsPlatform::GetPlatform()->DWriteEnabled();
|
|
|
|
double upTime = (double) GetTickCount();
|
|
|
|
fontInitInfo.AppendPrintf(" backend: %s system-uptime: %9.3f sec",
|
|
|
|
dwriteEnabled ? "directwrite" : "gdi", upTime/1000);
|
|
|
|
#endif
|
2015-08-05 05:03:41 +03:00
|
|
|
gfxCriticalError() << fontInitInfo.get();
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
char msg[256]; // CHECK buffer length if revising message below
|
2015-09-12 06:30:14 +03:00
|
|
|
nsAutoString familiesString;
|
|
|
|
mFamilyList.ToString(familiesString);
|
2016-08-15 09:44:00 +03:00
|
|
|
SprintfLiteral(msg, "unable to find a usable font (%.220s)",
|
|
|
|
NS_ConvertUTF16toUTF8(familiesString).get());
|
2014-09-25 07:16:54 +04:00
|
|
|
NS_RUNTIMEABORT(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDefaultFont.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFont*
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFontGroup::GetFirstValidFont(uint32_t aCh)
|
2014-09-25 07:16:54 +04:00
|
|
|
{
|
|
|
|
uint32_t count = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
FamilyFace& ff = mFonts[i];
|
|
|
|
if (ff.IsInvalid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// already have a font?
|
|
|
|
gfxFont* font = ff.Font();
|
|
|
|
if (font) {
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
// Need to build a font, loading userfont if not loaded. In
|
|
|
|
// cases where unicode range might apply, use the character
|
|
|
|
// provided.
|
|
|
|
if (ff.IsUserFontContainer()) {
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxUserFontEntry* ufe =
|
|
|
|
static_cast<gfxUserFontEntry*>(mFonts[i].FontEntry());
|
2014-11-06 07:42:50 +03:00
|
|
|
bool inRange = ufe->CharacterInUnicodeRange(aCh);
|
|
|
|
if (ufe->LoadState() == gfxUserFontEntry::STATUS_NOT_LOADED &&
|
|
|
|
inRange && !FontLoadingForFamily(ff.Family(), aCh)) {
|
2014-09-25 07:16:54 +04:00
|
|
|
ufe->Load();
|
2014-11-06 07:42:50 +03:00
|
|
|
ff.CheckState(mSkipDrawing);
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
2014-11-06 07:42:50 +03:00
|
|
|
if (ufe->LoadState() != gfxUserFontEntry::STATUS_LOADED ||
|
|
|
|
!inRange) {
|
2014-09-25 07:16:54 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
font = GetFontAt(i, aCh);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (font) {
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GetDefaultFont();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFont *
|
|
|
|
gfxFontGroup::GetFirstMathFont()
|
|
|
|
{
|
|
|
|
uint32_t count = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
gfxFont* font = GetFontAt(i);
|
2016-11-02 21:47:18 +03:00
|
|
|
if (font && font->TryGetMathTable()) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return font;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontGroup *
|
|
|
|
gfxFontGroup::Copy(const gfxFontStyle *aStyle)
|
|
|
|
{
|
2015-09-11 07:24:33 +03:00
|
|
|
gfxFontGroup *fg =
|
2015-11-20 16:01:12 +03:00
|
|
|
new gfxFontGroup(mFamilyList, aStyle, mTextPerf,
|
|
|
|
mUserFontSet, mDevToCssSize);
|
2014-09-16 13:58:12 +04:00
|
|
|
return fg;
|
|
|
|
}
|
|
|
|
|
2017-01-04 18:55:16 +03:00
|
|
|
bool
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::IsInvalidChar(uint8_t ch)
|
|
|
|
{
|
|
|
|
return ((ch & 0x7f) < 0x20 || ch == 0x7f);
|
|
|
|
}
|
|
|
|
|
2017-01-04 18:55:16 +03:00
|
|
|
bool
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::IsInvalidChar(char16_t ch)
|
|
|
|
{
|
|
|
|
// All printable 7-bit ASCII values are OK
|
|
|
|
if (ch >= ' ' && ch < 0x7f) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// No point in sending non-printing control chars through font shaping
|
|
|
|
if (ch <= 0x9f) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return (((ch & 0xFF00) == 0x2000 /* Unicode control character */ &&
|
|
|
|
(ch == 0x200B/*ZWSP*/ || ch == 0x2028/*LSEP*/ || ch == 0x2029/*PSEP*/)) ||
|
|
|
|
IsBidiControl(ch));
|
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxFontGroup::MakeEmptyTextRun(const Parameters *aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-05-05 00:27:05 +03:00
|
|
|
aFlags |= ShapedTextFlags::TEXT_IS_8BIT | ShapedTextFlags::TEXT_IS_PERSISTENT;
|
2017-05-05 00:25:16 +03:00
|
|
|
return gfxTextRun::Create(aParams, 0, this, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxFontGroup::MakeSpaceTextRun(const Parameters *aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-05-05 00:27:05 +03:00
|
|
|
aFlags |= ShapedTextFlags::TEXT_IS_8BIT | ShapedTextFlags::TEXT_IS_PERSISTENT;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun =
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxTextRun::Create(aParams, 1, this, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!textRun) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags orientation = aFlags & ShapedTextFlags::TEXT_ORIENT_MASK;
|
|
|
|
if (orientation == ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED) {
|
|
|
|
orientation = ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxFont *font = GetFirstValidFont();
|
2015-04-21 09:10:40 +03:00
|
|
|
if (MOZ_UNLIKELY(GetStyle()->size == 0) ||
|
|
|
|
MOZ_UNLIKELY(GetStyle()->sizeAdjust == 0.0f)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
|
|
|
|
// them, and always create at least size 1 fonts, i.e. they still
|
|
|
|
// render something for size 0 fonts.
|
2014-09-16 15:25:45 +04:00
|
|
|
textRun->AddGlyphRun(font, gfxTextRange::kFontGroup, 0, false,
|
|
|
|
orientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (font->GetSpaceGlyph()) {
|
|
|
|
// Normally, the font has a cached space glyph, so we can avoid
|
|
|
|
// the cost of calling FindFontForChar.
|
2015-12-16 00:56:41 +03:00
|
|
|
textRun->SetSpaceGlyph(font, aParams->mDrawTarget, 0, orientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
} else {
|
|
|
|
// In case the primary font doesn't have <space> (bug 970891),
|
|
|
|
// find one that does.
|
|
|
|
uint8_t matchType;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> spaceFont =
|
2016-04-21 20:58:59 +03:00
|
|
|
FindFontForChar(' ', 0, 0, Script::LATIN, nullptr,
|
2014-09-30 10:27:55 +04:00
|
|
|
&matchType);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (spaceFont) {
|
2015-12-16 00:56:41 +03:00
|
|
|
textRun->SetSpaceGlyph(spaceFont, aParams->mDrawTarget, 0,
|
2014-09-16 15:25:45 +04:00
|
|
|
orientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that the gfxGlyphExtents glyph bounds storage for the font will
|
|
|
|
// always contain an entry for the font's space glyph, so we don't have
|
|
|
|
// to call FetchGlyphExtents here.
|
2016-08-19 15:14:22 +03:00
|
|
|
return textRun.forget();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::MakeBlankTextRun(uint32_t aLength,
|
2017-05-05 00:25:16 +03:00
|
|
|
const Parameters *aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun =
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxTextRun::Create(aParams, aLength, this, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!textRun) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags orientation = aFlags & ShapedTextFlags::TEXT_ORIENT_MASK;
|
|
|
|
if (orientation == ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED) {
|
|
|
|
orientation = ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
}
|
2014-09-25 07:16:53 +04:00
|
|
|
textRun->AddGlyphRun(GetFirstValidFont(), gfxTextRange::kFontGroup, 0, false,
|
2014-09-16 15:25:45 +04:00
|
|
|
orientation);
|
2016-08-19 15:14:22 +03:00
|
|
|
return textRun.forget();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFontGroup::MakeHyphenTextRun(DrawTarget* aDrawTarget,
|
|
|
|
uint32_t aAppUnitsPerDevUnit)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
// only use U+2010 if it is supported by the first font in the group;
|
|
|
|
// it's better to use ASCII '-' from the primary font than to fall back to
|
|
|
|
// U+2010 from some other, possibly poorly-matching face
|
|
|
|
static const char16_t hyphen = 0x2010;
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFont *font = GetFirstValidFont(uint32_t(hyphen));
|
2014-09-25 07:16:53 +04:00
|
|
|
if (font->HasCharacter(hyphen)) {
|
2015-12-16 00:56:41 +03:00
|
|
|
return MakeTextRun(&hyphen, 1, aDrawTarget, aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
ShapedTextFlags::TEXT_IS_PERSISTENT,
|
|
|
|
nsTextFrameUtils::Flags(), nullptr);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const uint8_t dash = '-';
|
2015-12-16 00:56:41 +03:00
|
|
|
return MakeTextRun(&dash, 1, aDrawTarget, aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
ShapedTextFlags::TEXT_IS_PERSISTENT,
|
|
|
|
nsTextFrameUtils::Flags(), nullptr);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
2017-03-17 13:53:15 +03:00
|
|
|
gfxFontGroup::GetHyphenWidth(const gfxTextRun::PropertyProvider* aProvider)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
if (mHyphenWidth < 0) {
|
2015-12-16 00:56:41 +03:00
|
|
|
RefPtr<DrawTarget> dt(aProvider->GetDrawTarget());
|
|
|
|
if (dt) {
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun>
|
2015-12-16 00:56:41 +03:00
|
|
|
hyphRun(MakeHyphenTextRun(dt,
|
2014-09-16 13:58:12 +04:00
|
|
|
aProvider->GetAppUnitsPerDevUnit()));
|
2016-03-08 10:56:18 +03:00
|
|
|
mHyphenWidth = hyphRun.get() ? hyphRun->GetAdvanceWidth() : 0;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mHyphenWidth;
|
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::MakeTextRun(const uint8_t *aString, uint32_t aLength,
|
2017-05-05 00:25:16 +03:00
|
|
|
const Parameters *aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder *aMFR)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
if (aLength == 0) {
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeEmptyTextRun(aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
if (aLength == 1 && aString[0] == ' ') {
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeSpaceTextRun(aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
aFlags |= ShapedTextFlags::TEXT_IS_8BIT;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2015-04-21 09:10:40 +03:00
|
|
|
if (MOZ_UNLIKELY(GetStyle()->size == 0) ||
|
|
|
|
MOZ_UNLIKELY(GetStyle()->sizeAdjust == 0.0f)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
|
|
|
|
// them, and always create at least size 1 fonts, i.e. they still
|
|
|
|
// render something for size 0 fonts.
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeBlankTextRun(aLength, aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun = gfxTextRun::Create(aParams, aLength, this,
|
2017-05-05 00:25:16 +03:00
|
|
|
aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!textRun) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-19 19:13:28 +03:00
|
|
|
InitTextRun(aParams->mDrawTarget, textRun.get(), aString, aLength, aMFR);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
textRun->FetchGlyphExtents(aParams->mDrawTarget);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
return textRun.forget();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun>
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::MakeTextRun(const char16_t *aString, uint32_t aLength,
|
2017-05-05 00:25:16 +03:00
|
|
|
const Parameters *aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder *aMFR)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
if (aLength == 0) {
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeEmptyTextRun(aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
if (aLength == 1 && aString[0] == ' ') {
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeSpaceTextRun(aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2015-04-21 09:10:40 +03:00
|
|
|
if (MOZ_UNLIKELY(GetStyle()->size == 0) ||
|
|
|
|
MOZ_UNLIKELY(GetStyle()->sizeAdjust == 0.0f)) {
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeBlankTextRun(aLength, aParams, aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> textRun = gfxTextRun::Create(aParams, aLength, this,
|
2017-05-05 00:25:16 +03:00
|
|
|
aFlags, aFlags2);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!textRun) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-19 19:13:28 +03:00
|
|
|
InitTextRun(aParams->mDrawTarget, textRun.get(), aString, aLength, aMFR);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
textRun->FetchGlyphExtents(aParams->mDrawTarget);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
return textRun.forget();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const T *aString,
|
2014-12-22 19:35:54 +03:00
|
|
|
uint32_t aLength,
|
|
|
|
gfxMissingFontRecorder *aMFR)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aLength > 0, "don't call InitTextRun for a zero-length run");
|
|
|
|
|
|
|
|
// we need to do numeral processing even on 8-bit text,
|
|
|
|
// in case we're converting Western to Hindi/Arabic digits
|
|
|
|
int32_t numOption = gfxPlatform::GetPlatform()->GetBidiNumeralOption();
|
2015-10-20 20:13:35 +03:00
|
|
|
UniquePtr<char16_t[]> transformedString;
|
2014-09-16 13:58:12 +04:00
|
|
|
if (numOption != IBMBIDI_NUMERAL_NOMINAL) {
|
|
|
|
// scan the string for numerals that may need to be transformed;
|
|
|
|
// if we find any, we'll make a local copy here and use that for
|
|
|
|
// font matching and glyph generation/shaping
|
|
|
|
bool prevIsArabic =
|
2017-05-05 00:27:05 +03:00
|
|
|
!!(aTextRun->GetFlags() & ShapedTextFlags::TEXT_INCOMING_ARABICCHAR);
|
2014-09-16 13:58:12 +04:00
|
|
|
for (uint32_t i = 0; i < aLength; ++i) {
|
|
|
|
char16_t origCh = aString[i];
|
|
|
|
char16_t newCh = HandleNumberInChar(origCh, prevIsArabic, numOption);
|
|
|
|
if (newCh != origCh) {
|
|
|
|
if (!transformedString) {
|
2015-10-20 20:13:35 +03:00
|
|
|
transformedString = MakeUnique<char16_t[]>(aLength);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (sizeof(T) == sizeof(char16_t)) {
|
|
|
|
memcpy(transformedString.get(), aString, i * sizeof(char16_t));
|
|
|
|
} else {
|
|
|
|
for (uint32_t j = 0; j < i; ++j) {
|
|
|
|
transformedString[j] = aString[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (transformedString) {
|
|
|
|
transformedString[i] = newCh;
|
|
|
|
}
|
|
|
|
prevIsArabic = IS_ARABIC_CHAR(newCh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 01:58:24 +03:00
|
|
|
LogModule* log = mStyle.systemFont
|
|
|
|
? gfxPlatform::GetLog(eGfxLog_textrunui)
|
|
|
|
: gfxPlatform::GetLog(eGfxLog_textrun);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// variant fallback handling may end up passing through this twice
|
|
|
|
bool redo;
|
|
|
|
do {
|
|
|
|
redo = false;
|
|
|
|
|
|
|
|
if (sizeof(T) == sizeof(uint8_t) && !transformedString) {
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
|
2014-09-16 13:58:12 +04:00
|
|
|
nsAutoCString lang;
|
|
|
|
mStyle.language->ToUTF8String(lang);
|
|
|
|
nsAutoString families;
|
|
|
|
mFamilyList.ToString(families);
|
|
|
|
nsAutoCString str((const char*)aString, aLength);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(log, LogLevel::Warning,\
|
2014-09-16 13:58:12 +04:00
|
|
|
("(%s) fontgroup: [%s] default: %s lang: %s script: %d "
|
2016-12-16 06:16:31 +03:00
|
|
|
"len %d weight: %d width: %d style: %s size: %6.2f %" PRIuSIZE "-byte "
|
2014-09-16 13:58:12 +04:00
|
|
|
"TEXTRUN [%s] ENDTEXTRUN\n",
|
|
|
|
(mStyle.systemFont ? "textrunui" : "textrun"),
|
|
|
|
NS_ConvertUTF16toUTF8(families).get(),
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_serif ?
|
|
|
|
"serif" :
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_sans_serif ?
|
|
|
|
"sans-serif" : "none")),
|
2016-12-16 06:16:31 +03:00
|
|
|
lang.get(), static_cast<int>(Script::LATIN), aLength,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t(mStyle.weight), uint32_t(mStyle.stretch),
|
|
|
|
(mStyle.style & NS_FONT_STYLE_ITALIC ? "italic" :
|
|
|
|
(mStyle.style & NS_FONT_STYLE_OBLIQUE ? "oblique" :
|
|
|
|
"normal")),
|
|
|
|
mStyle.size,
|
|
|
|
sizeof(T),
|
|
|
|
str.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// the text is still purely 8-bit; bypass the script-run itemizer
|
|
|
|
// and treat it as a single Latin run
|
2015-12-16 00:56:41 +03:00
|
|
|
InitScriptRun(aDrawTarget, aTextRun, aString,
|
2016-04-21 20:58:59 +03:00
|
|
|
0, aLength, Script::LATIN, aMFR);
|
2014-09-16 13:58:12 +04:00
|
|
|
} else {
|
|
|
|
const char16_t *textPtr;
|
|
|
|
if (transformedString) {
|
|
|
|
textPtr = transformedString.get();
|
|
|
|
} else {
|
|
|
|
// typecast to avoid compilation error for the 8-bit version,
|
|
|
|
// even though this is dead code in that case
|
|
|
|
textPtr = reinterpret_cast<const char16_t*>(aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
// split into script runs so that script can potentially influence
|
|
|
|
// the font matching process below
|
|
|
|
gfxScriptItemizer scriptRuns(textPtr, aLength);
|
|
|
|
|
|
|
|
uint32_t runStart = 0, runLimit = aLength;
|
2016-04-21 20:58:59 +03:00
|
|
|
Script runScript = Script::LATIN;
|
2014-09-16 13:58:12 +04:00
|
|
|
while (scriptRuns.Next(runStart, runLimit, runScript)) {
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
|
2014-09-16 13:58:12 +04:00
|
|
|
nsAutoCString lang;
|
|
|
|
mStyle.language->ToUTF8String(lang);
|
|
|
|
nsAutoString families;
|
|
|
|
mFamilyList.ToString(families);
|
|
|
|
uint32_t runLen = runLimit - runStart;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(log, LogLevel::Warning,\
|
2014-09-16 13:58:12 +04:00
|
|
|
("(%s) fontgroup: [%s] default: %s lang: %s script: %d "
|
|
|
|
"len %d weight: %d width: %d style: %s size: %6.2f "
|
2016-12-16 06:16:31 +03:00
|
|
|
"%" PRIuSIZE "-byte TEXTRUN [%s] ENDTEXTRUN\n",
|
2014-09-16 13:58:12 +04:00
|
|
|
(mStyle.systemFont ? "textrunui" : "textrun"),
|
|
|
|
NS_ConvertUTF16toUTF8(families).get(),
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_serif ?
|
|
|
|
"serif" :
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_sans_serif ?
|
|
|
|
"sans-serif" : "none")),
|
2016-12-16 06:16:31 +03:00
|
|
|
lang.get(), static_cast<int>(runScript), runLen,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t(mStyle.weight), uint32_t(mStyle.stretch),
|
|
|
|
(mStyle.style & NS_FONT_STYLE_ITALIC ? "italic" :
|
|
|
|
(mStyle.style & NS_FONT_STYLE_OBLIQUE ? "oblique" :
|
|
|
|
"normal")),
|
|
|
|
mStyle.size,
|
|
|
|
sizeof(T),
|
|
|
|
NS_ConvertUTF16toUTF8(textPtr + runStart, runLen).get()));
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
InitScriptRun(aDrawTarget, aTextRun, textPtr + runStart,
|
2014-12-22 19:35:54 +03:00
|
|
|
runStart, runLimit - runStart, runScript, aMFR);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if shaping was aborted due to lack of feature support, clear out
|
|
|
|
// glyph runs and redo shaping with fallback forced on
|
|
|
|
if (aTextRun->GetShapingState() == gfxTextRun::eShapingState_Aborted) {
|
|
|
|
redo = true;
|
|
|
|
aTextRun->SetShapingState(
|
|
|
|
gfxTextRun::eShapingState_ForceFallbackFeature);
|
|
|
|
aTextRun->ClearGlyphsAndCharacters();
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (redo);
|
|
|
|
|
|
|
|
if (sizeof(T) == sizeof(char16_t) && aLength > 0) {
|
|
|
|
gfxTextRun::CompressedGlyph *glyph = aTextRun->GetCharacterGlyphs();
|
|
|
|
if (!glyph->IsSimpleGlyph()) {
|
|
|
|
glyph->SetClusterStart(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's possible for CoreText to omit glyph runs if it decides they contain
|
|
|
|
// only invisibles (e.g., U+FEFF, see reftest 474417-1). In this case, we
|
|
|
|
// need to eliminate them from the glyph run array to avoid drawing "partial
|
|
|
|
// ligatures" with the wrong font.
|
|
|
|
// We don't do this during InitScriptRun (or gfxFont::InitTextRun) because
|
|
|
|
// it will iterate back over all glyphruns in the textrun, which leads to
|
|
|
|
// pathologically-bad perf in the case where a textrun contains many script
|
|
|
|
// changes (see bug 680402) - we'd end up re-sanitizing all the earlier runs
|
|
|
|
// every time a new script subrun is processed.
|
|
|
|
aTextRun->SanitizeGlyphRuns();
|
|
|
|
|
|
|
|
aTextRun->SortGlyphRuns();
|
|
|
|
}
|
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
static inline bool
|
|
|
|
IsPUA(uint32_t aUSV)
|
|
|
|
{
|
|
|
|
// We could look up the General Category of the codepoint here,
|
|
|
|
// but it's simpler to check PUA codepoint ranges.
|
|
|
|
return (aUSV >= 0xE000 && aUSV <= 0xF8FF) || (aUSV >= 0xF0000);
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
template<typename T>
|
|
|
|
void
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const T *aString, // text for this script run,
|
|
|
|
// not the entire textrun
|
|
|
|
uint32_t aOffset, // position of the script run
|
|
|
|
// within the textrun
|
|
|
|
uint32_t aLength, // length of the script run
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aRunScript,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder *aMFR)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aLength > 0, "don't call InitScriptRun for a 0-length run");
|
|
|
|
NS_ASSERTION(aTextRun->GetShapingState() != gfxTextRun::eShapingState_Aborted,
|
|
|
|
"don't call InitScriptRun with aborted shaping state");
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// confirm the load state of userfonts in the list
|
2017-03-22 19:00:02 +03:00
|
|
|
if (mUserFontSet &&
|
2015-05-13 08:11:25 +03:00
|
|
|
mCurrGeneration != mUserFontSet->GetGeneration()) {
|
2014-09-25 07:16:54 +04:00
|
|
|
UpdateUserFonts();
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxFont *mainFont = GetFirstValidFont();
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
uint32_t runStart = 0;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<gfxTextRange,3> fontRanges;
|
2014-09-16 15:25:45 +04:00
|
|
|
ComputeRanges(fontRanges, aString, aLength, aRunScript,
|
2017-05-05 00:27:05 +03:00
|
|
|
aTextRun->GetFlags() & ShapedTextFlags::TEXT_ORIENT_MASK);
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t numRanges = fontRanges.Length();
|
2014-12-22 19:35:54 +03:00
|
|
|
bool missingChars = false;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
for (uint32_t r = 0; r < numRanges; r++) {
|
|
|
|
const gfxTextRange& range = fontRanges[r];
|
|
|
|
uint32_t matchedLength = range.Length();
|
|
|
|
gfxFont *matchedFont = range.font;
|
2014-10-01 23:25:48 +04:00
|
|
|
bool vertical =
|
2017-05-05 00:27:05 +03:00
|
|
|
range.orientation == ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
2014-09-16 13:58:12 +04:00
|
|
|
// create the glyph run for this range
|
|
|
|
if (matchedFont && mStyle.noFallbackVariantFeatures) {
|
|
|
|
// common case - just do glyph layout and record the
|
|
|
|
// resulting positioned glyphs
|
|
|
|
aTextRun->AddGlyphRun(matchedFont, range.matchType,
|
2014-09-16 15:25:45 +04:00
|
|
|
aOffset + runStart, (matchedLength > 0),
|
|
|
|
range.orientation);
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!matchedFont->SplitAndInitTextRun(aDrawTarget, aTextRun,
|
2014-09-16 13:58:12 +04:00
|
|
|
aString + runStart,
|
|
|
|
aOffset + runStart,
|
|
|
|
matchedLength,
|
2014-10-01 23:25:48 +04:00
|
|
|
aRunScript,
|
|
|
|
vertical)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// glyph layout failed! treat as missing glyphs
|
|
|
|
matchedFont = nullptr;
|
|
|
|
}
|
|
|
|
} else if (matchedFont) {
|
|
|
|
// shape with some variant feature that requires fallback handling
|
|
|
|
bool petiteToSmallCaps = false;
|
|
|
|
bool syntheticLower = false;
|
|
|
|
bool syntheticUpper = false;
|
|
|
|
|
|
|
|
if (mStyle.variantSubSuper != NS_FONT_VARIANT_POSITION_NORMAL &&
|
|
|
|
(aTextRun->GetShapingState() ==
|
|
|
|
gfxTextRun::eShapingState_ForceFallbackFeature ||
|
|
|
|
!matchedFont->SupportsSubSuperscript(mStyle.variantSubSuper,
|
|
|
|
aString, aLength,
|
|
|
|
aRunScript)))
|
|
|
|
{
|
|
|
|
// fallback for subscript/superscript variant glyphs
|
|
|
|
|
|
|
|
// if the feature was already used, abort and force
|
|
|
|
// fallback across the entire textrun
|
|
|
|
gfxTextRun::ShapingState ss = aTextRun->GetShapingState();
|
|
|
|
|
|
|
|
if (ss == gfxTextRun::eShapingState_Normal) {
|
|
|
|
aTextRun->SetShapingState(gfxTextRun::eShapingState_ShapingWithFallback);
|
|
|
|
} else if (ss == gfxTextRun::eShapingState_ShapingWithFeature) {
|
|
|
|
aTextRun->SetShapingState(gfxTextRun::eShapingState_Aborted);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> subSuperFont =
|
2014-09-16 13:58:12 +04:00
|
|
|
matchedFont->GetSubSuperscriptFont(aTextRun->GetAppUnitsPerDevUnit());
|
|
|
|
aTextRun->AddGlyphRun(subSuperFont, range.matchType,
|
2014-09-16 15:25:45 +04:00
|
|
|
aOffset + runStart, (matchedLength > 0),
|
|
|
|
range.orientation);
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!subSuperFont->SplitAndInitTextRun(aDrawTarget, aTextRun,
|
2014-09-16 13:58:12 +04:00
|
|
|
aString + runStart,
|
|
|
|
aOffset + runStart,
|
|
|
|
matchedLength,
|
2014-10-01 23:25:48 +04:00
|
|
|
aRunScript,
|
|
|
|
vertical)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// glyph layout failed! treat as missing glyphs
|
|
|
|
matchedFont = nullptr;
|
|
|
|
}
|
|
|
|
} else if (mStyle.variantCaps != NS_FONT_VARIANT_CAPS_NORMAL &&
|
|
|
|
!matchedFont->SupportsVariantCaps(aRunScript,
|
|
|
|
mStyle.variantCaps,
|
|
|
|
petiteToSmallCaps,
|
|
|
|
syntheticLower,
|
|
|
|
syntheticUpper))
|
|
|
|
{
|
|
|
|
// fallback for small-caps variant glyphs
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!matchedFont->InitFakeSmallCapsRun(aDrawTarget, aTextRun,
|
2014-09-16 13:58:12 +04:00
|
|
|
aString + runStart,
|
|
|
|
aOffset + runStart,
|
|
|
|
matchedLength,
|
|
|
|
range.matchType,
|
2014-09-16 15:25:45 +04:00
|
|
|
range.orientation,
|
2014-09-16 13:58:12 +04:00
|
|
|
aRunScript,
|
|
|
|
syntheticLower,
|
|
|
|
syntheticUpper)) {
|
|
|
|
matchedFont = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// shape normally with variant feature enabled
|
|
|
|
gfxTextRun::ShapingState ss = aTextRun->GetShapingState();
|
|
|
|
|
|
|
|
// adjust the shaping state if necessary
|
|
|
|
if (ss == gfxTextRun::eShapingState_Normal) {
|
|
|
|
aTextRun->SetShapingState(gfxTextRun::eShapingState_ShapingWithFeature);
|
|
|
|
} else if (ss == gfxTextRun::eShapingState_ShapingWithFallback) {
|
|
|
|
// already have shaping results using fallback, need to redo
|
|
|
|
aTextRun->SetShapingState(gfxTextRun::eShapingState_Aborted);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do glyph layout and record the resulting positioned glyphs
|
|
|
|
aTextRun->AddGlyphRun(matchedFont, range.matchType,
|
2014-09-16 15:25:45 +04:00
|
|
|
aOffset + runStart, (matchedLength > 0),
|
|
|
|
range.orientation);
|
2015-12-16 00:56:41 +03:00
|
|
|
if (!matchedFont->SplitAndInitTextRun(aDrawTarget, aTextRun,
|
2014-09-16 13:58:12 +04:00
|
|
|
aString + runStart,
|
|
|
|
aOffset + runStart,
|
|
|
|
matchedLength,
|
2014-10-01 23:25:48 +04:00
|
|
|
aRunScript,
|
|
|
|
vertical)) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// glyph layout failed! treat as missing glyphs
|
|
|
|
matchedFont = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aTextRun->AddGlyphRun(mainFont, gfxTextRange::kFontGroup,
|
2014-09-16 15:25:45 +04:00
|
|
|
aOffset + runStart, (matchedLength > 0),
|
|
|
|
range.orientation);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!matchedFont) {
|
|
|
|
// We need to set cluster boundaries (and mark spaces) so that
|
|
|
|
// surrogate pairs, combining characters, etc behave properly,
|
|
|
|
// even if we don't have glyphs for them
|
|
|
|
aTextRun->SetupClusterBoundaries(aOffset + runStart, aString + runStart,
|
|
|
|
matchedLength);
|
|
|
|
|
|
|
|
// various "missing" characters may need special handling,
|
|
|
|
// so we check for them here
|
|
|
|
uint32_t runLimit = runStart + matchedLength;
|
|
|
|
for (uint32_t index = runStart; index < runLimit; index++) {
|
|
|
|
T ch = aString[index];
|
|
|
|
|
|
|
|
// tab and newline are not to be displayed as hexboxes,
|
|
|
|
// but do need to be recorded in the textrun
|
|
|
|
if (ch == '\n') {
|
|
|
|
aTextRun->SetIsNewline(aOffset + index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == '\t') {
|
|
|
|
aTextRun->SetIsTab(aOffset + index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for 16-bit textruns only, check for surrogate pairs and
|
|
|
|
// special Unicode spaces; omit these checks in 8-bit runs
|
|
|
|
if (sizeof(T) == sizeof(char16_t)) {
|
|
|
|
if (NS_IS_HIGH_SURROGATE(ch) &&
|
|
|
|
index + 1 < aLength &&
|
|
|
|
NS_IS_LOW_SURROGATE(aString[index + 1]))
|
|
|
|
{
|
2014-12-22 19:35:54 +03:00
|
|
|
uint32_t usv =
|
|
|
|
SURROGATE_TO_UCS4(ch, aString[index + 1]);
|
2014-09-16 13:58:12 +04:00
|
|
|
aTextRun->SetMissingGlyph(aOffset + index,
|
2014-12-22 19:35:54 +03:00
|
|
|
usv,
|
2014-09-16 13:58:12 +04:00
|
|
|
mainFont);
|
|
|
|
index++;
|
2014-12-22 19:35:54 +03:00
|
|
|
if (!mSkipDrawing && !IsPUA(usv)) {
|
|
|
|
missingChars = true;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if this is a known Unicode whitespace character that
|
|
|
|
// we can render using the space glyph with a custom width
|
|
|
|
gfxFloat wid = mainFont->SynthesizeSpaceWidth(ch);
|
|
|
|
if (wid >= 0.0) {
|
|
|
|
nscoord advance =
|
|
|
|
aTextRun->GetAppUnitsPerDevUnit() * floor(wid + 0.5);
|
|
|
|
if (gfxShapedText::CompressedGlyph::IsSimpleAdvance(advance)) {
|
|
|
|
aTextRun->GetCharacterGlyphs()[aOffset + index].
|
|
|
|
SetSimpleGlyph(advance,
|
|
|
|
mainFont->GetSpaceGlyph());
|
|
|
|
} else {
|
|
|
|
gfxTextRun::DetailedGlyph detailedGlyph;
|
|
|
|
detailedGlyph.mGlyphID = mainFont->GetSpaceGlyph();
|
|
|
|
detailedGlyph.mAdvance = advance;
|
|
|
|
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
|
|
|
|
gfxShapedText::CompressedGlyph g;
|
|
|
|
g.SetComplex(true, true, 1);
|
|
|
|
aTextRun->SetGlyphs(aOffset + index,
|
|
|
|
g, &detailedGlyph);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsInvalidChar(ch)) {
|
|
|
|
// invalid chars are left as zero-width/invisible
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// record char code so we can draw a box with the Unicode value
|
|
|
|
aTextRun->SetMissingGlyph(aOffset + index, ch, mainFont);
|
2014-12-22 19:35:54 +03:00
|
|
|
if (!mSkipDrawing && !IsPUA(ch)) {
|
|
|
|
missingChars = true;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runStart += matchedLength;
|
|
|
|
}
|
2014-12-22 19:35:54 +03:00
|
|
|
|
|
|
|
if (aMFR && missingChars) {
|
|
|
|
aMFR->RecordScript(aRunScript);
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun *
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfx::ShapedTextFlags aFlags,
|
2015-12-16 00:56:41 +03:00
|
|
|
LazyReferenceDrawTargetGetter& aRefDrawTargetGetter)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-05-05 00:27:05 +03:00
|
|
|
MOZ_ASSERT(!(aFlags & ~ShapedTextFlags::TEXT_ORIENT_MASK),
|
2015-04-24 01:15:32 +03:00
|
|
|
"flags here should only be used to specify orientation");
|
2014-09-16 13:58:12 +04:00
|
|
|
if (mCachedEllipsisTextRun &&
|
2017-05-05 00:27:05 +03:00
|
|
|
(mCachedEllipsisTextRun->GetFlags() & ShapedTextFlags::TEXT_ORIENT_MASK) == aFlags &&
|
2014-09-16 13:58:12 +04:00
|
|
|
mCachedEllipsisTextRun->GetAppUnitsPerDevUnit() == aAppUnitsPerDevPixel) {
|
2016-04-15 22:45:37 +03:00
|
|
|
return mCachedEllipsisTextRun.get();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use a Unicode ellipsis if the font supports it,
|
|
|
|
// otherwise use three ASCII periods as fallback.
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFont* firstFont = GetFirstValidFont(uint32_t(kEllipsisChar[0]));
|
2014-09-16 13:58:12 +04:00
|
|
|
nsString ellipsis = firstFont->HasCharacter(kEllipsisChar[0])
|
|
|
|
? nsDependentString(kEllipsisChar,
|
|
|
|
ArrayLength(kEllipsisChar) - 1)
|
|
|
|
: nsDependentString(kASCIIPeriodsChar,
|
|
|
|
ArrayLength(kASCIIPeriodsChar) - 1);
|
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
RefPtr<DrawTarget> refDT = aRefDrawTargetGetter.GetRefDrawTarget();
|
2014-09-16 13:58:12 +04:00
|
|
|
Parameters params = {
|
2015-12-16 00:56:41 +03:00
|
|
|
refDT, nullptr, nullptr, nullptr, 0, aAppUnitsPerDevPixel
|
2014-09-16 13:58:12 +04:00
|
|
|
};
|
2016-04-19 19:13:28 +03:00
|
|
|
mCachedEllipsisTextRun =
|
2014-12-22 19:35:54 +03:00
|
|
|
MakeTextRun(ellipsis.get(), ellipsis.Length(), ¶ms,
|
2017-05-05 00:27:05 +03:00
|
|
|
aFlags | ShapedTextFlags::TEXT_IS_PERSISTENT,
|
|
|
|
nsTextFrameUtils::Flags(), nullptr);
|
2016-04-19 19:13:28 +03:00
|
|
|
if (!mCachedEllipsisTextRun) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-19 19:13:28 +03:00
|
|
|
// don't let the presence of a cached ellipsis textrun prolong the
|
|
|
|
// fontgroup's life
|
|
|
|
mCachedEllipsisTextRun->ReleaseFontGroup();
|
|
|
|
return mCachedEllipsisTextRun.get();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-11-11 15:13:33 +03:00
|
|
|
already_AddRefed<gfxFont>
|
|
|
|
gfxFontGroup::FindFallbackFaceForChar(gfxFontFamily* aFamily, uint32_t aCh,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aRunScript)
|
2015-11-11 15:13:33 +03:00
|
|
|
{
|
|
|
|
GlobalFontMatch data(aCh, aRunScript, &mStyle);
|
|
|
|
aFamily->SearchAllFontsForChar(&data);
|
|
|
|
gfxFontEntry* fe = data.mBestMatch;
|
|
|
|
if (!fe) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsBold = mStyle.weight >= 600 && !fe->IsBold() &&
|
|
|
|
mStyle.allowSyntheticWeight;
|
|
|
|
RefPtr<gfxFont> font = fe->FindOrMakeFont(&mStyle, needsBold);
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFloat
|
|
|
|
gfxFontGroup::GetUnderlineOffset()
|
|
|
|
{
|
|
|
|
if (mUnderlineOffset == UNDERLINE_OFFSET_NOT_SET) {
|
|
|
|
// if the fontlist contains a bad underline font, make the underline
|
|
|
|
// offset the min of the first valid font and bad font underline offsets
|
|
|
|
uint32_t len = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
FamilyFace& ff = mFonts[i];
|
2014-11-06 07:42:50 +03:00
|
|
|
if (!ff.IsUserFontContainer() &&
|
|
|
|
!ff.FontEntry()->IsUserFont() &&
|
|
|
|
ff.Family() &&
|
2014-09-25 07:16:54 +04:00
|
|
|
ff.Family()->IsBadUnderlineFamily()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font = GetFontAt(i);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (!font) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-30 10:38:26 +04:00
|
|
|
gfxFloat bad = font->GetMetrics(gfxFont::eHorizontal).
|
|
|
|
underlineOffset;
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFloat first =
|
2014-09-30 10:38:26 +04:00
|
|
|
GetFirstValidFont()->GetMetrics(gfxFont::eHorizontal).
|
|
|
|
underlineOffset;
|
2014-09-25 07:16:54 +04:00
|
|
|
mUnderlineOffset = std::min(first, bad);
|
|
|
|
return mUnderlineOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no bad underline fonts, use the first valid font's metric
|
2014-09-30 10:38:26 +04:00
|
|
|
mUnderlineOffset = GetFirstValidFont()->
|
|
|
|
GetMetrics(gfxFont::eHorizontal).underlineOffset;
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mUnderlineOffset;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
already_AddRefed<gfxFont>
|
2014-09-30 10:27:55 +04:00
|
|
|
gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh, uint32_t aNextCh,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aRunScript, gfxFont *aPrevMatchedFont,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint8_t *aMatchType)
|
|
|
|
{
|
2016-05-25 12:51:13 +03:00
|
|
|
// If the char is a cluster extender, we want to use the same font as the
|
|
|
|
// preceding character if possible. This is preferable to using the font
|
|
|
|
// group because it avoids breaks in shaping within a cluster.
|
|
|
|
if (aPrevMatchedFont && IsClusterExtender(aCh) &&
|
2015-02-07 23:45:06 +03:00
|
|
|
aPrevMatchedFont->HasCharacter(aCh)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
2015-02-07 23:45:06 +03:00
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:51:13 +03:00
|
|
|
// Special cases for NNBSP (as used in Mongolian):
|
|
|
|
const uint32_t NARROW_NO_BREAK_SPACE = 0x202f;
|
|
|
|
if (aCh == NARROW_NO_BREAK_SPACE) {
|
|
|
|
// If there is no preceding character, try the font that we'd use
|
|
|
|
// for the next char (unless it's just another NNBSP; we don't try
|
|
|
|
// to look ahead through a whole run of them).
|
|
|
|
if (!aPrevCh && aNextCh && aNextCh != NARROW_NO_BREAK_SPACE) {
|
|
|
|
RefPtr<gfxFont> nextFont =
|
|
|
|
FindFontForChar(aNextCh, 0, 0, aRunScript, aPrevMatchedFont,
|
|
|
|
aMatchType);
|
|
|
|
if (nextFont && nextFont->HasCharacter(aCh)) {
|
|
|
|
return nextFont.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, treat NNBSP like a cluster extender (as above) and try
|
|
|
|
// to continue the preceding font run.
|
|
|
|
if (aPrevMatchedFont && aPrevMatchedFont->HasCharacter(aCh)) {
|
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// To optimize common cases, try the first font in the font-group
|
|
|
|
// before going into the more detailed checks below
|
|
|
|
uint32_t nextIndex = 0;
|
|
|
|
bool isJoinControl = gfxFontUtils::IsJoinControl(aCh);
|
|
|
|
bool wasJoinCauser = gfxFontUtils::IsJoinCauser(aPrevCh);
|
|
|
|
bool isVarSelector = gfxFontUtils::IsVarSelector(aCh);
|
|
|
|
|
|
|
|
if (!isJoinControl && !wasJoinCauser && !isVarSelector) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> firstFont = GetFontAt(0, aCh);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (firstFont) {
|
|
|
|
if (firstFont->HasCharacter(aCh)) {
|
2014-09-25 07:16:52 +04:00
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
2014-09-25 07:16:54 +04:00
|
|
|
return firstFont.forget();
|
|
|
|
}
|
|
|
|
|
2016-04-14 23:02:12 +03:00
|
|
|
RefPtr<gfxFont> font;
|
2015-11-11 15:13:33 +03:00
|
|
|
if (mFonts[0].CheckForFallbackFaces()) {
|
2016-04-14 23:02:12 +03:00
|
|
|
font = FindFallbackFaceForChar(mFonts[0].Family(), aCh,
|
|
|
|
aRunScript);
|
|
|
|
} else if (!firstFont->GetFontEntry()->IsUserFont()) {
|
|
|
|
// For platform fonts (but not userfonts), we may need to do
|
|
|
|
// fallback within the family to handle cases where some faces
|
|
|
|
// such as Italic or Black have reduced character sets compared
|
|
|
|
// to the family's Regular face.
|
|
|
|
gfxFontEntry* fe = firstFont->GetFontEntry();
|
|
|
|
if (!fe->IsUpright() ||
|
|
|
|
fe->Weight() != NS_FONT_WEIGHT_NORMAL ||
|
|
|
|
fe->Stretch() != NS_FONT_STRETCH_NORMAL) {
|
|
|
|
// If style/weight/stretch was not Normal, see if we can
|
|
|
|
// fall back to a next-best face (e.g. Arial Black -> Bold,
|
|
|
|
// or Arial Narrow -> Regular).
|
|
|
|
font = FindFallbackFaceForChar(mFonts[0].Family(), aCh,
|
|
|
|
aRunScript);
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
2014-09-25 07:16:52 +04:00
|
|
|
}
|
2016-04-14 23:02:12 +03:00
|
|
|
if (font) {
|
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return font.forget();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2014-09-25 07:16:52 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// we don't need to check the first font again below
|
|
|
|
++nextIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPrevMatchedFont) {
|
|
|
|
// Don't switch fonts for control characters, regardless of
|
|
|
|
// whether they are present in the current font, as they won't
|
|
|
|
// actually be rendered (see bug 716229)
|
|
|
|
if (isJoinControl ||
|
|
|
|
GetGeneralCategory(aCh) == HB_UNICODE_GENERAL_CATEGORY_CONTROL) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if previous character was a join-causer (ZWJ),
|
|
|
|
// use the same font as the previous range if we can
|
|
|
|
if (wasJoinCauser) {
|
|
|
|
if (aPrevMatchedFont->HasCharacter(aCh)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this character is a variation selector,
|
|
|
|
// use the previous font regardless of whether it supports VS or not.
|
|
|
|
// otherwise the text run will be divided.
|
|
|
|
if (isVarSelector) {
|
|
|
|
if (aPrevMatchedFont) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
// VS alone. it's meaningless to search different fonts
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. check remaining fonts in the font group
|
2014-09-25 07:16:54 +04:00
|
|
|
uint32_t fontListLength = mFonts.Length();
|
2014-09-16 13:58:12 +04:00
|
|
|
for (uint32_t i = nextIndex; i < fontListLength; i++) {
|
2014-09-25 07:16:54 +04:00
|
|
|
FamilyFace& ff = mFonts[i];
|
|
|
|
if (ff.IsInvalid() || ff.IsLoading()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
// if available, use already made gfxFont and check for character
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font = ff.Font();
|
2014-11-06 07:42:50 +03:00
|
|
|
if (font) {
|
|
|
|
if (font->HasCharacter(aCh)) {
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-25 07:16:52 +04:00
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
// don't have a gfxFont yet, test before building
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFontEntry *fe = ff.FontEntry();
|
|
|
|
if (fe->mIsUserFontContainer) {
|
2014-11-06 07:42:50 +03:00
|
|
|
// for userfonts, need to test both the unicode range map and
|
|
|
|
// the cmap of the platform font entry
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxUserFontEntry* ufe = static_cast<gfxUserFontEntry*>(fe);
|
2014-11-06 07:42:50 +03:00
|
|
|
|
|
|
|
// never match a character outside the defined unicode range
|
|
|
|
if (!ufe->CharacterInUnicodeRange(aCh)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// load if not already loaded but only if no other font in similar
|
|
|
|
// range within family is loading
|
|
|
|
if (ufe->LoadState() == gfxUserFontEntry::STATUS_NOT_LOADED &&
|
|
|
|
!FontLoadingForFamily(ff.Family(), aCh)) {
|
2014-09-25 07:16:54 +04:00
|
|
|
ufe->Load();
|
2014-11-06 07:42:50 +03:00
|
|
|
ff.CheckState(mSkipDrawing);
|
2014-09-25 07:16:52 +04:00
|
|
|
}
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFontEntry* pfe = ufe->GetPlatformFontEntry();
|
|
|
|
if (pfe && pfe->HasCharacter(aCh)) {
|
2014-11-06 07:42:50 +03:00
|
|
|
font = GetFontAt(i, aCh);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (font) {
|
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (fe->HasCharacter(aCh)) {
|
2014-11-06 07:42:50 +03:00
|
|
|
// for normal platform fonts, after checking the cmap
|
|
|
|
// build the font via GetFontAt
|
|
|
|
font = GetFontAt(i, aCh);
|
2014-09-25 07:16:54 +04:00
|
|
|
if (font) {
|
2014-09-25 07:16:52 +04:00
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return font.forget();
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-11-11 15:13:33 +03:00
|
|
|
// check other family faces if needed
|
|
|
|
if (ff.CheckForFallbackFaces()) {
|
|
|
|
NS_ASSERTION(i == 0 ? true :
|
|
|
|
!mFonts[i-1].CheckForFallbackFaces() ||
|
|
|
|
!mFonts[i-1].Family()->Name().Equals(ff.Family()->Name()),
|
|
|
|
"should only do fallback once per font family");
|
|
|
|
font = FindFallbackFaceForChar(ff.Family(), aCh, aRunScript);
|
2014-09-25 07:16:52 +04:00
|
|
|
if (font) {
|
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return font.forget();
|
|
|
|
}
|
2015-11-11 15:13:33 +03:00
|
|
|
} else {
|
2016-04-14 23:02:12 +03:00
|
|
|
// For platform fonts, but not user fonts, consider intra-family
|
|
|
|
// fallback to handle styles with reduced character sets (see
|
|
|
|
// also above).
|
2015-11-11 15:13:33 +03:00
|
|
|
fe = ff.FontEntry();
|
2016-04-14 23:02:12 +03:00
|
|
|
if (!fe->mIsUserFontContainer && !fe->IsUserFont() &&
|
|
|
|
(!fe->IsUpright() ||
|
|
|
|
fe->Weight() != NS_FONT_WEIGHT_NORMAL ||
|
|
|
|
fe->Stretch() != NS_FONT_STRETCH_NORMAL)) {
|
|
|
|
font = FindFallbackFaceForChar(ff.Family(), aCh, aRunScript);
|
2015-11-11 15:13:33 +03:00
|
|
|
if (font) {
|
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
if (fontListLength == 0) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> defaultFont = GetDefaultFont();
|
2014-09-25 07:16:54 +04:00
|
|
|
if (defaultFont->HasCharacter(aCh)) {
|
|
|
|
*aMatchType = gfxTextRange::kFontGroup;
|
|
|
|
return defaultFont.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// if character is in Private Use Area, don't do matching against pref or system fonts
|
|
|
|
if ((aCh >= 0xE000 && aCh <= 0xF8FF) || (aCh >= 0xF0000 && aCh <= 0x10FFFD))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// 2. search pref fonts
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font = WhichPrefFontSupportsChar(aCh);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (font) {
|
|
|
|
*aMatchType = gfxTextRange::kPrefsFallback;
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. use fallback fonts
|
|
|
|
// -- before searching for something else check the font used for the previous character
|
|
|
|
if (aPrevMatchedFont && aPrevMatchedFont->HasCharacter(aCh)) {
|
|
|
|
*aMatchType = gfxTextRange::kSystemFallback;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> ret = aPrevMatchedFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// for known "space" characters, don't do a full system-fallback search;
|
|
|
|
// we'll synthesize appropriate-width spaces instead of missing-glyph boxes
|
|
|
|
if (GetGeneralCategory(aCh) ==
|
|
|
|
HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR &&
|
2014-09-25 07:16:53 +04:00
|
|
|
GetFirstValidFont()->SynthesizeSpaceWidth(aCh) >= 0.0)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- otherwise look for other stuff
|
|
|
|
*aMatchType = gfxTextRange::kSystemFallback;
|
2014-09-30 10:27:55 +04:00
|
|
|
font = WhichSystemFontSupportsChar(aCh, aNextCh, aRunScript);
|
2014-09-16 13:58:12 +04:00
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
|
|
|
|
const T *aString, uint32_t aLength,
|
2017-05-05 00:27:05 +03:00
|
|
|
Script aRunScript,
|
|
|
|
gfx::ShapedTextFlags aOrientation)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aRanges.Length() == 0, "aRanges must be initially empty");
|
|
|
|
NS_ASSERTION(aLength > 0, "don't call ComputeRanges for zero-length text");
|
|
|
|
|
|
|
|
uint32_t prevCh = 0;
|
2014-09-30 10:27:55 +04:00
|
|
|
uint32_t nextCh = aString[0];
|
|
|
|
if (sizeof(T) == sizeof(char16_t)) {
|
|
|
|
if (aLength > 1 && NS_IS_HIGH_SURROGATE(nextCh) &&
|
|
|
|
NS_IS_LOW_SURROGATE(aString[1])) {
|
|
|
|
nextCh = SURROGATE_TO_UCS4(nextCh, aString[1]);
|
|
|
|
}
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t lastRangeIndex = -1;
|
|
|
|
|
|
|
|
// initialize prevFont to the group's primary font, so that this will be
|
|
|
|
// used for string-initial control chars, etc rather than risk hitting font
|
|
|
|
// fallback for these (bug 716229)
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxFont *prevFont = GetFirstValidFont();
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// if we use the initial value of prevFont, we treat this as a match from
|
|
|
|
// the font group; fixes bug 978313
|
|
|
|
uint8_t matchType = gfxTextRange::kFontGroup;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aLength; i++) {
|
|
|
|
|
|
|
|
const uint32_t origI = i; // save off in case we increase for surrogate
|
|
|
|
|
|
|
|
// set up current ch
|
2014-09-30 10:27:55 +04:00
|
|
|
uint32_t ch = nextCh;
|
|
|
|
|
|
|
|
// Get next char (if any) so that FindFontForChar can look ahead
|
|
|
|
// for a possible variation selector.
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
if (sizeof(T) == sizeof(char16_t)) {
|
2014-09-30 10:27:55 +04:00
|
|
|
// In 16-bit case only, check for surrogate pairs.
|
|
|
|
if (ch > 0xffffu) {
|
2014-09-16 13:58:12 +04:00
|
|
|
i++;
|
|
|
|
}
|
2014-09-30 10:27:55 +04:00
|
|
|
if (i < aLength - 1) {
|
|
|
|
nextCh = aString[i + 1];
|
|
|
|
if ((i + 2 < aLength) && NS_IS_HIGH_SURROGATE(nextCh) &&
|
|
|
|
NS_IS_LOW_SURROGATE(aString[i + 2])) {
|
|
|
|
nextCh = SURROGATE_TO_UCS4(nextCh, aString[i + 2]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextCh = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 8-bit case is trivial.
|
|
|
|
nextCh = i < aLength - 1 ? aString[i + 1] : 0;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == 0xa0) {
|
|
|
|
ch = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the font for this char
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font =
|
2014-09-30 10:27:55 +04:00
|
|
|
FindFontForChar(ch, prevCh, nextCh, aRunScript, prevFont,
|
|
|
|
&matchType);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-10-08 12:14:49 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
2014-09-16 13:58:12 +04:00
|
|
|
if (MOZ_UNLIKELY(mTextPerf)) {
|
|
|
|
if (matchType == gfxTextRange::kPrefsFallback) {
|
|
|
|
mTextPerf->current.fallbackPrefs++;
|
|
|
|
} else if (matchType == gfxTextRange::kSystemFallback) {
|
|
|
|
mTextPerf->current.fallbackSystem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
prevCh = ch;
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
ShapedTextFlags orient = aOrientation;
|
|
|
|
if (aOrientation == ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED) {
|
2014-09-16 15:25:45 +04:00
|
|
|
// For CSS text-orientation:mixed, we need to resolve orientation
|
|
|
|
// on a per-character basis using the UTR50 orientation property.
|
|
|
|
switch (GetVerticalOrientation(ch)) {
|
|
|
|
case VERTICAL_ORIENTATION_U:
|
|
|
|
case VERTICAL_ORIENTATION_Tr:
|
|
|
|
case VERTICAL_ORIENTATION_Tu:
|
2017-05-05 00:27:05 +03:00
|
|
|
orient = ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
break;
|
|
|
|
case VERTICAL_ORIENTATION_R:
|
2017-05-05 00:27:05 +03:00
|
|
|
orient = ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
2014-09-16 15:25:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
if (lastRangeIndex == -1) {
|
|
|
|
// first char ==> make a new range
|
2014-09-16 15:25:45 +04:00
|
|
|
aRanges.AppendElement(gfxTextRange(0, 1, font, matchType, orient));
|
2014-09-16 13:58:12 +04:00
|
|
|
lastRangeIndex++;
|
|
|
|
prevFont = font;
|
|
|
|
} else {
|
2016-02-15 12:07:53 +03:00
|
|
|
// if font or orientation has changed, make a new range...
|
|
|
|
// unless ch is a variation selector (bug 1248248)
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRange& prevRange = aRanges[lastRangeIndex];
|
2014-09-16 15:25:45 +04:00
|
|
|
if (prevRange.font != font || prevRange.matchType != matchType ||
|
2016-02-15 12:07:53 +03:00
|
|
|
(prevRange.orientation != orient && !IsClusterExtender(ch))) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// close out the previous range
|
|
|
|
prevRange.end = origI;
|
|
|
|
aRanges.AppendElement(gfxTextRange(origI, i + 1,
|
2014-09-16 15:25:45 +04:00
|
|
|
font, matchType, orient));
|
2014-09-16 13:58:12 +04:00
|
|
|
lastRangeIndex++;
|
|
|
|
|
|
|
|
// update prevFont for the next match, *unless* we switched
|
|
|
|
// fonts on a ZWJ, in which case propagating the changed font
|
|
|
|
// is probably not a good idea (see bug 619511)
|
|
|
|
if (sizeof(T) == sizeof(uint8_t) ||
|
|
|
|
!gfxFontUtils::IsJoinCauser(ch))
|
|
|
|
{
|
|
|
|
prevFont = font;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aRanges[lastRangeIndex].end = aLength;
|
2014-11-06 07:42:50 +03:00
|
|
|
|
2016-10-08 12:14:49 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
2015-10-30 01:58:24 +03:00
|
|
|
LogModule* log = mStyle.systemFont
|
|
|
|
? gfxPlatform::GetLog(eGfxLog_textrunui)
|
|
|
|
: gfxPlatform::GetLog(eGfxLog_textrun);
|
2015-07-06 04:11:19 +03:00
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Debug))) {
|
|
|
|
nsAutoCString lang;
|
|
|
|
mStyle.language->ToUTF8String(lang);
|
|
|
|
nsAutoString families;
|
|
|
|
mFamilyList.ToString(families);
|
|
|
|
|
|
|
|
// collect the font matched for each range
|
|
|
|
nsAutoCString fontMatches;
|
|
|
|
for (size_t i = 0, i_end = aRanges.Length(); i < i_end; i++) {
|
|
|
|
const gfxTextRange& r = aRanges[i];
|
|
|
|
fontMatches.AppendPrintf(" [%u:%u] %.200s (%s)", r.start, r.end,
|
|
|
|
(r.font.get() ?
|
|
|
|
NS_ConvertUTF16toUTF8(r.font->GetName()).get() : "<null>"),
|
|
|
|
(r.matchType == gfxTextRange::kFontGroup ?
|
|
|
|
"list" :
|
|
|
|
(r.matchType == gfxTextRange::kPrefsFallback) ?
|
|
|
|
"prefs" : "sys"));
|
|
|
|
}
|
|
|
|
MOZ_LOG(log, LogLevel::Debug,\
|
|
|
|
("(%s-fontmatching) fontgroup: [%s] default: %s lang: %s script: %d"
|
|
|
|
"%s\n",
|
|
|
|
(mStyle.systemFont ? "textrunui" : "textrun"),
|
|
|
|
NS_ConvertUTF16toUTF8(families).get(),
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_serif ?
|
|
|
|
"serif" :
|
|
|
|
(mFamilyList.GetDefaultFontType() == eFamily_sans_serif ?
|
|
|
|
"sans-serif" : "none")),
|
2016-12-16 06:16:31 +03:00
|
|
|
lang.get(), static_cast<int>(aRunScript),
|
2015-07-06 04:11:19 +03:00
|
|
|
fontMatches.get()));
|
2014-11-06 07:42:50 +03:00
|
|
|
}
|
|
|
|
#endif
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxUserFontSet*
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::GetUserFontSet()
|
|
|
|
{
|
|
|
|
return mUserFontSet;
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
void
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup::SetUserFontSet(gfxUserFontSet *aUserFontSet)
|
|
|
|
{
|
|
|
|
if (aUserFontSet == mUserFontSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mUserFontSet = aUserFontSet;
|
|
|
|
mCurrGeneration = GetGeneration() - 1;
|
2014-09-25 07:16:54 +04:00
|
|
|
UpdateUserFonts();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
gfxFontGroup::GetGeneration()
|
|
|
|
{
|
|
|
|
if (!mUserFontSet)
|
|
|
|
return 0;
|
|
|
|
return mUserFontSet->GetGeneration();
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
uint64_t
|
|
|
|
gfxFontGroup::GetRebuildGeneration()
|
|
|
|
{
|
|
|
|
if (!mUserFontSet)
|
|
|
|
return 0;
|
|
|
|
return mUserFontSet->GetRebuildGeneration();
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFontGroup::UpdateUserFonts()
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2014-09-25 07:16:54 +04:00
|
|
|
if (mCurrGeneration < GetRebuildGeneration()) {
|
|
|
|
// fonts in userfont set changed, need to redo the fontlist
|
2014-09-16 13:58:12 +04:00
|
|
|
mFonts.Clear();
|
2016-08-18 04:26:50 +03:00
|
|
|
ClearCachedData();
|
2014-09-16 13:58:12 +04:00
|
|
|
BuildFontList();
|
|
|
|
mCurrGeneration = GetGeneration();
|
2014-09-25 07:16:54 +04:00
|
|
|
} else if (mCurrGeneration != GetGeneration()) {
|
|
|
|
// load state change occurred, verify load state and validity of fonts
|
2016-08-18 04:26:50 +03:00
|
|
|
ClearCachedData();
|
2014-09-25 07:16:54 +04:00
|
|
|
|
|
|
|
uint32_t len = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
FamilyFace& ff = mFonts[i];
|
2014-11-06 07:42:50 +03:00
|
|
|
if (ff.Font() || !ff.IsUserFontContainer()) {
|
2014-09-25 07:16:54 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-06 07:42:50 +03:00
|
|
|
ff.CheckState(mSkipDrawing);
|
2014-09-25 07:16:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrGeneration = GetGeneration();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
bool
|
|
|
|
gfxFontGroup::ContainsUserFont(const gfxUserFontEntry* aUserFont)
|
|
|
|
{
|
|
|
|
UpdateUserFonts();
|
|
|
|
// search through the fonts list for a specific user font
|
|
|
|
uint32_t len = mFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
FamilyFace& ff = mFonts[i];
|
|
|
|
if (ff.EqualsUserFont(aUserFont)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
already_AddRefed<gfxFont>
|
|
|
|
gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// get the pref font list if it hasn't been set up already
|
|
|
|
uint32_t unicodeRange = FindCharUnicodeRange(aCh);
|
2015-09-29 04:51:29 +03:00
|
|
|
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
|
|
|
|
eFontPrefLang charLang = pfl->GetFontPrefLangFor(unicodeRange);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// if the last pref font was the first family in the pref list, no need to recheck through a list of families
|
|
|
|
if (mLastPrefFont && charLang == mLastPrefLang &&
|
|
|
|
mLastPrefFirstFont && mLastPrefFont->HasCharacter(aCh)) {
|
|
|
|
font = mLastPrefFont;
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// based on char lang and page lang, set up list of pref lang fonts to check
|
|
|
|
eFontPrefLang prefLangs[kMaxLenPrefLangList];
|
|
|
|
uint32_t i, numLangs = 0;
|
|
|
|
|
2015-09-29 04:51:29 +03:00
|
|
|
pfl->GetLangPrefs(prefLangs, numLangs, charLang, mPageLang);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
for (i = 0; i < numLangs; i++) {
|
|
|
|
eFontPrefLang currentLang = prefLangs[i];
|
2015-09-29 04:51:29 +03:00
|
|
|
mozilla::FontFamilyType defaultGeneric =
|
|
|
|
pfl->GetDefaultGeneric(currentLang);
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<gfxFontFamily>>* families =
|
2015-09-29 04:51:29 +03:00
|
|
|
pfl->GetPrefFontsLangGroup(defaultGeneric, currentLang);
|
|
|
|
NS_ASSERTION(families, "no pref font families found");
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// find the first pref font that includes the character
|
|
|
|
uint32_t j, numPrefs;
|
2015-09-29 04:51:29 +03:00
|
|
|
numPrefs = families->Length();
|
2014-09-16 13:58:12 +04:00
|
|
|
for (j = 0; j < numPrefs; j++) {
|
|
|
|
// look up the appropriate face
|
2015-09-29 04:51:29 +03:00
|
|
|
gfxFontFamily *family = (*families)[j];
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!family) continue;
|
|
|
|
|
|
|
|
// if a pref font is used, it's likely to be used again in the same text run.
|
|
|
|
// the style doesn't change so the face lookup can be cached rather than calling
|
|
|
|
// FindOrMakeFont repeatedly. speeds up FindFontForChar lookup times for subsequent
|
|
|
|
// pref font lookups
|
|
|
|
if (family == mLastPrefFamily && mLastPrefFont->HasCharacter(aCh)) {
|
|
|
|
font = mLastPrefFont;
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needsBold;
|
|
|
|
gfxFontEntry *fe = family->FindFontForStyle(mStyle, needsBold);
|
|
|
|
// if ch in cmap, create and return a gfxFont
|
2015-01-15 14:07:24 +03:00
|
|
|
if (fe && fe->HasCharacter(aCh)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> prefFont = fe->FindOrMakeFont(&mStyle, needsBold);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!prefFont) continue;
|
|
|
|
mLastPrefFamily = family;
|
|
|
|
mLastPrefFont = prefFont;
|
|
|
|
mLastPrefLang = charLang;
|
|
|
|
mLastPrefFirstFont = (i == 0 && j == 0);
|
|
|
|
return prefFont.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxFont>
|
2014-09-30 10:27:55 +04:00
|
|
|
gfxFontGroup::WhichSystemFontSupportsChar(uint32_t aCh, uint32_t aNextCh,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aRunScript)
|
2014-09-16 13:58:12 +04:00
|
|
|
{
|
2017-01-04 18:55:16 +03:00
|
|
|
gfxFontEntry *fe =
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->
|
2014-09-30 10:27:55 +04:00
|
|
|
SystemFindFontForChar(aCh, aNextCh, aRunScript, &mStyle);
|
2014-09-16 13:58:12 +04:00
|
|
|
if (fe) {
|
|
|
|
bool wantBold = mStyle.ComputeWeight() >= 6;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> font =
|
2014-09-16 13:58:12 +04:00
|
|
|
fe->FindOrMakeFont(&mStyle, wantBold && !fe->IsBold());
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
void
|
|
|
|
gfxMissingFontRecorder::Flush()
|
|
|
|
{
|
|
|
|
static bool mNotifiedFontsInitialized = false;
|
|
|
|
static uint32_t mNotifiedFonts[gfxMissingFontRecorder::kNumScriptBitsWords];
|
|
|
|
if (!mNotifiedFontsInitialized) {
|
|
|
|
memset(&mNotifiedFonts, 0, sizeof(mNotifiedFonts));
|
|
|
|
mNotifiedFontsInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString fontNeeded;
|
|
|
|
for (uint32_t i = 0; i < kNumScriptBitsWords; ++i) {
|
|
|
|
mMissingFonts[i] &= ~mNotifiedFonts[i];
|
|
|
|
if (!mMissingFonts[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (uint32_t j = 0; j < 32; ++j) {
|
|
|
|
if (!(mMissingFonts[i] & (1 << j))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mNotifiedFonts[i] |= (1 << j);
|
|
|
|
if (!fontNeeded.IsEmpty()) {
|
2015-08-14 01:33:48 +03:00
|
|
|
fontNeeded.Append(char16_t(','));
|
2014-12-22 19:35:54 +03:00
|
|
|
}
|
2016-04-21 20:58:59 +03:00
|
|
|
uint32_t sc = i * 32 + j;
|
|
|
|
MOZ_ASSERT(sc < static_cast<uint32_t>(Script::NUM_SCRIPT_CODES),
|
|
|
|
"how did we set the bit for an invalid script code?");
|
|
|
|
uint32_t tag = GetScriptTagForCode(static_cast<Script>(sc));
|
2014-12-22 19:35:54 +03:00
|
|
|
fontNeeded.Append(char16_t(tag >> 24));
|
|
|
|
fontNeeded.Append(char16_t((tag >> 16) & 0xff));
|
|
|
|
fontNeeded.Append(char16_t((tag >> 8) & 0xff));
|
|
|
|
fontNeeded.Append(char16_t(tag & 0xff));
|
|
|
|
}
|
|
|
|
mMissingFonts[i] = 0;
|
|
|
|
}
|
|
|
|
if (!fontNeeded.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIObserverService> service = GetObserverService();
|
|
|
|
service->NotifyObservers(nullptr, "font-needed", fontNeeded.get());
|
|
|
|
}
|
|
|
|
}
|