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

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: 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
« include/core/SkTArray.h ('K') | « include/core/SkTArray.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 "SkDraw.h" 11 #include "SkDraw.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkParsePath.h" 13 #include "SkParsePath.h"
14 #include "SkPathOps.h" 14 #include "SkPathOps.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 #include "SkTArray.h"
17 #include "SkTypeface.h" 18 #include "SkTypeface.h"
18 #include "SkUtils.h" 19 #include "SkUtils.h"
19 #include "SkXMLWriter.h" 20 #include "SkXMLWriter.h"
20 21
21 namespace { 22 namespace {
22 23
23 static SkString svg_color(SkColor color) { 24 static SkString svg_color(SkColor color) {
24 return SkStringPrintf("rgb(%u,%u,%u)", 25 return SkStringPrintf("rgb(%u,%u,%u)",
25 SkColorGetR(color), 26 SkColorGetR(color),
26 SkColorGetG(color), 27 SkColorGetG(color),
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 this->addAttribute("font-size", paint.getTextSize()); 452 this->addAttribute("font-size", paint.getTextSize());
452 453
453 SkTypeface::Style style = paint.getTypeface()->style(); 454 SkTypeface::Style style = paint.getTypeface()->style();
454 if (style & SkTypeface::kItalic) { 455 if (style & SkTypeface::kItalic) {
455 this->addAttribute("font-style", "italic"); 456 this->addAttribute("font-style", "italic");
456 } 457 }
457 if (style & SkTypeface::kBold) { 458 if (style & SkTypeface::kBold) {
458 this->addAttribute("font-weight", "bold"); 459 this->addAttribute("font-weight", "bold");
459 } 460 }
460 461
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())) { 462 if (const char* textAlign = svg_text_align(paint.getTextAlign())) {
470 this->addAttribute("text-anchor", textAlign); 463 this->addAttribute("text-anchor", textAlign);
471 } 464 }
465
466 SkString familyName;
467 SkTArray<SkString> familyNamesSet;
468 SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
469 SkRef(paint.getTypeface()) : SkTypeface::RefDefault(style));
470 SkAutoTUnref<SkTypeface::LocalizedStrings> familyNameIter(tface->createFamil yNameIterator());
471 SkTypeface::LocalizedString familyString;
472 while (familyNameIter->next(&familyString)) {
473 // !!linear search!! In general we expect a small number of names so thi s should be ok.
474 if (familyNamesSet.rfind(familyString.fString) < 0) {
475 familyNamesSet.push_back() = familyString.fString;
476 familyName.appendf((familyName.isEmpty() ? "%s" : ", %s"),
477 familyString.fString.c_str());
478 }
479 }
480
481 if (!familyName.isEmpty()) {
482 this->addAttribute("font-family", familyName);
483 }
472 } 484 }
473 485
474 SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) { 486 SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) {
475 if (!writer) { 487 if (!writer) {
476 return NULL; 488 return NULL;
477 } 489 }
478 490
479 return SkNEW_ARGS(SkSVGDevice, (size, writer)); 491 return SkNEW_ARGS(SkSVGDevice, (size, writer));
480 } 492 }
481 493
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 const SkPaint& paint) { 654 const SkPaint& paint) {
643 // todo 655 // todo
644 SkDebugf("unsupported operation: drawVertices()\n"); 656 SkDebugf("unsupported operation: drawVertices()\n");
645 } 657 }
646 658
647 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, 659 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
648 const SkPaint&) { 660 const SkPaint&) {
649 // todo 661 // todo
650 SkDebugf("unsupported operation: drawDevice()\n"); 662 SkDebugf("unsupported operation: drawDevice()\n");
651 } 663 }
OLDNEW
« 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