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

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: slightly less lame hash function 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
« no previous file with comments | « include/core/SkTDArray.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..4b9f48983296837c24b6ea9e2838d84215e187d0 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -8,12 +8,14 @@
#include "SkSVGDevice.h"
#include "SkBitmap.h"
+#include "SkChecksum.h"
#include "SkDraw.h"
#include "SkPaint.h"
#include "SkParsePath.h"
#include "SkPathOps.h"
#include "SkShader.h"
#include "SkStream.h"
+#include "SkTHash.h"
#include "SkTypeface.h"
#include "SkUtils.h"
#include "SkXMLWriter.h"
@@ -164,6 +166,12 @@ static SkString svg_text(const void* text, size_t byteLen, const SkPaint& paint)
return svgText;
}
+uint32_t hash_family_string(const SkString& family) {
+ // This is a lame hash function, but we don't really expect to see more than 1-2
mtklein 2015/02/13 15:01:20 At least, it is not without precedent: http://www
+ // family names under normal circumstances.
+ return SkChecksum::Mix(SkToU32(family.size()));
+}
+
struct Resources {
Resources(const SkPaint& paint)
: fPaintServer(svg_color(paint.getColor())) {}
@@ -458,16 +466,26 @@ 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;
+ SkTHashSet<SkString, hash_family_string> familySet;
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)) {
+ if (familySet.contains(familyString.fString)) {
+ continue;
+ }
+ familySet.add(familyString.fString);
mtklein 2015/02/13 15:01:20 Well, now I want SkTHashSet's add to return a bool
f(malita) 2015/02/13 15:24:09 Ack. Yeah, that would let us avoid a double hash
+ 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);
}
}
« no previous file with comments | « include/core/SkTDArray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698