Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: src/svg/SkSVGDevice.cpp

Issue 923583002: [SkSVGDevice] Full font family support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkTArray.h ('K') | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/svg/SkSVGDevice.cpp
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index bf19a81a1d3670ef193836d668660bbb7f72464d..28b73c882b5bef021092b58e8e82b6b231a64505 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -14,6 +14,7 @@
#include "SkPathOps.h"
#include "SkShader.h"
#include "SkStream.h"
+#include "SkTArray.h"
#include "SkTypeface.h"
#include "SkUtils.h"
#include "SkXMLWriter.h"
@@ -458,16 +459,27 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
this->addAttribute("font-weight", "bold");
}
+ if (const char* textAlign = svg_text_align(paint.getTextAlign())) {
+ this->addAttribute("text-anchor", textAlign);
+ }
+
+ SkString familyName;
+ SkTArray<SkString> familyNamesSet;
SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
SkRef(paint.getTypeface()) : SkTypeface::RefDefault(style));
- SkString familyName;
- tface->getFamilyName(&familyName);
- if (!familyName.isEmpty()) {
- this->addAttribute("font-family", familyName);
+ SkAutoTUnref<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamilyNameIterator());
+ SkTypeface::LocalizedString familyString;
+ while (familyNameIter->next(&familyString)) {
+ // !!linear search!! In general we expect a small number of names so this should be ok.
+ if (familyNamesSet.rfind(familyString.fString) < 0) {
+ familyNamesSet.push_back() = familyString.fString;
+ familyName.appendf((familyName.isEmpty() ? "%s" : ", %s"),
+ familyString.fString.c_str());
+ }
}
- if (const char* textAlign = svg_text_align(paint.getTextAlign())) {
- this->addAttribute("text-anchor", textAlign);
+ if (!familyName.isEmpty()) {
+ this->addAttribute("font-family", familyName);
}
}
« include/core/SkTArray.h ('K') | « include/core/SkTArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698