X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2Fskia%2Fsrc%2Fcore%2FSkTypeface.cpp;h=f9487870ccc537ad13e669083ab9022f554b6151;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=01b534c95fa4adb28f216b4818e4ef9c42b957cd;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/skia/src/core/SkTypeface.cpp b/src/third_party/skia/src/core/SkTypeface.cpp index 01b534c..f948787 100644 --- a/src/third_party/skia/src/core/SkTypeface.cpp +++ b/src/third_party/skia/src/core/SkTypeface.cpp @@ -8,7 +8,7 @@ #include "SkAdvancedTypefaceMetrics.h" #include "SkEndian.h" #include "SkFontDescriptor.h" -#include "SkFontHost.h" +#include "SkFontMgr.h" #include "SkLazyPtr.h" #include "SkOTTable_OS_2.h" #include "SkStream.h" @@ -67,6 +67,9 @@ protected: public: virtual bool next(SkTypeface::LocalizedString*) SK_OVERRIDE { return false; } }; + virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { + familyName->reset(); + } virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE { return SkNEW(EmptyLocalizedStrings); }; @@ -84,7 +87,8 @@ SkTypeface* SkTypeface::CreateDefault(int style) { // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? SkAutoMutexAcquire lock(&gCreateDefaultMutex); - SkTypeface* t = SkFontHost::CreateTypeface(NULL, NULL, (Style)style); + SkAutoTUnref fm(SkFontMgr::RefDefault()); + SkTypeface* t = fm->legacyCreateTypeface(NULL, style);; return t ? t : SkEmptyTypeface::Create(); } @@ -123,23 +127,39 @@ SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { if (NULL == name) { return RefDefault(style); } - return SkFontHost::CreateTypeface(NULL, name, style); + SkAutoTUnref fm(SkFontMgr::RefDefault()); + return fm->legacyCreateTypeface(name, style); } SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { - if (family && family->style() == s) { + if (!family) { + return SkTypeface::RefDefault(s); + } + + if (family->style() == s) { family->ref(); return const_cast(family); } - return SkFontHost::CreateTypeface(family, NULL, s); + + SkAutoTUnref fm(SkFontMgr::RefDefault()); + bool bold = s & SkTypeface::kBold; + bool italic = s & SkTypeface::kItalic; + SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight + : SkFontStyle::kNormal_Weight, + SkFontStyle::kNormal_Width, + italic ? SkFontStyle::kItalic_Slant + : SkFontStyle::kUpright_Slant); + return fm->matchFaceStyle(family, newStyle); } -SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { - return SkFontHost::CreateTypefaceFromStream(stream); +SkTypeface* SkTypeface::CreateFromStream(SkStream* stream, int index) { + SkAutoTUnref fm(SkFontMgr::RefDefault()); + return fm->createFromStream(stream, index); } -SkTypeface* SkTypeface::CreateFromFile(const char path[]) { - return SkFontHost::CreateTypefaceFromFile(path); +SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { + SkAutoTUnref fm(SkFontMgr::RefDefault()); + return fm->createFromFile(path, index); } /////////////////////////////////////////////////////////////////////////////// @@ -149,45 +169,24 @@ void SkTypeface::serialize(SkWStream* wstream) const { SkFontDescriptor desc(this->style()); this->onGetFontDescriptor(&desc, &isLocal); - desc.serialize(wstream); - if (isLocal) { - int ttcIndex; // TODO: write this to the stream? - SkAutoTUnref rstream(this->openStream(&ttcIndex)); - if (rstream.get()) { - size_t length = rstream->getLength(); - wstream->writePackedUInt(length); - wstream->writeStream(rstream, length); - } else { - wstream->writePackedUInt(0); - } - } else { - wstream->writePackedUInt(0); + if (isLocal && NULL == desc.getFontData()) { + int ttcIndex; + desc.setFontData(this->onOpenStream(&ttcIndex)); + desc.setFontIndex(ttcIndex); } + + desc.serialize(wstream); } SkTypeface* SkTypeface::Deserialize(SkStream* stream) { SkFontDescriptor desc(stream); - size_t length = stream->readPackedUInt(); - if (length > 0) { - void* addr = sk_malloc_flags(length, 0); - if (addr) { - SkAutoTUnref localStream(SkNEW(SkMemoryStream)); - localStream->setMemoryOwned(addr, length); - - if (stream->read(addr, length) == length) { - return SkTypeface::CreateFromStream(localStream.get()); - } else { - // Failed to read the full font data, so fall through and try to create from name. - // If this is because of EOF, all subsequent reads from the stream will be EOF. - // If this is because of a stream error, the stream is in an error state, - // do not attempt to skip any remaining bytes. - } - } else { - // failed to allocate, so just skip and create-from-name - stream->skip(length); + SkStream* data = desc.getFontData(); + if (data) { + SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIndex()); + if (typeface) { + return typeface; } } - return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); } @@ -261,10 +260,8 @@ SkTypeface::LocalizedStrings* SkTypeface::createFamilyNameIterator() const { } void SkTypeface::getFamilyName(SkString* name) const { - bool isLocal = false; - SkFontDescriptor desc(this->style()); - this->onGetFontDescriptor(&desc, &isLocal); - name->set(desc.getFamilyName()); + SkASSERT(name); + this->onGetFamilyName(name); } SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(