This source file includes following definitions.
- shouldUseCoreText
- fill
#include "config.h"
#include "platform/fonts/GlyphPageTreeNode.h"
#include <ApplicationServices/ApplicationServices.h>
#include "platform/fonts/Character.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/SimpleFontData.h"
extern "C" {
void CGFontGetGlyphsForUnichars(CGFontRef font, const UniChar chars[], CGGlyph glyphs[], size_t length);
}
namespace WebCore {
static bool shouldUseCoreText(UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
{
if (fontData->platformData().isCompositeFontReference())
return true;
if (bufferLength >= 2 && U_IS_SURROGATE(buffer[0]) && fontData->hasVerticalGlyphs()) {
ASSERT(U_IS_SURROGATE_LEAD(buffer[0]));
ASSERT(U_IS_TRAIL(buffer[1]));
return false;
}
if (fontData->platformData().widthVariant() != RegularWidth || fontData->hasVerticalGlyphs()) {
for (unsigned i = 0; i < bufferLength; ++i) {
if (!Character::isCJKIdeograph(buffer[i]))
return true;
}
}
return false;
}
bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
{
bool haveGlyphs = false;
Vector<CGGlyph, 512> glyphs(bufferLength);
if (!shouldUseCoreText(buffer, bufferLength, fontData)) {
CGFontGetGlyphsForUnichars(fontData->platformData().cgFont(), buffer, glyphs.data(), bufferLength);
for (unsigned i = 0; i < length; ++i) {
if (!glyphs[i])
setGlyphDataForIndex(offset + i, 0, 0);
else {
setGlyphDataForIndex(offset + i, glyphs[i], fontData);
haveGlyphs = true;
}
}
} else if (!fontData->platformData().isCompositeFontReference() && fontData->platformData().widthVariant() != RegularWidth
&& CTFontGetGlyphsForCharacters(fontData->platformData().ctFont(), buffer, glyphs.data(), bufferLength)) {
unsigned glyphStep = bufferLength / length;
for (unsigned i = 0; i < length; ++i) {
if (!glyphs[i * glyphStep])
setGlyphDataForIndex(offset + i, 0, 0);
else {
setGlyphDataForIndex(offset + i, glyphs[i * glyphStep], fontData);
haveGlyphs = true;
}
}
} else {
RetainPtr<CFStringRef> string(AdoptCF, CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, buffer, bufferLength, kCFAllocatorNull));
RetainPtr<CFAttributedStringRef> attributedString(AdoptCF, CFAttributedStringCreate(kCFAllocatorDefault, string.get(), fontData->getCFStringAttributes(0, fontData->hasVerticalGlyphs() ? Vertical : Horizontal)));
RetainPtr<CTLineRef> line(AdoptCF, CTLineCreateWithAttributedString(attributedString.get()));
CFArrayRef runArray = CTLineGetGlyphRuns(line.get());
CFIndex runCount = CFArrayGetCount(runArray);
for (unsigned index = 0; index < length; ++index)
setGlyphDataForIndex(offset + index, 0, 0);
Vector<CGGlyph, 512> glyphVector;
Vector<CFIndex, 512> indexVector;
bool done = false;
RetainPtr<CGFontRef> cgFont(AdoptCF, CTFontCopyGraphicsFont(fontData->platformData().ctFont(), 0));
for (CFIndex r = 0; r < runCount && !done ; ++r) {
CTRunRef ctRun = static_cast<CTRunRef>(CFArrayGetValueAtIndex(runArray, r));
ASSERT(CFGetTypeID(ctRun) == CTRunGetTypeID());
CFDictionaryRef attributes = CTRunGetAttributes(ctRun);
CTFontRef runFont = static_cast<CTFontRef>(CFDictionaryGetValue(attributes, kCTFontAttributeName));
RetainPtr<CGFontRef> runCGFont(AdoptCF, CTFontCopyGraphicsFont(runFont, 0));
bool gotBaseFont = CFEqual(cgFont.get(), runCGFont.get());
if (gotBaseFont || fontData->platformData().isCompositeFontReference()) {
CFIndex glyphCount = CTRunGetGlyphCount(ctRun);
const CGGlyph* glyphs = CTRunGetGlyphsPtr(ctRun);
if (!glyphs) {
glyphVector.resize(glyphCount);
CTRunGetGlyphs(ctRun, CFRangeMake(0, 0), glyphVector.data());
glyphs = glyphVector.data();
}
const CFIndex* stringIndices = CTRunGetStringIndicesPtr(ctRun);
if (!stringIndices) {
indexVector.resize(glyphCount);
CTRunGetStringIndices(ctRun, CFRangeMake(0, 0), indexVector.data());
stringIndices = indexVector.data();
}
if (gotBaseFont) {
for (CFIndex i = 0; i < glyphCount; ++i) {
if (stringIndices[i] >= static_cast<CFIndex>(length)) {
done = true;
break;
}
if (glyphs[i]) {
setGlyphDataForIndex(offset + stringIndices[i], glyphs[i], fontData);
haveGlyphs = true;
}
}
} else {
const SimpleFontData* runSimple = fontData->getCompositeFontReferenceFontData((NSFont *)runFont);
if (runSimple) {
for (CFIndex i = 0; i < glyphCount; ++i) {
if (stringIndices[i] >= static_cast<CFIndex>(length)) {
done = true;
break;
}
if (glyphs[i]) {
setGlyphDataForIndex(offset + stringIndices[i], glyphs[i], runSimple);
haveGlyphs = true;
}
}
}
}
}
}
}
return haveGlyphs;
}
}