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

Side by Side Diff: src/ports/SkFontConfigInterface_direct.cpp

Issue 1471033002: Fix Google3 fonts. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years, 1 month 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 | « BUILD.public ('k') | tools/BUILD.public.expected » ('j') | 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 2009 Google Inc. 2 * Copyright 2009 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 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
9 9
10 #include "SkBuffer.h" 10 #include "SkBuffer.h"
11 #include "SkDataTable.h" 11 #include "SkDataTable.h"
12 #include "SkFontConfigInterface.h" 12 #include "SkFontConfigInterface.h"
13 #include "SkFontStyle.h" 13 #include "SkFontStyle.h"
14 #include "SkMutex.h" 14 #include "SkMutex.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkString.h" 16 #include "SkString.h"
17 #include "SkTArray.h" 17 #include "SkTArray.h"
18 #include "SkTDArray.h" 18 #include "SkTDArray.h"
19 #include "SkTemplates.h" 19 #include "SkTemplates.h"
20 #include "SkTypeface.h" 20 #include "SkTypeface.h"
21 #include "SkTypes.h" 21 #include "SkTypes.h"
22 22
23 #include <fontconfig/fontconfig.h> 23 #include <fontconfig/fontconfig.h>
24 #include <unistd.h> 24 #include <unistd.h>
25 25
26 #if defined(GOOGLE3)
bungeman-skia 2015/11/23 19:04:54 I would very much like to minimize this craziness.
27 #include "google_font_file_buffering.h"
28 #endif
29
26 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const { 30 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const {
27 size_t size = sizeof(fID) + sizeof(fTTCIndex); 31 size_t size = sizeof(fID) + sizeof(fTTCIndex);
28 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic 32 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic
29 size += sizeof(int32_t) + fString.size(); // store length+data 33 size += sizeof(int32_t) + fString.size(); // store length+data
30 if (addr) { 34 if (addr) {
31 SkWBuffer buffer(addr, size); 35 SkWBuffer buffer(addr, size);
32 36
33 buffer.write32(fID); 37 buffer.write32(fID);
34 buffer.write32(fTTCIndex); 38 buffer.write32(fTTCIndex);
35 buffer.write32(fString.size()); 39 buffer.write32(fString.size());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 SkASSERT(iden0 != iden1); 104 SkASSERT(iden0 != iden1);
101 105
102 make_iden(&iden1); 106 make_iden(&iden1);
103 SkASSERT(iden0 == iden1); 107 SkASSERT(iden0 == iden1);
104 108
105 test_writeToMemory(iden0, 0); 109 test_writeToMemory(iden0, 0);
106 test_writeToMemory(iden0, 0); 110 test_writeToMemory(iden0, 0);
107 } 111 }
108 #endif 112 #endif
109 113
110 class SkFontConfigInterfaceDirect : public SkFontConfigInterface { 114 class SkFontConfigInterfaceDirect : public SkFontConfigInterface {
bungeman-skia 2015/11/23 21:39:59 So here's a plan. Take this definition and put it
111 public: 115 public:
112 SkFontConfigInterfaceDirect(); 116 SkFontConfigInterfaceDirect();
113 virtual ~SkFontConfigInterfaceDirect(); 117 virtual ~SkFontConfigInterfaceDirect();
114 118
115 virtual bool matchFamilyName(const char familyName[], 119 virtual bool matchFamilyName(const char familyName[],
116 SkTypeface::Style requested, 120 SkTypeface::Style requested,
117 FontIdentity* outFontIdentifier, 121 FontIdentity* outFontIdentifier,
118 SkString* outFamilyName, 122 SkString* outFamilyName,
119 SkTypeface::Style* outStyle) override; 123 SkTypeface::Style* outStyle) override;
120 SkStreamAsset* openStream(const FontIdentity&) override; 124 SkStreamAsset* openStream(const FontIdentity&) override;
121 125
122 // new APIs 126 // new APIs
123 SkDataTable* getFamilyNames() override; 127 SkDataTable* getFamilyNames() override;
124 virtual bool matchFamilySet(const char inFamilyName[], 128 virtual bool matchFamilySet(const char inFamilyName[],
125 SkString* outFamilyName, 129 SkString* outFamilyName,
126 SkTArray<FontIdentity>*) override; 130 SkTArray<FontIdentity>*) override;
127 131
128 private: 132 private:
129 SkMutex mutex_; 133 SkMutex mutex_;
130 }; 134 };
131 135
132 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBase Mutex* mutex) { 136 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBase Mutex* mutex) {
bungeman-skia 2015/11/23 21:39:59 Then, since this is a factory, put this in a separ
133 SkAutoMutexAcquire ac(mutex); 137 SkAutoMutexAcquire ac(mutex);
134 static SkFontConfigInterfaceDirect* singleton = nullptr; 138 static SkFontConfigInterfaceDirect* singleton = nullptr;
135 if (singleton == nullptr) { 139 if (singleton == nullptr) {
136 singleton = new SkFontConfigInterfaceDirect; 140 singleton = new SkFontConfigInterfaceDirect;
137 } 141 }
138 return singleton; 142 return singleton;
139 } 143 }
140 144
141 /////////////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////////////
142 146
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 || !is_scalable) { 345 || !is_scalable) {
342 return false; 346 return false;
343 } 347 }
344 #endif 348 #endif
345 349
346 // fontconfig can also return fonts which are unreadable 350 // fontconfig can also return fonts which are unreadable
347 const char* c_filename = get_name(pattern, FC_FILE); 351 const char* c_filename = get_name(pattern, FC_FILE);
348 if (!c_filename) { 352 if (!c_filename) {
349 return false; 353 return false;
350 } 354 }
355
356 #if defined(GOOGLE3)
bungeman-skia 2015/11/23 21:39:59 This block is harder to remove, but since it wasn'
bungeman-skia 2015/11/24 21:56:36 This block is needed, or at least the 'access' cod
357 // Check if this font has been pre-loaded into memory.
358 const char* unused;
359 if (GoogleFreeType::GoogleFt2ReadFontFromMemory(c_filename, &unused) >= 0) {
360 return true;
361 }
362 #endif
363
351 if (access(c_filename, R_OK) != 0) { 364 if (access(c_filename, R_OK) != 0) {
352 return false; 365 return false;
353 } 366 }
367
354 return true; 368 return true;
355 } 369 }
356 370
357 // Find matching font from |font_set| for the given font family. 371 // Find matching font from |font_set| for the given font family.
358 FcPattern* MatchFont(FcFontSet* font_set, 372 FcPattern* MatchFont(FcFontSet* font_set,
359 const char* post_config_family, 373 const char* post_config_family,
360 const SkString& family) { 374 const SkString& family) {
361 // Older versions of fontconfig have a bug where they cannot select 375 // Older versions of fontconfig have a bug where they cannot select
362 // only scalable fonts so we have to manually filter the results. 376 // only scalable fonts so we have to manually filter the results.
363 FcPattern* match = nullptr; 377 FcPattern* match = nullptr;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 if (outFamilyName) { 566 if (outFamilyName) {
553 outFamilyName->set(post_config_family); 567 outFamilyName->set(post_config_family);
554 } 568 }
555 if (outStyle) { 569 if (outStyle) {
556 *outStyle = GetFontStyle(match); 570 *outStyle = GetFontStyle(match);
557 } 571 }
558 return true; 572 return true;
559 } 573 }
560 574
561 SkStreamAsset* SkFontConfigInterfaceDirect::openStream(const FontIdentity& ident ity) { 575 SkStreamAsset* SkFontConfigInterfaceDirect::openStream(const FontIdentity& ident ity) {
562 return SkStream::NewFromFile(identity.fString.c_str()); 576 const char* c_filename = identity.fString.c_str();
577 #if defined(GOOGLE3)
578 // Read the system fonts from the fonts we've pre-loaded into memory.
579 const char* buffer;
580 int length = GoogleFreeType::GoogleFt2ReadFontFromMemory(
581 c_filename, &buffer);
582 if (length >= 0) return new SkMemoryStream(buffer, length);
583 #endif
584 return SkStream::NewFromFile(c_filename);
563 } 585 }
564 586
565 /////////////////////////////////////////////////////////////////////////////// 587 ///////////////////////////////////////////////////////////////////////////////
566 588
567 static bool find_name(const SkTDArray<const char*>& list, const char* str) { 589 static bool find_name(const SkTDArray<const char*>& list, const char* str) {
568 int count = list.count(); 590 int count = list.count();
569 for (int i = 0; i < count; ++i) { 591 for (int i = 0; i < count; ++i) {
570 if (!strcmp(list[i], str)) { 592 if (!strcmp(list[i], str)) {
571 return true; 593 return true;
572 } 594 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 const char* justName = find_just_name(get_name(match[i], FC_FILE)); 752 const char* justName = find_just_name(get_name(match[i], FC_FILE));
731 if (!is_lower(*justName)) { 753 if (!is_lower(*justName)) {
732 *trimmedMatches.append() = match[i]; 754 *trimmedMatches.append() = match[i];
733 } 755 }
734 } 756 }
735 757
736 SkFontStyleSet_FC* sset = new SkFontStyleSet_FC (trimmedMatches.begin(), trimmedMatches.count()); 758 SkFontStyleSet_FC* sset = new SkFontStyleSet_FC (trimmedMatches.begin(), trimmedMatches.count());
737 #endif 759 #endif
738 return false; 760 return false;
739 } 761 }
OLDNEW
« no previous file with comments | « BUILD.public ('k') | tools/BUILD.public.expected » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698