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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/core/SkTDArray.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSVGDevice.h" 8 #include "SkSVGDevice.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkChecksum.h"
11 #include "SkDraw.h" 12 #include "SkDraw.h"
12 #include "SkPaint.h" 13 #include "SkPaint.h"
13 #include "SkParsePath.h" 14 #include "SkParsePath.h"
14 #include "SkPathOps.h" 15 #include "SkPathOps.h"
15 #include "SkShader.h" 16 #include "SkShader.h"
16 #include "SkStream.h" 17 #include "SkStream.h"
18 #include "SkTHash.h"
17 #include "SkTypeface.h" 19 #include "SkTypeface.h"
18 #include "SkUtils.h" 20 #include "SkUtils.h"
19 #include "SkXMLWriter.h" 21 #include "SkXMLWriter.h"
20 22
21 namespace { 23 namespace {
22 24
23 static SkString svg_color(SkColor color) { 25 static SkString svg_color(SkColor color) {
24 return SkStringPrintf("rgb(%u,%u,%u)", 26 return SkStringPrintf("rgb(%u,%u,%u)",
25 SkColorGetR(color), 27 SkColorGetR(color),
26 SkColorGetG(color), 28 SkColorGetG(color),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 append_escaped_unichar(c32[i], &svgText); 159 append_escaped_unichar(c32[i], &svgText);
158 } 160 }
159 } break; 161 } break;
160 default: 162 default:
161 SkFAIL("unknown text encoding"); 163 SkFAIL("unknown text encoding");
162 } 164 }
163 165
164 return svgText; 166 return svgText;
165 } 167 }
166 168
169 uint32_t hash_family_string(const SkString& family) {
170 // 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
171 // family names under normal circumstances.
172 return SkChecksum::Mix(SkToU32(family.size()));
173 }
174
167 struct Resources { 175 struct Resources {
168 Resources(const SkPaint& paint) 176 Resources(const SkPaint& paint)
169 : fPaintServer(svg_color(paint.getColor())) {} 177 : fPaintServer(svg_color(paint.getColor())) {}
170 178
171 SkString fPaintServer; 179 SkString fPaintServer;
172 SkString fClip; 180 SkString fClip;
173 }; 181 };
174 182
175 } 183 }
176 184
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 this->addAttribute("font-size", paint.getTextSize()); 459 this->addAttribute("font-size", paint.getTextSize());
452 460
453 SkTypeface::Style style = paint.getTypeface()->style(); 461 SkTypeface::Style style = paint.getTypeface()->style();
454 if (style & SkTypeface::kItalic) { 462 if (style & SkTypeface::kItalic) {
455 this->addAttribute("font-style", "italic"); 463 this->addAttribute("font-style", "italic");
456 } 464 }
457 if (style & SkTypeface::kBold) { 465 if (style & SkTypeface::kBold) {
458 this->addAttribute("font-weight", "bold"); 466 this->addAttribute("font-weight", "bold");
459 } 467 }
460 468
461 SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
462 SkRef(paint.getTypeface()) : SkTypeface::RefDefault(style));
463 SkString familyName;
464 tface->getFamilyName(&familyName);
465 if (!familyName.isEmpty()) {
466 this->addAttribute("font-family", familyName);
467 }
468
469 if (const char* textAlign = svg_text_align(paint.getTextAlign())) { 469 if (const char* textAlign = svg_text_align(paint.getTextAlign())) {
470 this->addAttribute("text-anchor", textAlign); 470 this->addAttribute("text-anchor", textAlign);
471 } 471 }
472
473 SkString familyName;
474 SkTHashSet<SkString, hash_family_string> familySet;
475 SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
476 SkRef(paint.getTypeface()) : SkTypeface::RefDefault(style));
477 SkAutoTUnref<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamil yNameIterator());
478 SkTypeface::LocalizedString familyString;
479 while (familyNameIter->next(&familyString)) {
480 if (familySet.contains(familyString.fString)) {
481 continue;
482 }
483 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
484 familyName.appendf((familyName.isEmpty() ? "%s" : ", %s"), familyString. fString.c_str());
485 }
486
487 if (!familyName.isEmpty()) {
488 this->addAttribute("font-family", familyName);
489 }
472 } 490 }
473 491
474 SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) { 492 SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) {
475 if (!writer) { 493 if (!writer) {
476 return NULL; 494 return NULL;
477 } 495 }
478 496
479 return SkNEW_ARGS(SkSVGDevice, (size, writer)); 497 return SkNEW_ARGS(SkSVGDevice, (size, writer));
480 } 498 }
481 499
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 const SkPaint& paint) { 660 const SkPaint& paint) {
643 // todo 661 // todo
644 SkDebugf("unsupported operation: drawVertices()\n"); 662 SkDebugf("unsupported operation: drawVertices()\n");
645 } 663 }
646 664
647 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, 665 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
648 const SkPaint&) { 666 const SkPaint&) {
649 // todo 667 // todo
650 SkDebugf("unsupported operation: drawDevice()\n"); 668 SkDebugf("unsupported operation: drawDevice()\n");
651 } 669 }
OLDNEW
« 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