2009-03-29 17:31:51 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2010-03-10 04:46:41 -08:00
|
|
|
#include "gfxCoreTextShaper.h"
|
|
|
|
#include "gfxMacFont.h"
|
2009-03-29 17:31:51 -07:00
|
|
|
#include "gfxFontUtils.h"
|
2014-09-16 02:58:12 -07:00
|
|
|
#include "gfxTextRun.h"
|
2013-10-07 16:15:59 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-03-29 17:31:51 -07:00
|
|
|
// standard font descriptors that we construct the first time they're needed
|
2013-07-31 08:44:31 -07:00
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sDefaultFeaturesDescriptor = nullptr;
|
|
|
|
CTFontDescriptorRef gfxCoreTextShaper::sDisableLigaturesDescriptor = nullptr;
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2010-03-10 04:46:41 -08:00
|
|
|
gfxCoreTextShaper::gfxCoreTextShaper(gfxMacFont *aFont)
|
|
|
|
: gfxFontShaper(aFont)
|
2009-07-16 03:00:38 -07:00
|
|
|
{
|
2010-03-10 04:46:41 -08:00
|
|
|
// Create our CTFontRef
|
2012-11-19 02:01:43 -08:00
|
|
|
mCTFont = ::CTFontCreateWithGraphicsFont(aFont->GetCGFontRef(),
|
|
|
|
aFont->GetAdjustedSize(),
|
2013-07-31 08:44:31 -07:00
|
|
|
nullptr,
|
2012-11-19 02:01:43 -08:00
|
|
|
GetDefaultFeaturesDescriptor());
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// Set up the default attribute dictionary that we will need each time we create a CFAttributedString
|
2010-03-10 04:46:41 -08:00
|
|
|
mAttributesDict = ::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void**) &kCTFontAttributeName,
|
|
|
|
(const void**) &mCTFont,
|
|
|
|
1, // count of attributes
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
2010-03-10 04:46:41 -08:00
|
|
|
gfxCoreTextShaper::~gfxCoreTextShaper()
|
2009-03-29 17:31:51 -07:00
|
|
|
{
|
2010-03-10 04:46:41 -08:00
|
|
|
if (mAttributesDict) {
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(mAttributesDict);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
2010-03-10 04:46:41 -08:00
|
|
|
if (mCTFont) {
|
|
|
|
::CFRelease(mCTFont);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxCoreTextShaper::ShapeText(gfxContext *aContext,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aText,
|
2013-01-04 10:35:37 -08:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 12:25:48 -07:00
|
|
|
bool aVertical,
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText *aShapedText)
|
2009-03-29 17:31:51 -07:00
|
|
|
{
|
2009-10-07 08:26:58 -07:00
|
|
|
// Create a CFAttributedString with text and style info, so we can use CoreText to lay it out.
|
2009-07-16 03:00:38 -07:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
bool isRightToLeft = aShapedText->IsRightToLeft();
|
|
|
|
uint32_t length = aLength;
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
// we need to bidi-wrap the text if the run is RTL,
|
|
|
|
// or if it is an LTR run but may contain (overridden) RTL chars
|
2011-12-06 04:39:19 -08:00
|
|
|
bool bidiWrap = isRightToLeft;
|
2013-01-04 10:35:37 -08:00
|
|
|
if (!bidiWrap && !aShapedText->TextIs8Bit()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2011-12-06 04:39:19 -08:00
|
|
|
for (i = 0; i < length; ++i) {
|
2013-01-04 10:35:37 -08:00
|
|
|
if (gfxFontUtils::PotentialRTLChar(aText[i])) {
|
2011-10-17 07:59:28 -07:00
|
|
|
bidiWrap = true;
|
2009-03-29 17:31:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
// If there's a possibility of any bidi, we wrap the text with direction overrides
|
|
|
|
// to ensure neutrals or characters that were bidi-overridden in HTML behave properly.
|
2010-01-26 23:46:31 -08:00
|
|
|
const UniChar beginLTR[] = { 0x202d, 0x20 };
|
|
|
|
const UniChar beginRTL[] = { 0x202e, 0x20 };
|
2010-04-07 02:18:57 -07:00
|
|
|
const UniChar endBidiWrap[] = { 0x20, 0x2e, 0x202c };
|
2009-10-07 08:26:58 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t startOffset;
|
2009-10-07 08:26:58 -07:00
|
|
|
CFStringRef stringObj;
|
|
|
|
if (bidiWrap) {
|
2011-12-06 04:39:19 -08:00
|
|
|
startOffset = isRightToLeft ?
|
|
|
|
mozilla::ArrayLength(beginRTL) : mozilla::ArrayLength(beginLTR);
|
2009-10-07 08:26:58 -07:00
|
|
|
CFMutableStringRef mutableString =
|
|
|
|
::CFStringCreateMutable(kCFAllocatorDefault,
|
2011-12-06 04:39:19 -08:00
|
|
|
length + startOffset + mozilla::ArrayLength(endBidiWrap));
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFStringAppendCharacters(mutableString,
|
2011-12-06 04:39:19 -08:00
|
|
|
isRightToLeft ? beginRTL : beginLTR,
|
2009-10-07 08:26:58 -07:00
|
|
|
startOffset);
|
2013-10-10 09:59:40 -07:00
|
|
|
::CFStringAppendCharacters(mutableString, reinterpret_cast<const UniChar*>(aText), length);
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFStringAppendCharacters(mutableString,
|
2011-12-06 04:39:19 -08:00
|
|
|
endBidiWrap, mozilla::ArrayLength(endBidiWrap));
|
2009-10-07 08:26:58 -07:00
|
|
|
stringObj = mutableString;
|
|
|
|
} else {
|
|
|
|
startOffset = 0;
|
|
|
|
stringObj = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault,
|
2013-10-10 09:59:40 -07:00
|
|
|
reinterpret_cast<const UniChar*>(aText),
|
|
|
|
length, kCFAllocatorNull);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CFDictionaryRef attrObj;
|
2013-01-04 10:35:37 -08:00
|
|
|
if (aShapedText->DisableLigatures()) {
|
2009-03-29 17:31:51 -07:00
|
|
|
// For letterspacing (or maybe other situations) we need to make a copy of the CTFont
|
|
|
|
// with the ligature feature disabled
|
2009-07-16 03:00:38 -07:00
|
|
|
CTFontRef ctFont =
|
2011-06-24 10:55:27 -07:00
|
|
|
CreateCTFontWithDisabledLigatures(::CTFontGetSize(mCTFont));
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
attrObj =
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void**) &kCTFontAttributeName,
|
|
|
|
(const void**) &ctFont,
|
|
|
|
1, // count of attributes
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2009-07-16 03:00:38 -07:00
|
|
|
// Having created the dict, we're finished with our ligature-disabled CTFontRef
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(ctFont);
|
2009-03-29 17:31:51 -07:00
|
|
|
} else {
|
2010-03-10 04:46:41 -08:00
|
|
|
attrObj = mAttributesDict;
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRetain(attrObj);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we can create an attributed string
|
|
|
|
CFAttributedStringRef attrStringObj =
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFAttributedStringCreate(kCFAllocatorDefault, stringObj, attrObj);
|
|
|
|
::CFRelease(stringObj);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// Create the CoreText line from our string, then we're done with it
|
2009-10-07 08:26:58 -07:00
|
|
|
CTLineRef line = ::CTLineCreateWithAttributedString(attrStringObj);
|
|
|
|
::CFRelease(attrStringObj);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// and finally retrieve the glyph data and store into the gfxTextRun
|
2009-10-07 08:26:58 -07:00
|
|
|
CFArrayRef glyphRuns = ::CTLineGetGlyphRuns(line);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t numRuns = ::CFArrayGetCount(glyphRuns);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
// Iterate through the glyph runs.
|
|
|
|
// Note that this includes the bidi wrapper, so we have to be careful
|
|
|
|
// not to include the extra glyphs from there
|
2011-09-28 23:19:26 -07:00
|
|
|
bool success = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t runIndex = 0; runIndex < numRuns; runIndex++) {
|
2011-12-06 04:39:19 -08:00
|
|
|
CTRunRef aCTRun =
|
|
|
|
(CTRunRef)::CFArrayGetValueAtIndex(glyphRuns, runIndex);
|
2014-09-26 01:20:20 -07: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)...
|
|
|
|
const void* font1 = ::CFDictionaryGetValue(attrObj, kCTFontAttributeName);
|
|
|
|
const void* font2 = ::CFDictionaryGetValue(runAttr, kCTFontAttributeName);
|
|
|
|
if (font1 != font2) {
|
|
|
|
// ...except that if the fallback was only for a variation
|
|
|
|
// selector that is otherwise unsupported, we just ignore it.
|
|
|
|
CFRange range = ::CTRunGetStringRange(aCTRun);
|
|
|
|
if (range.length == 1 &&
|
|
|
|
gfxFontUtils::IsVarSelector(aText[range.location -
|
|
|
|
startOffset])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NS_WARNING("unexpected font fallback in Core Text");
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 10:35:37 -08:00
|
|
|
if (SetGlyphsFromRun(aShapedText, aOffset, aLength, aCTRun, startOffset) != NS_OK) {
|
2011-10-17 07:59:28 -07:00
|
|
|
success = false;
|
2009-03-29 17:31:51 -07:00
|
|
|
break;
|
2010-03-15 02:34:25 -07:00
|
|
|
}
|
2009-10-07 08:26:58 -07:00
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2014-09-26 01:20:20 -07:00
|
|
|
::CFRelease(attrObj);
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(line);
|
2010-03-15 02:34:25 -07:00
|
|
|
|
|
|
|
return success;
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 08:26:58 -07: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-29 17:31:51 -07:00
|
|
|
nsresult
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
CTRunRef aCTRun,
|
|
|
|
int32_t aStringOffset)
|
2009-03-29 17:31:51 -07:00
|
|
|
{
|
2011-12-06 04:39:19 -08:00
|
|
|
// The word has been bidi-wrapped; aStringOffset is the number
|
2009-10-07 08:26:58 -07:00
|
|
|
// of chars at the beginning of the CTLine that we should skip.
|
2009-03-29 17:31:51 -07:00
|
|
|
// aCTRun is a glyph run from the CoreText layout process.
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
int32_t direction = aShapedText->IsRightToLeft() ? -1 : 1;
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numGlyphs = ::CTRunGetGlyphCount(aCTRun);
|
2010-03-10 04:46:41 -08:00
|
|
|
if (numGlyphs == 0) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_OK;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
int32_t wordLength = aLength;
|
2011-12-06 04:39:19 -08:00
|
|
|
|
2009-10-07 08:26:58 -07: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
|
|
|
|
// plus directional-override padding
|
|
|
|
// (d) the CTRun currently being processed, which may be a sub-run of the CoreText line
|
|
|
|
// (but may extend beyond the actual font run into the bidi wrapping text).
|
|
|
|
// aStringOffset tells us how many initial characters of the line to ignore.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
if (stringRange.location - aStringOffset + stringRange.length <= 0 ||
|
2011-12-06 04:39:19 -08:00
|
|
|
stringRange.location - aStringOffset >= wordLength) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_OK;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// retrieve the laid-out glyph data from the CTRun
|
|
|
|
nsAutoArrayPtr<CGGlyph> glyphsArray;
|
|
|
|
nsAutoArrayPtr<CGPoint> positionsArray;
|
|
|
|
nsAutoArrayPtr<CFIndex> glyphToCharArray;
|
2013-07-31 08:44:31 -07:00
|
|
|
const CGGlyph* glyphs = nullptr;
|
|
|
|
const CGPoint* positions = nullptr;
|
|
|
|
const CFIndex* glyphToChar = nullptr;
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// Testing indicates that CTRunGetGlyphsPtr (almost?) always succeeds,
|
|
|
|
// and so allocating a new array and copying data with CTRunGetGlyphs
|
|
|
|
// will be extremely rare.
|
|
|
|
// If this were not the case, we could use an nsAutoTArray<> to
|
|
|
|
// try and avoid the heap allocation for small runs.
|
|
|
|
// It's possible that some future change to CoreText will mean that
|
|
|
|
// CTRunGetGlyphsPtr fails more often; if this happens, nsAutoTArray<>
|
|
|
|
// may become an attractive option.
|
2009-10-07 08:26:58 -07:00
|
|
|
glyphs = ::CTRunGetGlyphsPtr(aCTRun);
|
2010-01-27 14:23:57 -08:00
|
|
|
if (!glyphs) {
|
|
|
|
glyphsArray = new (std::nothrow) CGGlyph[numGlyphs];
|
2010-03-10 04:46:41 -08:00
|
|
|
if (!glyphsArray) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-10-07 08:26:58 -07:00
|
|
|
::CTRunGetGlyphs(aCTRun, ::CFRangeMake(0, 0), glyphsArray.get());
|
2009-03-29 17:31:51 -07:00
|
|
|
glyphs = glyphsArray.get();
|
|
|
|
}
|
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
positions = ::CTRunGetPositionsPtr(aCTRun);
|
2010-01-27 14:23:57 -08:00
|
|
|
if (!positions) {
|
|
|
|
positionsArray = new (std::nothrow) CGPoint[numGlyphs];
|
2010-03-10 04:46:41 -08:00
|
|
|
if (!positionsArray) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-10-07 08:26:58 -07:00
|
|
|
::CTRunGetPositions(aCTRun, ::CFRangeMake(0, 0), positionsArray.get());
|
2009-03-29 17:31:51 -07:00
|
|
|
positions = positionsArray.get();
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:04:26 -07: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 08:26:58 -07:00
|
|
|
glyphToChar = ::CTRunGetStringIndicesPtr(aCTRun);
|
2010-01-27 14:23:57 -08:00
|
|
|
if (!glyphToChar) {
|
|
|
|
glyphToCharArray = new (std::nothrow) CFIndex[numGlyphs];
|
2010-03-10 04:46:41 -08:00
|
|
|
if (!glyphToCharArray) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-10-07 08:26:58 -07:00
|
|
|
::CTRunGetStringIndices(aCTRun, ::CFRangeMake(0, 0), glyphToCharArray.get());
|
2009-03-29 17:31:51 -07:00
|
|
|
glyphToChar = glyphToCharArray.get();
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:04:26 -07:00
|
|
|
double runWidth = ::CTRunGetTypographicBounds(aCTRun, ::CFRangeMake(0, 0),
|
2013-07-31 08:44:31 -07:00
|
|
|
nullptr, nullptr, nullptr);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
nsAutoTArray<gfxShapedText::DetailedGlyph,1> detailedGlyphs;
|
|
|
|
gfxShapedText::CompressedGlyph g;
|
|
|
|
gfxShapedText::CompressedGlyph *charGlyphs =
|
|
|
|
aShapedText->GetCharacterGlyphs() + aOffset;
|
2009-03-29 17:31:51 -07: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 08:26:58 -07:00
|
|
|
|
|
|
|
// The charToGlyph array is indexed by char position within the stringRange of the glyph run.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t NO_GLYPH = -1;
|
2014-02-08 10:10:07 -08:00
|
|
|
AutoFallibleTArray<int32_t,SMALL_GLYPH_RUN> charToGlyphArray;
|
2010-03-10 04:46:41 -08:00
|
|
|
if (!charToGlyphArray.SetLength(stringRange.length)) {
|
2009-03-29 17:31:51 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *charToGlyph = charToGlyphArray.Elements();
|
|
|
|
for (int32_t offset = 0; offset < stringRange.length; ++offset) {
|
2009-03-29 17:31:51 -07:00
|
|
|
charToGlyph[offset] = NO_GLYPH;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < numGlyphs; ++i) {
|
|
|
|
int32_t loc = glyphToChar[i] - stringRange.location;
|
2009-10-07 08:26:58 -07:00
|
|
|
if (loc >= 0 && loc < stringRange.length) {
|
2010-01-30 05:16:35 -08:00
|
|
|
charToGlyph[loc] = i;
|
2009-10-07 08:26:58 -07:00
|
|
|
}
|
|
|
|
}
|
2009-03-29 17:31:51 -07: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 04:39:19 -08:00
|
|
|
|
|
|
|
// This may find characters that fall outside the range 0:wordLength,
|
2009-03-29 17:31:51 -07:00
|
|
|
// so we won't necessarily use everything we find here.
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
bool isRightToLeft = aShapedText->IsRightToLeft();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t glyphStart = 0; // looking for a clump that starts at this glyph index
|
|
|
|
int32_t charStart = isRightToLeft ?
|
2011-12-06 04:39:19 -08:00
|
|
|
stringRange.length - 1 : 0; // and this char index (in the stringRange of the glyph run)
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
while (glyphStart < numGlyphs) { // keep finding groups until all glyphs are accounted for
|
2011-09-28 23:19:26 -07:00
|
|
|
bool inOrder = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t charEnd = glyphToChar[glyphStart] - stringRange.location;
|
2012-04-20 00:04:26 -07:00
|
|
|
NS_WARN_IF_FALSE(charEnd >= 0 && charEnd < stringRange.length,
|
|
|
|
"glyph-to-char mapping points outside string range");
|
|
|
|
// clamp charEnd to the valid range of the string
|
2013-01-15 04:22:03 -08:00
|
|
|
charEnd = std::max(charEnd, 0);
|
|
|
|
charEnd = std::min(charEnd, int32_t(stringRange.length));
|
2012-04-20 00:04:26 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t glyphEnd = glyphStart;
|
|
|
|
int32_t charLimit = isRightToLeft ? -1 : stringRange.length;
|
2009-03-29 17:31:51 -07:00
|
|
|
do {
|
2009-04-25 01:24:25 -07: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 05:16:35 -08:00
|
|
|
NS_ASSERTION((direction > 0 && charEnd < charLimit) ||
|
|
|
|
(direction < 0 && charEnd > charLimit),
|
|
|
|
"no characters left in range?");
|
2009-03-29 17:31:51 -07:00
|
|
|
charEnd += direction;
|
2010-01-30 05:16:35 -08:00
|
|
|
while (charEnd != charLimit && charToGlyph[charEnd] == NO_GLYPH) {
|
2009-04-25 01:24:25 -07:00
|
|
|
charEnd += direction;
|
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-04-25 01:24:25 -07:00
|
|
|
// find the maximum glyph index covered by the clump so far
|
2012-04-20 00:04:26 -07:00
|
|
|
if (isRightToLeft) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = charStart; i > charEnd; --i) {
|
2012-04-20 00:04:26 -07:00
|
|
|
if (charToGlyph[i] != NO_GLYPH) {
|
|
|
|
// update extent of glyph range
|
2013-01-15 04:22:03 -08:00
|
|
|
glyphEnd = std::max(glyphEnd, charToGlyph[i] + 1);
|
2012-04-20 00:04:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = charStart; i < charEnd; ++i) {
|
2012-04-20 00:04:26 -07:00
|
|
|
if (charToGlyph[i] != NO_GLYPH) {
|
|
|
|
// update extent of glyph range
|
2013-01-15 04:22:03 -08:00
|
|
|
glyphEnd = std::max(glyphEnd, charToGlyph[i] + 1);
|
2012-04-20 00:04:26 -07:00
|
|
|
}
|
2009-04-25 01:24:25 -07:00
|
|
|
}
|
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-04-25 01:24:25 -07:00
|
|
|
if (glyphEnd == glyphStart + 1) {
|
|
|
|
// for the common case of a single-glyph clump, we can skip the following checks
|
|
|
|
break;
|
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-04-25 01:24:25 -07: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-28 23:19:26 -07:00
|
|
|
bool allGlyphsAreWithinCluster = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t prevGlyphCharIndex = charStart;
|
|
|
|
for (int32_t i = glyphStart; i < glyphEnd; ++i) {
|
|
|
|
int32_t glyphCharIndex = glyphToChar[i] - stringRange.location;
|
2011-12-06 04:39:19 -08:00
|
|
|
if (isRightToLeft) {
|
|
|
|
if (glyphCharIndex > charStart || glyphCharIndex <= charEnd) {
|
2011-10-17 07:59:28 -07:00
|
|
|
allGlyphsAreWithinCluster = false;
|
2009-04-25 01:24:25 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
if (glyphCharIndex > prevGlyphCharIndex) {
|
2011-10-17 07:59:28 -07:00
|
|
|
inOrder = false;
|
2009-04-25 01:24:25 -07:00
|
|
|
}
|
|
|
|
prevGlyphCharIndex = glyphCharIndex;
|
|
|
|
} else {
|
2011-12-06 04:39:19 -08:00
|
|
|
if (glyphCharIndex < charStart || glyphCharIndex >= charEnd) {
|
2011-10-17 07:59:28 -07:00
|
|
|
allGlyphsAreWithinCluster = false;
|
2009-04-25 01:24:25 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
if (glyphCharIndex < prevGlyphCharIndex) {
|
2011-10-17 07:59:28 -07:00
|
|
|
inOrder = false;
|
2009-04-25 01:24:25 -07:00
|
|
|
}
|
|
|
|
prevGlyphCharIndex = glyphCharIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allGlyphsAreWithinCluster) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (charEnd != charLimit);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2012-04-20 00:04:26 -07:00
|
|
|
NS_WARN_IF_FALSE(glyphStart < glyphEnd,
|
|
|
|
"character/glyph clump contains no glyphs!");
|
|
|
|
if (glyphStart == glyphEnd) {
|
|
|
|
++glyphStart; // make progress - avoid potential infinite loop
|
|
|
|
charStart = charEnd;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARN_IF_FALSE(charStart != charEnd,
|
|
|
|
"character/glyph clump contains no characters!");
|
|
|
|
if (charStart == charEnd) {
|
|
|
|
glyphStart = glyphEnd; // this is bad - we'll discard the glyph(s),
|
|
|
|
// as there's nowhere to attach them
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-29 17:31:51 -07: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 08:26:58 -07: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 08:56:38 -07:00
|
|
|
int32_t baseCharIndex, endCharIndex;
|
2011-12-06 04:39:19 -08:00
|
|
|
if (isRightToLeft) {
|
2010-03-10 04:46:41 -08:00
|
|
|
while (charEnd >= 0 && charToGlyph[charEnd] == NO_GLYPH) {
|
2009-03-29 17:31:51 -07:00
|
|
|
charEnd--;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
baseCharIndex = charEnd + stringRange.location - aStringOffset + 1;
|
|
|
|
endCharIndex = charStart + stringRange.location - aStringOffset + 1;
|
|
|
|
} else {
|
|
|
|
while (charEnd < stringRange.length && charToGlyph[charEnd] == NO_GLYPH) {
|
|
|
|
charEnd++;
|
|
|
|
}
|
|
|
|
baseCharIndex = charStart + stringRange.location - aStringOffset;
|
|
|
|
endCharIndex = charEnd + stringRange.location - aStringOffset;
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
2009-04-25 01:24:25 -07:00
|
|
|
// Then we check if the clump falls outside our actual string range; if so, just go to the next.
|
2011-12-06 04:39:19 -08:00
|
|
|
if (endCharIndex <= 0 || baseCharIndex >= wordLength) {
|
2009-03-29 17:31:51 -07:00
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-06 04:39:19 -08:00
|
|
|
// Ensure we won't try to go beyond the valid length of the word's text
|
2013-01-15 04:22:03 -08:00
|
|
|
baseCharIndex = std::max(baseCharIndex, 0);
|
|
|
|
endCharIndex = std::min(endCharIndex, wordLength);
|
2009-03-29 17:31:51 -07: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 10:35:37 -08:00
|
|
|
int32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
|
2009-03-29 17:31:51 -07:00
|
|
|
double toNextGlyph;
|
2010-03-10 04:46:41 -08:00
|
|
|
if (glyphStart < numGlyphs-1) {
|
2009-03-29 17:31:51 -07:00
|
|
|
toNextGlyph = positions[glyphStart+1].x - positions[glyphStart].x;
|
2010-03-10 04:46:41 -08:00
|
|
|
} else {
|
2009-03-29 17:31:51 -07:00
|
|
|
toNextGlyph = positions[0].x + runWidth - positions[glyphStart].x;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t advance = int32_t(toNextGlyph * appUnitsPerDevUnit);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
// Check if it's a simple one-to-one mapping
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t glyphsInClump = glyphEnd - glyphStart;
|
2009-03-29 17:31:51 -07:00
|
|
|
if (glyphsInClump == 1 &&
|
|
|
|
gfxTextRun::CompressedGlyph::IsSimpleGlyphID(glyphs[glyphStart]) &&
|
|
|
|
gfxTextRun::CompressedGlyph::IsSimpleAdvance(advance) &&
|
2013-01-04 10:35:37 -08:00
|
|
|
charGlyphs[baseCharIndex].IsClusterStart() &&
|
2009-03-29 17:31:51 -07:00
|
|
|
positions[glyphStart].y == 0.0)
|
|
|
|
{
|
2013-01-04 10:35:37 -08:00
|
|
|
charGlyphs[baseCharIndex].SetSimpleGlyph(advance,
|
|
|
|
glyphs[glyphStart]);
|
2009-03-29 17:31:51 -07: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
|
|
|
|
while (1) {
|
|
|
|
gfxTextRun::DetailedGlyph *details = detailedGlyphs.AppendElement();
|
|
|
|
details->mGlyphID = glyphs[glyphStart];
|
|
|
|
details->mXOffset = 0;
|
|
|
|
details->mYOffset = -positions[glyphStart].y * appUnitsPerDevUnit;
|
|
|
|
details->mAdvance = advance;
|
2010-03-10 04:46:41 -08:00
|
|
|
if (++glyphStart >= glyphEnd) {
|
2009-03-29 17:31:51 -07:00
|
|
|
break;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
|
|
|
if (glyphStart < numGlyphs-1) {
|
2009-03-29 17:31:51 -07:00
|
|
|
toNextGlyph = positions[glyphStart+1].x - positions[glyphStart].x;
|
2010-03-10 04:46:41 -08:00
|
|
|
} else {
|
2009-03-29 17:31:51 -07:00
|
|
|
toNextGlyph = positions[0].x + runWidth - positions[glyphStart].x;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
advance = int32_t(toNextGlyph * appUnitsPerDevUnit);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxTextRun::CompressedGlyph g;
|
2013-01-04 10:35:37 -08:00
|
|
|
g.SetComplex(charGlyphs[baseCharIndex].IsClusterStart(),
|
2011-10-17 07:59:28 -07:00
|
|
|
true, detailedGlyphs.Length());
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->SetGlyphs(aOffset + baseCharIndex, g, detailedGlyphs.Elements());
|
2009-03-29 17:31:51 -07:00
|
|
|
|
|
|
|
detailedGlyphs.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// the rest of the chars in the group are ligature continuations, no associated glyphs
|
2011-12-06 04:39:19 -08:00
|
|
|
while (++baseCharIndex != endCharIndex && baseCharIndex < wordLength) {
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph &g = charGlyphs[baseCharIndex];
|
|
|
|
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
|
|
|
|
g.SetComplex(inOrder && g.IsClusterStart(), false, 0);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
glyphStart = glyphEnd;
|
|
|
|
charStart = charEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-27 05:03:04 -08:00
|
|
|
#undef SMALL_GLYPH_RUN
|
|
|
|
|
2009-10-07 08:26:58 -07: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.
|
|
|
|
void
|
2010-03-10 04:46:41 -08:00
|
|
|
gfxCoreTextShaper::CreateDefaultFeaturesDescriptor()
|
2009-03-29 17:31:51 -07:00
|
|
|
{
|
2013-07-31 08:44:31 -07:00
|
|
|
if (sDefaultFeaturesDescriptor != nullptr) {
|
2009-10-07 08:26:58 -07:00
|
|
|
return;
|
2010-03-10 04:46:41 -08:00
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
SInt16 val = kSmartSwashType;
|
|
|
|
CFNumberRef swashesType =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&val);
|
|
|
|
val = kLineInitialSwashesOffSelector;
|
|
|
|
CFNumberRef lineInitialsOffSelector =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&val);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
CFTypeRef keys[] = { kCTFontFeatureTypeIdentifierKey,
|
|
|
|
kCTFontFeatureSelectorIdentifierKey };
|
|
|
|
CFTypeRef values[] = { swashesType,
|
|
|
|
lineInitialsOffSelector };
|
|
|
|
CFDictionaryRef featureSettings[2];
|
|
|
|
featureSettings[0] =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) keys,
|
|
|
|
(const void **) values,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(keys),
|
2009-10-07 08:26:58 -07:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(lineInitialsOffSelector);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
val = kLineFinalSwashesOffSelector;
|
|
|
|
CFNumberRef lineFinalsOffSelector =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&val);
|
|
|
|
values[1] = lineFinalsOffSelector;
|
|
|
|
featureSettings[1] =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) keys,
|
|
|
|
(const void **) values,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(keys),
|
2009-10-07 08:26:58 -07:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(lineFinalsOffSelector);
|
|
|
|
::CFRelease(swashesType);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
CFArrayRef featuresArray =
|
|
|
|
::CFArrayCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) featureSettings,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(featureSettings),
|
2009-10-07 08:26:58 -07:00
|
|
|
&kCFTypeArrayCallBacks);
|
|
|
|
::CFRelease(featureSettings[0]);
|
|
|
|
::CFRelease(featureSettings[1]);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
const CFTypeRef attrKeys[] = { kCTFontFeatureSettingsAttribute };
|
|
|
|
const CFTypeRef attrValues[] = { featuresArray };
|
|
|
|
CFDictionaryRef attributesDict =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) attrKeys,
|
|
|
|
(const void **) attrValues,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(attrKeys),
|
2009-10-07 08:26:58 -07:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(featuresArray);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
sDefaultFeaturesDescriptor =
|
|
|
|
::CTFontDescriptorCreateWithAttributes(attributesDict);
|
|
|
|
::CFRelease(attributesDict);
|
|
|
|
}
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
// Create a CTFontRef, with the Common Ligatures feature disabled
|
2009-10-07 08:26:58 -07:00
|
|
|
CTFontRef
|
2011-06-24 10:55:27 -07:00
|
|
|
gfxCoreTextShaper::CreateCTFontWithDisabledLigatures(CGFloat aSize)
|
2009-10-07 08:26:58 -07:00
|
|
|
{
|
2013-07-31 08:44:31 -07:00
|
|
|
if (sDisableLigaturesDescriptor == nullptr) {
|
2009-10-07 08:26:58 -07:00
|
|
|
// initialize cached descriptor to turn off the Common Ligatures feature
|
|
|
|
SInt16 val = kLigaturesType;
|
|
|
|
CFNumberRef ligaturesType =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&val);
|
|
|
|
val = kCommonLigaturesOffSelector;
|
|
|
|
CFNumberRef commonLigaturesOffSelector =
|
|
|
|
::CFNumberCreate(kCFAllocatorDefault,
|
|
|
|
kCFNumberSInt16Type,
|
|
|
|
&val);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
const CFTypeRef keys[] = { kCTFontFeatureTypeIdentifierKey,
|
|
|
|
kCTFontFeatureSelectorIdentifierKey };
|
|
|
|
const CFTypeRef values[] = { ligaturesType,
|
|
|
|
commonLigaturesOffSelector };
|
|
|
|
CFDictionaryRef featureSettingDict =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) keys,
|
|
|
|
(const void **) values,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(keys),
|
2009-10-07 08:26:58 -07:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(ligaturesType);
|
|
|
|
::CFRelease(commonLigaturesOffSelector);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
CFArrayRef featuresArray =
|
|
|
|
::CFArrayCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) &featureSettingDict,
|
|
|
|
1,
|
|
|
|
&kCFTypeArrayCallBacks);
|
|
|
|
::CFRelease(featureSettingDict);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
CFDictionaryRef attributesDict =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault,
|
|
|
|
(const void **) &kCTFontFeatureSettingsAttribute,
|
|
|
|
(const void **) &featuresArray,
|
|
|
|
1, // count of keys & values
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
::CFRelease(featuresArray);
|
2009-03-29 17:31:51 -07:00
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
sDisableLigaturesDescriptor =
|
2011-06-24 10:55:27 -07:00
|
|
|
::CTFontDescriptorCreateCopyWithAttributes(GetDefaultFeaturesDescriptor(),
|
|
|
|
attributesDict);
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(attributesDict);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
gfxMacFont *f = static_cast<gfxMacFont*>(mFont);
|
2013-07-31 08:44:31 -07:00
|
|
|
return ::CTFontCreateWithGraphicsFont(f->GetCGFontRef(), aSize, nullptr,
|
2011-06-24 10:55:27 -07:00
|
|
|
sDisableLigaturesDescriptor);
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-10 04:46:41 -08:00
|
|
|
gfxCoreTextShaper::Shutdown() // [static]
|
2009-03-29 17:31:51 -07:00
|
|
|
{
|
2013-07-31 08:44:31 -07:00
|
|
|
if (sDisableLigaturesDescriptor != nullptr) {
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(sDisableLigaturesDescriptor);
|
2013-07-31 08:44:31 -07:00
|
|
|
sDisableLigaturesDescriptor = nullptr;
|
2009-10-07 08:26:58 -07:00
|
|
|
}
|
2013-07-31 08:44:31 -07:00
|
|
|
if (sDefaultFeaturesDescriptor != nullptr) {
|
2009-10-07 08:26:58 -07:00
|
|
|
::CFRelease(sDefaultFeaturesDescriptor);
|
2013-07-31 08:44:31 -07:00
|
|
|
sDefaultFeaturesDescriptor = nullptr;
|
2009-03-29 17:31:51 -07:00
|
|
|
}
|
|
|
|
}
|