2009-03-30 04:31:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2010-03-10 15:46:41 +03:00
|
|
|
#include "gfxCoreTextShaper.h"
|
|
|
|
#include "gfxMacFont.h"
|
2009-03-30 04:31:51 +04:00
|
|
|
#include "gfxFontUtils.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-10-20 20:13:35 +03:00
|
|
|
#include "mozilla/UniquePtrExtensions.h"
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-12-30 23:29:48 +03:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-03-30 04:31:51 +04:00
|
|
|
// standard font descriptors that we construct the first time they're needed
|
2013-07-31 19:44:31 +04:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sDefaultFeaturesDescriptor = nullptr;
|
2017-10-12 00:12:43 +03:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sSmallCapsDescriptor = nullptr;
|
2013-07-31 19:44:31 +04:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sDisableLigaturesDescriptor = nullptr;
|
2017-10-12 00:12:43 +03:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sSmallCapDisableLigDescriptor = nullptr;
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sIndicFeaturesDescriptor = nullptr;
|
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sIndicDisableLigaturesDescriptor = nullptr;
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-12-30 23:29:48 +03:00
|
|
|
// Helper to create a CFDictionary with the right attributes for shaping our
|
|
|
|
// text, including imposing the given directionality.
|
|
|
|
CFDictionaryRef
|
|
|
|
gfxCoreTextShaper::CreateAttrDict(bool aRightToLeft)
|
|
|
|
{
|
|
|
|
// Because we always shape unidirectional runs, and may have applied
|
|
|
|
// directional overrides, we want to force a direction rather than
|
|
|
|
// allowing CoreText to do its own unicode-based bidi processing.
|
2017-09-15 00:45:26 +03:00
|
|
|
SInt16 dirOverride = kCTWritingDirectionOverride |
|
2015-12-30 23:29:48 +03:00
|
|
|
(aRightToLeft ? kCTWritingDirectionRightToLeft
|
|
|
|
: kCTWritingDirectionLeftToRight);
|
|
|
|
CFNumberRef dirNumber =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type, &dirOverride);
|
|
|
|
CFArrayRef dirArray =
|
|
|
|
::CFArrayCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) &dirNumber, 1,
|
|
|
|
&kCFTypeArrayCallBacks);
|
|
|
|
::CFRelease(dirNumber);
|
2017-09-15 00:45:26 +03:00
|
|
|
CFTypeRef attrs[] = { kCTFontAttributeName, kCTWritingDirectionAttributeName };
|
2015-12-30 23:29:48 +03:00
|
|
|
CFTypeRef values[] = { mCTFont, dirArray };
|
|
|
|
CFDictionaryRef attrDict =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
attrs, values, ArrayLength(attrs),
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(dirArray);
|
|
|
|
return attrDict;
|
|
|
|
}
|
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
gfxCoreTextShaper::gfxCoreTextShaper(gfxMacFont *aFont)
|
|
|
|
: gfxFontShaper(aFont)
|
2015-12-30 23:29:48 +03:00
|
|
|
, mAttributesDictLTR(nullptr)
|
|
|
|
, mAttributesDictRTL(nullptr)
|
2009-07-16 14:00:38 +04:00
|
|
|
{
|
2010-03-10 15:46:41 +03:00
|
|
|
// Create our CTFontRef
|
2015-03-25 11:25:49 +03:00
|
|
|
mCTFont = CreateCTFontWithFeatures(aFont->GetAdjustedSize(),
|
|
|
|
GetDefaultFeaturesDescriptor());
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
gfxCoreTextShaper::~gfxCoreTextShaper()
|
2009-03-30 04:31:51 +04:00
|
|
|
{
|
2015-12-30 23:29:48 +03:00
|
|
|
if (mAttributesDictLTR) {
|
|
|
|
::CFRelease(mAttributesDictLTR);
|
|
|
|
}
|
|
|
|
if (mAttributesDictRTL) {
|
|
|
|
::CFRelease(mAttributesDictRTL);
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
2010-03-10 15:46:41 +03:00
|
|
|
if (mCTFont) {
|
|
|
|
::CFRelease(mCTFont);
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
static bool
|
2016-04-21 20:58:59 +03:00
|
|
|
IsBuggyIndicScript(unicode::Script aScript)
|
2015-03-25 11:25:49 +03:00
|
|
|
{
|
2016-04-21 20:58:59 +03:00
|
|
|
return aScript == unicode::Script::BENGALI ||
|
2017-10-12 00:12:42 +03:00
|
|
|
aScript == unicode::Script::KANNADA ||
|
2017-10-12 00:12:42 +03:00
|
|
|
aScript == unicode::Script::ORIYA ||
|
|
|
|
aScript == unicode::Script::KHMER;
|
2015-03-25 11:25:49 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxCoreTextShaper::ShapeText(DrawTarget *aDrawTarget,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aText,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScript,
|
2014-10-01 23:25:48 +04:00
|
|
|
bool aVertical,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding,
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxShapedText *aShapedText)
|
2009-03-30 04:31:51 +04:00
|
|
|
{
|
2009-10-07 19:26:58 +04:00
|
|
|
// Create a CFAttributedString with text and style info, so we can use CoreText to lay it out.
|
2013-01-04 22:35:37 +04:00
|
|
|
bool isRightToLeft = aShapedText->IsRightToLeft();
|
2015-12-30 23:29:48 +03:00
|
|
|
const UniChar* text = reinterpret_cast<const UniChar*>(aText);
|
|
|
|
|
2017-09-15 00:45:26 +03:00
|
|
|
CFStringRef stringObj =
|
|
|
|
::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
|
|
|
|
text, aLength,
|
|
|
|
kCFAllocatorNull);
|
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
// Figure out whether we should try to set the AAT small-caps feature:
|
|
|
|
// examine OpenType tags for the requested style, and see if 'smcp' is
|
|
|
|
// among them.
|
|
|
|
const gfxFontStyle *style = mFont->GetStyle();
|
|
|
|
gfxFontEntry *entry = mFont->GetFontEntry();
|
|
|
|
auto handleFeatureTag = [](const uint32_t& aTag, uint32_t& aValue,
|
|
|
|
void *aUserArg) -> void {
|
|
|
|
if (aTag == HB_TAG('s','m','c','p') && aValue) {
|
|
|
|
*static_cast<bool*>(aUserArg) = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
bool addSmallCaps = false;
|
|
|
|
MergeFontFeatures(style,
|
|
|
|
entry->mFeatureSettings,
|
|
|
|
false,
|
|
|
|
entry->FamilyName(),
|
|
|
|
false,
|
|
|
|
handleFeatureTag,
|
|
|
|
&addSmallCaps);
|
|
|
|
|
2017-09-15 00:45:26 +03:00
|
|
|
// Get an attributes dictionary suitable for shaping text in the
|
|
|
|
// current direction, creating it if necessary.
|
|
|
|
CFDictionaryRef attrObj =
|
|
|
|
isRightToLeft ? mAttributesDictRTL : mAttributesDictLTR;
|
|
|
|
if (!attrObj) {
|
|
|
|
attrObj = CreateAttrDict(isRightToLeft);
|
|
|
|
(isRightToLeft ? mAttributesDictRTL : mAttributesDictLTR) = attrObj;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontRef tempCTFont = nullptr;
|
|
|
|
if (IsBuggyIndicScript(aScript)) {
|
|
|
|
// To work around buggy Indic AAT fonts shipped with OS X,
|
|
|
|
// we re-enable the Line Initial Smart Swashes feature that is needed
|
|
|
|
// for "split vowels" to work in at least Bengali and Kannada fonts.
|
|
|
|
// Affected fonts include Bangla MN, Bangla Sangam MN, Kannada MN,
|
|
|
|
// Kannada Sangam MN. See bugs 686225, 728557, 953231, 1145515.
|
2017-10-12 00:12:42 +03:00
|
|
|
// Also applies to Oriya and Khmer, see bug 1370927 and bug 1403166.
|
2015-03-25 11:25:49 +03:00
|
|
|
tempCTFont =
|
|
|
|
CreateCTFontWithFeatures(::CTFontGetSize(mCTFont),
|
|
|
|
aShapedText->DisableLigatures()
|
|
|
|
? GetIndicDisableLigaturesDescriptor()
|
|
|
|
: GetIndicFeaturesDescriptor());
|
|
|
|
} else if (aShapedText->DisableLigatures()) {
|
|
|
|
// For letterspacing (or maybe other situations) we need to make
|
|
|
|
// a copy of the CTFont with the ligature feature disabled.
|
|
|
|
tempCTFont =
|
|
|
|
CreateCTFontWithFeatures(::CTFontGetSize(mCTFont),
|
2017-10-12 00:12:43 +03:00
|
|
|
addSmallCaps
|
|
|
|
? GetSmallCapDisableLigDescriptor()
|
|
|
|
: GetDisableLigaturesDescriptor());
|
|
|
|
} else if (addSmallCaps) {
|
|
|
|
tempCTFont =
|
|
|
|
CreateCTFontWithFeatures(::CTFontGetSize(mCTFont),
|
|
|
|
GetSmallCapsDescriptor());
|
2015-03-25 11:25:49 +03:00
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
// For the disabled-ligature, buggy-indic-font or small-caps case, replace
|
2015-12-30 23:29:48 +03:00
|
|
|
// the standard CTFont in the attribute dictionary with a tweaked version.
|
|
|
|
CFMutableDictionaryRef mutableAttr = nullptr;
|
2015-03-25 11:25:49 +03:00
|
|
|
if (tempCTFont) {
|
2015-12-30 23:29:48 +03:00
|
|
|
mutableAttr = ::CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 2,
|
|
|
|
attrObj);
|
|
|
|
::CFDictionaryReplaceValue(mutableAttr,
|
|
|
|
kCTFontAttributeName, tempCTFont);
|
2015-03-25 11:25:49 +03:00
|
|
|
// Having created the dict, we're finished with our temporary
|
2017-10-12 00:12:43 +03:00
|
|
|
// Indic and/or ligature-disabled or small-caps CTFontRef.
|
2015-03-25 11:25:49 +03:00
|
|
|
::CFRelease(tempCTFont);
|
2015-12-30 23:29:48 +03:00
|
|
|
attrObj = mutableAttr;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we can create an attributed string
|
|
|
|
CFAttributedStringRef attrStringObj =
|
2009-10-07 19:26:58 +04:00
|
|
|
::CFAttributedStringCreate(kCFAllocatorDefault, stringObj, attrObj);
|
|
|
|
::CFRelease(stringObj);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Create the CoreText line from our string, then we're done with it
|
2009-10-07 19:26:58 +04:00
|
|
|
CTLineRef line = ::CTLineCreateWithAttributedString(attrStringObj);
|
|
|
|
::CFRelease(attrStringObj);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// and finally retrieve the glyph data and store into the gfxTextRun
|
2009-10-07 19:26:58 +04:00
|
|
|
CFArrayRef glyphRuns = ::CTLineGetGlyphRuns(line);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numRuns = ::CFArrayGetCount(glyphRuns);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// Iterate through the glyph runs.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool success = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t runIndex = 0; runIndex < numRuns; runIndex++) {
|
2011-12-06 16:39:19 +04:00
|
|
|
CTRunRef aCTRun =
|
|
|
|
(CTRunRef)::CFArrayGetValueAtIndex(glyphRuns, runIndex);
|
2015-04-14 11:37:53 +03:00
|
|
|
CFRange range = ::CTRunGetStringRange(aCTRun);
|
2014-09-26 12:20:20 +04:00
|
|
|
CFDictionaryRef runAttr = ::CTRunGetAttributes(aCTRun);
|
|
|
|
if (runAttr != attrObj) {
|
|
|
|
// If Core Text manufactured a new dictionary, this may indicate
|
|
|
|
// unexpected font substitution. In that case, we fail (and fall
|
|
|
|
// back to harfbuzz shaping)...
|
2015-12-30 23:29:48 +03:00
|
|
|
const void* font1 =
|
|
|
|
::CFDictionaryGetValue(attrObj, kCTFontAttributeName);
|
|
|
|
const void* font2 =
|
|
|
|
::CFDictionaryGetValue(runAttr, kCTFontAttributeName);
|
2014-09-26 12:20:20 +04:00
|
|
|
if (font1 != font2) {
|
|
|
|
// ...except that if the fallback was only for a variation
|
2015-12-08 03:22:06 +03:00
|
|
|
// selector or join control that is otherwise unsupported,
|
|
|
|
// we just ignore it.
|
|
|
|
if (range.length == 1) {
|
2017-09-15 00:45:26 +03:00
|
|
|
char16_t ch = aText[range.location];
|
2015-12-08 03:22:06 +03:00
|
|
|
if (gfxFontUtils::IsJoinControl(ch) ||
|
|
|
|
gfxFontUtils::IsVarSelector(ch)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-26 12:20:20 +04:00
|
|
|
}
|
|
|
|
NS_WARNING("unexpected font fallback in Core Text");
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-15 00:45:26 +03:00
|
|
|
if (SetGlyphsFromRun(aShapedText, aOffset, aLength, aCTRun) != NS_OK) {
|
2011-10-17 18:59:28 +04:00
|
|
|
success = false;
|
2009-03-30 04:31:51 +04:00
|
|
|
break;
|
2010-03-15 12:34:25 +03:00
|
|
|
}
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-12-30 23:29:48 +03:00
|
|
|
if (mutableAttr) {
|
|
|
|
::CFRelease(mutableAttr);
|
|
|
|
}
|
2009-10-07 19:26:58 +04:00
|
|
|
::CFRelease(line);
|
2010-03-15 12:34:25 +03:00
|
|
|
|
|
|
|
return success;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
#define SMALL_GLYPH_RUN 128 // preallocated size of our auto arrays for per-glyph data;
|
|
|
|
// some testing indicates that 90%+ of glyph runs will fit
|
|
|
|
// without requiring a separate allocation
|
|
|
|
|
2009-03-30 04:31:51 +04:00
|
|
|
nsresult
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2017-09-15 00:45:26 +03:00
|
|
|
CTRunRef aCTRun)
|
2009-03-30 04:31:51 +04:00
|
|
|
{
|
2017-11-11 18:32:58 +03:00
|
|
|
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
int32_t direction = aShapedText->IsRightToLeft() ? -1 : 1;
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t numGlyphs = ::CTRunGetGlyphCount(aCTRun);
|
2010-03-10 15:46:41 +03:00
|
|
|
if (numGlyphs == 0) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_OK;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
int32_t wordLength = aLength;
|
2011-12-06 16:39:19 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// character offsets get really confusing here, as we have to keep track of
|
|
|
|
// (a) the text in the actual textRun we're constructing
|
|
|
|
// (c) the string that was handed to CoreText, which contains the text of the font run
|
|
|
|
// (d) the CTRun currently being processed, which may be a sub-run of the CoreText line
|
|
|
|
|
|
|
|
// get the source string range within the CTLine's text
|
|
|
|
CFRange stringRange = ::CTRunGetStringRange(aCTRun);
|
|
|
|
// skip the run if it is entirely outside the actual range of the font run
|
2017-09-15 00:45:26 +03:00
|
|
|
if (stringRange.location + stringRange.length <= 0 ||
|
|
|
|
stringRange.location >= wordLength) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_OK;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// retrieve the laid-out glyph data from the CTRun
|
2015-10-20 20:13:35 +03:00
|
|
|
UniquePtr<CGGlyph[]> glyphsArray;
|
|
|
|
UniquePtr<CGPoint[]> positionsArray;
|
|
|
|
UniquePtr<CFIndex[]> glyphToCharArray;
|
2013-07-31 19:44:31 +04:00
|
|
|
const CGGlyph* glyphs = nullptr;
|
|
|
|
const CGPoint* positions = nullptr;
|
|
|
|
const CFIndex* glyphToChar = nullptr;
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Testing indicates that CTRunGetGlyphsPtr (almost?) always succeeds,
|
|
|
|
// and so allocating a new array and copying data with CTRunGetGlyphs
|
|
|
|
// will be extremely rare.
|
2016-02-02 18:36:30 +03:00
|
|
|
// If this were not the case, we could use an AutoTArray<> to
|
2009-03-30 04:31:51 +04:00
|
|
|
// try and avoid the heap allocation for small runs.
|
|
|
|
// It's possible that some future change to CoreText will mean that
|
2016-02-02 18:36:30 +03:00
|
|
|
// CTRunGetGlyphsPtr fails more often; if this happens, AutoTArray<>
|
2009-03-30 04:31:51 +04:00
|
|
|
// may become an attractive option.
|
2009-10-07 19:26:58 +04:00
|
|
|
glyphs = ::CTRunGetGlyphsPtr(aCTRun);
|
2010-01-28 01:23:57 +03:00
|
|
|
if (!glyphs) {
|
2015-10-20 20:13:35 +03:00
|
|
|
glyphsArray = MakeUniqueFallible<CGGlyph[]>(numGlyphs);
|
2010-03-10 15:46:41 +03:00
|
|
|
if (!glyphsArray) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2009-10-07 19:26:58 +04:00
|
|
|
::CTRunGetGlyphs(aCTRun, ::CFRangeMake(0, 0), glyphsArray.get());
|
2009-03-30 04:31:51 +04:00
|
|
|
glyphs = glyphsArray.get();
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
positions = ::CTRunGetPositionsPtr(aCTRun);
|
2010-01-28 01:23:57 +03:00
|
|
|
if (!positions) {
|
2015-10-20 20:13:35 +03:00
|
|
|
positionsArray = MakeUniqueFallible<CGPoint[]>(numGlyphs);
|
2010-03-10 15:46:41 +03:00
|
|
|
if (!positionsArray) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2009-10-07 19:26:58 +04:00
|
|
|
::CTRunGetPositions(aCTRun, ::CFRangeMake(0, 0), positionsArray.get());
|
2009-03-30 04:31:51 +04:00
|
|
|
positions = positionsArray.get();
|
|
|
|
}
|
|
|
|
|
2012-04-20 11:04:26 +04:00
|
|
|
// Remember that the glyphToChar indices relate to the CoreText line,
|
|
|
|
// not to the beginning of the textRun, the font run,
|
|
|
|
// or the stringRange of the glyph run
|
2009-10-07 19:26:58 +04:00
|
|
|
glyphToChar = ::CTRunGetStringIndicesPtr(aCTRun);
|
2010-01-28 01:23:57 +03:00
|
|
|
if (!glyphToChar) {
|
2015-10-20 20:13:35 +03:00
|
|
|
glyphToCharArray = MakeUniqueFallible<CFIndex[]>(numGlyphs);
|
2010-03-10 15:46:41 +03:00
|
|
|
if (!glyphToCharArray) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2009-10-07 19:26:58 +04:00
|
|
|
::CTRunGetStringIndices(aCTRun, ::CFRangeMake(0, 0), glyphToCharArray.get());
|
2009-03-30 04:31:51 +04:00
|
|
|
glyphToChar = glyphToCharArray.get();
|
|
|
|
}
|
|
|
|
|
2012-04-20 11:04:26 +04:00
|
|
|
double runWidth = ::CTRunGetTypographicBounds(aCTRun, ::CFRangeMake(0, 0),
|
2013-07-31 19:44:31 +04:00
|
|
|
nullptr, nullptr, nullptr);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<gfxShapedText::DetailedGlyph,1> detailedGlyphs;
|
2017-11-11 18:32:58 +03:00
|
|
|
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// CoreText gives us the glyphindex-to-charindex mapping, which relates each glyph
|
|
|
|
// to a source text character; we also need the charindex-to-glyphindex mapping to
|
|
|
|
// find the glyph for a given char. Note that some chars may not map to any glyph
|
|
|
|
// (ligature continuations), and some may map to several glyphs (eg Indic split vowels).
|
|
|
|
// We set the glyph index to NO_GLYPH for chars that have no associated glyph, and we
|
|
|
|
// record the last glyph index for cases where the char maps to several glyphs,
|
|
|
|
// so that our clumping will include all the glyph fragments for the character.
|
2009-10-07 19:26:58 +04:00
|
|
|
|
|
|
|
// The charToGlyph array is indexed by char position within the stringRange of the glyph run.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t NO_GLYPH = -1;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<int32_t,SMALL_GLYPH_RUN> charToGlyphArray;
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!charToGlyphArray.SetLength(stringRange.length, fallible)) {
|
2009-03-30 04:31:51 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *charToGlyph = charToGlyphArray.Elements();
|
|
|
|
for (int32_t offset = 0; offset < stringRange.length; ++offset) {
|
2009-03-30 04:31:51 +04:00
|
|
|
charToGlyph[offset] = NO_GLYPH;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < numGlyphs; ++i) {
|
|
|
|
int32_t loc = glyphToChar[i] - stringRange.location;
|
2009-10-07 19:26:58 +04:00
|
|
|
if (loc >= 0 && loc < stringRange.length) {
|
2010-01-30 16:16:35 +03:00
|
|
|
charToGlyph[loc] = i;
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Find character and glyph clumps that correspond, allowing for ligatures,
|
|
|
|
// indic reordering, split glyphs, etc.
|
|
|
|
//
|
|
|
|
// The idea is that we'll find a character sequence starting at the first char of stringRange,
|
|
|
|
// and extend it until it includes the character associated with the first glyph;
|
|
|
|
// we also extend it as long as there are "holes" in the range of glyphs. So we
|
|
|
|
// will eventually have a contiguous sequence of characters, starting at the beginning
|
|
|
|
// of the range, that map to a contiguous sequence of glyphs, starting at the beginning
|
|
|
|
// of the glyph array. That's a clump; then we update the starting positions and repeat.
|
|
|
|
//
|
|
|
|
// NB: In the case of RTL layouts, we iterate over the stringRange in reverse.
|
|
|
|
//
|
2011-12-06 16:39:19 +04:00
|
|
|
|
|
|
|
// This may find characters that fall outside the range 0:wordLength,
|
2009-03-30 04:31:51 +04:00
|
|
|
// so we won't necessarily use everything we find here.
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
bool isRightToLeft = aShapedText->IsRightToLeft();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphStart = 0; // looking for a clump that starts at this glyph index
|
|
|
|
int32_t charStart = isRightToLeft ?
|
2011-12-06 16:39:19 +04:00
|
|
|
stringRange.length - 1 : 0; // and this char index (in the stringRange of the glyph run)
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
while (glyphStart < numGlyphs) { // keep finding groups until all glyphs are accounted for
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inOrder = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t charEnd = glyphToChar[glyphStart] - stringRange.location;
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
charEnd >= 0 && charEnd < stringRange.length,
|
|
|
|
"glyph-to-char mapping points outside string range");
|
2012-04-20 11:04:26 +04:00
|
|
|
// clamp charEnd to the valid range of the string
|
2013-01-15 16:22:03 +04:00
|
|
|
charEnd = std::max(charEnd, 0);
|
|
|
|
charEnd = std::min(charEnd, int32_t(stringRange.length));
|
2012-04-20 11:04:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphEnd = glyphStart;
|
|
|
|
int32_t charLimit = isRightToLeft ? -1 : stringRange.length;
|
2009-03-30 04:31:51 +04:00
|
|
|
do {
|
2009-04-25 12:24:25 +04:00
|
|
|
// This is normally executed once for each iteration of the outer loop,
|
|
|
|
// but in unusual cases where the character/glyph association is complex,
|
|
|
|
// the initial character range might correspond to a non-contiguous
|
|
|
|
// glyph range with "holes" in it. If so, we will repeat this loop to
|
|
|
|
// extend the character range until we have a contiguous glyph sequence.
|
2010-01-30 16:16:35 +03:00
|
|
|
NS_ASSERTION((direction > 0 && charEnd < charLimit) ||
|
|
|
|
(direction < 0 && charEnd > charLimit),
|
|
|
|
"no characters left in range?");
|
2009-03-30 04:31:51 +04:00
|
|
|
charEnd += direction;
|
2010-01-30 16:16:35 +03:00
|
|
|
while (charEnd != charLimit && charToGlyph[charEnd] == NO_GLYPH) {
|
2009-04-25 12:24:25 +04:00
|
|
|
charEnd += direction;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-04-25 12:24:25 +04:00
|
|
|
// find the maximum glyph index covered by the clump so far
|
2012-04-20 11:04:26 +04:00
|
|
|
if (isRightToLeft) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = charStart; i > charEnd; --i) {
|
2012-04-20 11:04:26 +04:00
|
|
|
if (charToGlyph[i] != NO_GLYPH) {
|
|
|
|
// update extent of glyph range
|
2013-01-15 16:22:03 +04:00
|
|
|
glyphEnd = std::max(glyphEnd, charToGlyph[i] + 1);
|
2012-04-20 11:04:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = charStart; i < charEnd; ++i) {
|
2012-04-20 11:04:26 +04:00
|
|
|
if (charToGlyph[i] != NO_GLYPH) {
|
|
|
|
// update extent of glyph range
|
2013-01-15 16:22:03 +04:00
|
|
|
glyphEnd = std::max(glyphEnd, charToGlyph[i] + 1);
|
2012-04-20 11:04:26 +04:00
|
|
|
}
|
2009-04-25 12:24:25 +04:00
|
|
|
}
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-04-25 12:24:25 +04:00
|
|
|
if (glyphEnd == glyphStart + 1) {
|
|
|
|
// for the common case of a single-glyph clump, we can skip the following checks
|
|
|
|
break;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-04-25 12:24:25 +04:00
|
|
|
if (glyphEnd == glyphStart) {
|
|
|
|
// no glyphs, try to extend the clump
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether all glyphs in the range are associated with the characters
|
|
|
|
// in our clump; if not, we have a discontinuous range, and should extend it
|
|
|
|
// unless we've reached the end of the text
|
2011-09-29 10:19:26 +04:00
|
|
|
bool allGlyphsAreWithinCluster = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t prevGlyphCharIndex = charStart;
|
|
|
|
for (int32_t i = glyphStart; i < glyphEnd; ++i) {
|
|
|
|
int32_t glyphCharIndex = glyphToChar[i] - stringRange.location;
|
2011-12-06 16:39:19 +04:00
|
|
|
if (isRightToLeft) {
|
|
|
|
if (glyphCharIndex > charStart || glyphCharIndex <= charEnd) {
|
2011-10-17 18:59:28 +04:00
|
|
|
allGlyphsAreWithinCluster = false;
|
2009-04-25 12:24:25 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
if (glyphCharIndex > prevGlyphCharIndex) {
|
2011-10-17 18:59:28 +04:00
|
|
|
inOrder = false;
|
2009-04-25 12:24:25 +04:00
|
|
|
}
|
|
|
|
prevGlyphCharIndex = glyphCharIndex;
|
|
|
|
} else {
|
2011-12-06 16:39:19 +04:00
|
|
|
if (glyphCharIndex < charStart || glyphCharIndex >= charEnd) {
|
2011-10-17 18:59:28 +04:00
|
|
|
allGlyphsAreWithinCluster = false;
|
2009-04-25 12:24:25 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
if (glyphCharIndex < prevGlyphCharIndex) {
|
2011-10-17 18:59:28 +04:00
|
|
|
inOrder = false;
|
2009-04-25 12:24:25 +04:00
|
|
|
}
|
|
|
|
prevGlyphCharIndex = glyphCharIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allGlyphsAreWithinCluster) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (charEnd != charLimit);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(glyphStart < glyphEnd,
|
|
|
|
"character/glyph clump contains no glyphs!");
|
2012-04-20 11:04:26 +04:00
|
|
|
if (glyphStart == glyphEnd) {
|
|
|
|
++glyphStart; // make progress - avoid potential infinite loop
|
|
|
|
charStart = charEnd;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(charStart != charEnd,
|
|
|
|
"character/glyph clump contains no characters!");
|
2012-04-20 11:04:26 +04:00
|
|
|
if (charStart == charEnd) {
|
|
|
|
glyphStart = glyphEnd; // this is bad - we'll discard the glyph(s),
|
|
|
|
// as there's nowhere to attach them
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Now charStart..charEnd is a ligature clump, corresponding to glyphStart..glyphEnd;
|
|
|
|
// Set baseCharIndex to the char we'll actually attach the glyphs to (1st of ligature),
|
2009-10-07 19:26:58 +04:00
|
|
|
// and endCharIndex to the limit (position beyond the last char),
|
|
|
|
// adjusting for the offset of the stringRange relative to the textRun.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t baseCharIndex, endCharIndex;
|
2011-12-06 16:39:19 +04:00
|
|
|
if (isRightToLeft) {
|
2010-03-10 15:46:41 +03:00
|
|
|
while (charEnd >= 0 && charToGlyph[charEnd] == NO_GLYPH) {
|
2009-03-30 04:31:51 +04:00
|
|
|
charEnd--;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2017-09-15 00:45:26 +03:00
|
|
|
baseCharIndex = charEnd + stringRange.location + 1;
|
|
|
|
endCharIndex = charStart + stringRange.location + 1;
|
2011-12-06 16:39:19 +04:00
|
|
|
} else {
|
|
|
|
while (charEnd < stringRange.length && charToGlyph[charEnd] == NO_GLYPH) {
|
|
|
|
charEnd++;
|
|
|
|
}
|
2017-09-15 00:45:26 +03:00
|
|
|
baseCharIndex = charStart + stringRange.location;
|
|
|
|
endCharIndex = charEnd + stringRange.location;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
2009-04-25 12:24:25 +04:00
|
|
|
// Then we check if the clump falls outside our actual string range; if so, just go to the next.
|
2011-12-06 16:39:19 +04:00
|
|
|
if (endCharIndex <= 0 || baseCharIndex >= wordLength) {
|
2009-03-30 04:31:51 +04:00
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
// Ensure we won't try to go beyond the valid length of the word's text
|
2013-01-15 16:22:03 +04:00
|
|
|
baseCharIndex = std::max(baseCharIndex, 0);
|
|
|
|
endCharIndex = std::min(endCharIndex, wordLength);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Now we're ready to set the glyph info in the textRun; measure the glyph width
|
|
|
|
// of the first (perhaps only) glyph, to see if it is "Simple"
|
2013-01-04 22:35:37 +04:00
|
|
|
int32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
|
2009-03-30 04:31:51 +04:00
|
|
|
double toNextGlyph;
|
2010-03-10 15:46:41 +03:00
|
|
|
if (glyphStart < numGlyphs-1) {
|
2009-03-30 04:31:51 +04:00
|
|
|
toNextGlyph = positions[glyphStart+1].x - positions[glyphStart].x;
|
2010-03-10 15:46:41 +03:00
|
|
|
} else {
|
2009-03-30 04:31:51 +04:00
|
|
|
toNextGlyph = positions[0].x + runWidth - positions[glyphStart].x;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t advance = int32_t(toNextGlyph * appUnitsPerDevUnit);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
// Check if it's a simple one-to-one mapping
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t glyphsInClump = glyphEnd - glyphStart;
|
2009-03-30 04:31:51 +04:00
|
|
|
if (glyphsInClump == 1 &&
|
|
|
|
gfxTextRun::CompressedGlyph::IsSimpleGlyphID(glyphs[glyphStart]) &&
|
|
|
|
gfxTextRun::CompressedGlyph::IsSimpleAdvance(advance) &&
|
2013-01-04 22:35:37 +04:00
|
|
|
charGlyphs[baseCharIndex].IsClusterStart() &&
|
2009-03-30 04:31:51 +04:00
|
|
|
positions[glyphStart].y == 0.0)
|
|
|
|
{
|
2013-01-04 22:35:37 +04:00
|
|
|
charGlyphs[baseCharIndex].SetSimpleGlyph(advance,
|
|
|
|
glyphs[glyphStart]);
|
2009-03-30 04:31:51 +04:00
|
|
|
} else {
|
|
|
|
// collect all glyphs in a list to be assigned to the first char;
|
|
|
|
// there must be at least one in the clump, and we already measured its advance,
|
|
|
|
// hence the placement of the loop-exit test and the measurement of the next glyph
|
2016-11-15 12:12:27 +03:00
|
|
|
while (true) {
|
2009-03-30 04:31:51 +04:00
|
|
|
gfxTextRun::DetailedGlyph *details = detailedGlyphs.AppendElement();
|
|
|
|
details->mGlyphID = glyphs[glyphStart];
|
2017-10-30 17:55:42 +03:00
|
|
|
details->mOffset.y = -positions[glyphStart].y * appUnitsPerDevUnit;
|
2009-03-30 04:31:51 +04:00
|
|
|
details->mAdvance = advance;
|
2010-03-10 15:46:41 +03:00
|
|
|
if (++glyphStart >= glyphEnd) {
|
2009-03-30 04:31:51 +04:00
|
|
|
break;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
|
|
|
if (glyphStart < numGlyphs-1) {
|
2009-03-30 04:31:51 +04:00
|
|
|
toNextGlyph = positions[glyphStart+1].x - positions[glyphStart].x;
|
2010-03-10 15:46:41 +03:00
|
|
|
} else {
|
2009-03-30 04:31:51 +04:00
|
|
|
toNextGlyph = positions[0].x + runWidth - positions[glyphStart].x;
|
2010-03-10 15:46:41 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
advance = int32_t(toNextGlyph * appUnitsPerDevUnit);
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
bool isClusterStart = charGlyphs[baseCharIndex].IsClusterStart();
|
|
|
|
aShapedText->SetGlyphs(aOffset + baseCharIndex,
|
|
|
|
CompressedGlyph::MakeComplex(isClusterStart, true,
|
|
|
|
detailedGlyphs.Length()),
|
2015-09-12 06:30:14 +03:00
|
|
|
detailedGlyphs.Elements());
|
2009-03-30 04:31:51 +04:00
|
|
|
|
|
|
|
detailedGlyphs.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// the rest of the chars in the group are ligature continuations, no associated glyphs
|
2011-12-06 16:39:19 +04:00
|
|
|
while (++baseCharIndex != endCharIndex && baseCharIndex < wordLength) {
|
2017-11-11 18:32:58 +03:00
|
|
|
CompressedGlyph &shapedTextGlyph = charGlyphs[baseCharIndex];
|
2015-09-12 06:30:14 +03:00
|
|
|
NS_ASSERTION(!shapedTextGlyph.IsSimpleGlyph(), "overwriting a simple glyph");
|
|
|
|
shapedTextGlyph.SetComplex(inOrder && shapedTextGlyph.IsClusterStart(), false, 0);
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-27 17:03:04 +04:00
|
|
|
#undef SMALL_GLYPH_RUN
|
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
// Construct the font attribute descriptor that we'll apply by default when
|
|
|
|
// creating a CTFontRef. This will turn off line-edge swashes by default,
|
|
|
|
// because we don't know the actual line breaks when doing glyph shaping.
|
|
|
|
|
|
|
|
// We also cache feature descriptors for shaping with disabled ligatures, and
|
|
|
|
// for buggy Indic AAT font workarounds, created on an as-needed basis.
|
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
#define MAX_FEATURES 5 // max used by any of our Get*Descriptor functions
|
2015-03-25 11:25:49 +03:00
|
|
|
|
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::CreateFontFeaturesDescriptor(
|
|
|
|
const std::pair<SInt16,SInt16> aFeatures[],
|
|
|
|
size_t aCount)
|
2009-03-30 04:31:51 +04:00
|
|
|
{
|
2015-03-25 11:25:49 +03:00
|
|
|
MOZ_ASSERT(aCount <= MAX_FEATURES);
|
|
|
|
|
|
|
|
CFDictionaryRef featureSettings[MAX_FEATURES];
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aCount; i++) {
|
|
|
|
CFNumberRef type = ::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&aFeatures[i].first);
|
|
|
|
CFNumberRef selector = ::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&aFeatures[i].second);
|
|
|
|
|
|
|
|
CFTypeRef keys[] = { kCTFontFeatureTypeIdentifierKey,
|
|
|
|
kCTFontFeatureSelectorIdentifierKey };
|
|
|
|
CFTypeRef values[] = { type, selector };
|
|
|
|
featureSettings[i] =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) keys,
|
|
|
|
(const void **) values,
|
|
|
|
ArrayLength(keys),
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
::CFRelease(selector);
|
|
|
|
::CFRelease(type);
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
CFArrayRef featuresArray =
|
|
|
|
::CFArrayCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) featureSettings,
|
2015-03-25 11:25:49 +03:00
|
|
|
aCount, // not ArrayLength(featureSettings), as we
|
|
|
|
// may not have used all the allocated slots
|
2009-10-07 19:26:58 +04:00
|
|
|
&kCFTypeArrayCallBacks);
|
2015-03-25 11:25:49 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < aCount; i++) {
|
|
|
|
::CFRelease(featureSettings[i]);
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
const CFTypeRef attrKeys[] = { kCTFontFeatureSettingsAttribute };
|
|
|
|
const CFTypeRef attrValues[] = { featuresArray };
|
|
|
|
CFDictionaryRef attributesDict =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) attrKeys,
|
|
|
|
(const void **) attrValues,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(attrKeys),
|
2009-10-07 19:26:58 +04:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(featuresArray);
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef descriptor =
|
2009-10-07 19:26:58 +04:00
|
|
|
::CTFontDescriptorCreateWithAttributes(attributesDict);
|
|
|
|
::CFRelease(attributesDict);
|
2015-03-25 11:25:49 +03:00
|
|
|
|
|
|
|
return descriptor;
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetDefaultFeaturesDescriptor()
|
2009-10-07 19:26:58 +04:00
|
|
|
{
|
2015-03-25 11:25:49 +03:00
|
|
|
if (sDefaultFeaturesDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kDefaultFeatures[] = {
|
|
|
|
{ kSmartSwashType, kLineInitialSwashesOffSelector },
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector }
|
|
|
|
};
|
2017-10-12 00:12:43 +03:00
|
|
|
static_assert(ArrayLength(kDefaultFeatures) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
2015-03-25 11:25:49 +03:00
|
|
|
sDefaultFeaturesDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kDefaultFeatures,
|
|
|
|
ArrayLength(kDefaultFeatures));
|
|
|
|
}
|
|
|
|
return sDefaultFeaturesDescriptor;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetSmallCapsDescriptor()
|
|
|
|
{
|
|
|
|
if (sSmallCapsDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kSmallCaps[] = {
|
|
|
|
{ kSmartSwashType, kLineInitialSwashesOffSelector },
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector },
|
|
|
|
{ kLetterCaseType, kSmallCapsSelector },
|
|
|
|
{ kLowerCaseType, kLowerCaseSmallCapsSelector }
|
|
|
|
};
|
|
|
|
static_assert(ArrayLength(kSmallCaps) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
|
|
|
sSmallCapsDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kSmallCaps,
|
|
|
|
ArrayLength(kSmallCaps));
|
|
|
|
}
|
|
|
|
return sSmallCapsDescriptor;
|
|
|
|
}
|
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetDisableLigaturesDescriptor()
|
|
|
|
{
|
|
|
|
if (sDisableLigaturesDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kDisableLigatures[] = {
|
|
|
|
{ kSmartSwashType, kLineInitialSwashesOffSelector },
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector },
|
|
|
|
{ kLigaturesType, kCommonLigaturesOffSelector }
|
|
|
|
};
|
2017-10-12 00:12:43 +03:00
|
|
|
static_assert(ArrayLength(kDisableLigatures) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
2015-03-25 11:25:49 +03:00
|
|
|
sDisableLigaturesDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kDisableLigatures,
|
|
|
|
ArrayLength(kDisableLigatures));
|
|
|
|
}
|
|
|
|
return sDisableLigaturesDescriptor;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetSmallCapDisableLigDescriptor()
|
|
|
|
{
|
|
|
|
if (sSmallCapDisableLigDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kFeatures[] = {
|
|
|
|
{ kSmartSwashType, kLineInitialSwashesOffSelector },
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector },
|
|
|
|
{ kLigaturesType, kCommonLigaturesOffSelector },
|
|
|
|
{ kLetterCaseType, kSmallCapsSelector },
|
|
|
|
{ kLowerCaseType, kLowerCaseSmallCapsSelector }
|
|
|
|
};
|
|
|
|
static_assert(ArrayLength(kFeatures) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
|
|
|
sSmallCapDisableLigDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kFeatures,
|
|
|
|
ArrayLength(kFeatures));
|
|
|
|
}
|
|
|
|
return sSmallCapDisableLigDescriptor;
|
|
|
|
}
|
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetIndicFeaturesDescriptor()
|
|
|
|
{
|
|
|
|
if (sIndicFeaturesDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kIndicFeatures[] = {
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector }
|
|
|
|
};
|
2017-10-12 00:12:43 +03:00
|
|
|
static_assert(ArrayLength(kIndicFeatures) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
2015-03-25 11:25:49 +03:00
|
|
|
sIndicFeaturesDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kIndicFeatures,
|
|
|
|
ArrayLength(kIndicFeatures));
|
|
|
|
}
|
|
|
|
return sIndicFeaturesDescriptor;
|
|
|
|
}
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontDescriptorRef
|
|
|
|
gfxCoreTextShaper::GetIndicDisableLigaturesDescriptor()
|
|
|
|
{
|
|
|
|
if (sIndicDisableLigaturesDescriptor == nullptr) {
|
|
|
|
const std::pair<SInt16,SInt16> kIndicDisableLigatures[] = {
|
|
|
|
{ kSmartSwashType, kLineFinalSwashesOffSelector },
|
|
|
|
{ kLigaturesType, kCommonLigaturesOffSelector }
|
|
|
|
};
|
2017-10-12 00:12:43 +03:00
|
|
|
static_assert(ArrayLength(kIndicDisableLigatures) <= MAX_FEATURES,
|
|
|
|
"need to increase MAX_FEATURES");
|
2015-03-25 11:25:49 +03:00
|
|
|
sIndicDisableLigaturesDescriptor =
|
|
|
|
CreateFontFeaturesDescriptor(kIndicDisableLigatures,
|
|
|
|
ArrayLength(kIndicDisableLigatures));
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
2015-03-25 11:25:49 +03:00
|
|
|
return sIndicDisableLigaturesDescriptor;
|
|
|
|
}
|
2011-06-24 21:55:27 +04:00
|
|
|
|
2015-03-25 11:25:49 +03:00
|
|
|
CTFontRef
|
|
|
|
gfxCoreTextShaper::CreateCTFontWithFeatures(CGFloat aSize,
|
|
|
|
CTFontDescriptorRef aDescriptor)
|
|
|
|
{
|
2017-01-06 19:35:12 +03:00
|
|
|
CGFontRef cgFont = static_cast<gfxMacFont*>(mFont)->GetCGFontRef();
|
|
|
|
return gfxMacFont::CreateCTFontFromCGFontWithVariations(cgFont, aSize,
|
|
|
|
aDescriptor);
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-10 15:46:41 +03:00
|
|
|
gfxCoreTextShaper::Shutdown() // [static]
|
2009-03-30 04:31:51 +04:00
|
|
|
{
|
2015-03-25 11:25:49 +03:00
|
|
|
if (sIndicDisableLigaturesDescriptor != nullptr) {
|
|
|
|
::CFRelease(sIndicDisableLigaturesDescriptor);
|
|
|
|
sIndicDisableLigaturesDescriptor = nullptr;
|
|
|
|
}
|
|
|
|
if (sIndicFeaturesDescriptor != nullptr) {
|
|
|
|
::CFRelease(sIndicFeaturesDescriptor);
|
|
|
|
sIndicFeaturesDescriptor = nullptr;
|
|
|
|
}
|
2013-07-31 19:44:31 +04:00
|
|
|
if (sDisableLigaturesDescriptor != nullptr) {
|
2009-10-07 19:26:58 +04:00
|
|
|
::CFRelease(sDisableLigaturesDescriptor);
|
2013-07-31 19:44:31 +04:00
|
|
|
sDisableLigaturesDescriptor = nullptr;
|
2015-03-25 11:25:49 +03:00
|
|
|
}
|
2013-07-31 19:44:31 +04:00
|
|
|
if (sDefaultFeaturesDescriptor != nullptr) {
|
2009-10-07 19:26:58 +04:00
|
|
|
::CFRelease(sDefaultFeaturesDescriptor);
|
2013-07-31 19:44:31 +04:00
|
|
|
sDefaultFeaturesDescriptor = nullptr;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
}
|