Chromium Code Reviews| 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); |
| } |
| } |