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

Side by Side Diff: trunk/src/ports/SkFontHost_android.cpp

Issue 12919013: move SK_MMAP_SUPPORT into SkPreConfig, so we can know about its availability (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/core/SkStream.cpp ('k') | trunk/src/ports/SkFontHost_ascender.cpp » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkFontHost.h" 8 #include "SkFontHost.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkDescriptor.h" 11 #include "SkDescriptor.h"
12 #include "SkMMapStream.h"
13 #include "SkPaint.h" 12 #include "SkPaint.h"
14 #include "SkString.h" 13 #include "SkString.h"
15 #include "SkStream.h" 14 #include "SkStream.h"
16 #include "SkThread.h" 15 #include "SkThread.h"
17 #include "SkTSearch.h" 16 #include "SkTSearch.h"
18 #include "SkTypeface_android.h" 17 #include "SkTypeface_android.h"
19 #include "FontHostConfiguration_android.h" 18 #include "FontHostConfiguration_android.h"
20 19
21 #ifndef SK_FONT_FILE_PREFIX 20 #ifndef SK_FONT_FILE_PREFIX
22 #define SK_FONT_FILE_PREFIX "/fonts/" 21 #define SK_FONT_FILE_PREFIX "/fonts/"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 : INHERITED(style, sysFont, familyMember, isFixedWidth) { 362 : INHERITED(style, sysFont, familyMember, isFixedWidth) {
364 SkString fullpath; 363 SkString fullpath;
365 364
366 if (sysFont) { 365 if (sysFont) {
367 GetFullPathForSysFonts(&fullpath, path); 366 GetFullPathForSysFonts(&fullpath, path);
368 path = fullpath.c_str(); 367 path = fullpath.c_str();
369 } 368 }
370 fPath.set(path); 369 fPath.set(path);
371 } 370 }
372 371
373 // overrides 372 virtual SkStream* openStream() SK_OVERRIDE {
374 virtual SkStream* openStream() { 373 return SkStream::NewFromFile(fPath.c_str());
375 SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str())); 374 }
376 375
377 // check for failure 376 virtual const char* getUniqueString() const SK_OVERRIDE {
378 if (stream->getLength() <= 0) {
379 SkDELETE(stream);
380 // maybe MMAP isn't supported. try FILE
381 stream = SkNEW_ARGS(SkFILEStream, (fPath.c_str()));
382 if (stream->getLength() <= 0) {
383 SkDELETE(stream);
384 stream = NULL;
385 }
386 }
387 return stream;
388 }
389 virtual const char* getUniqueString() const {
390 const char* str = strrchr(fPath.c_str(), '/'); 377 const char* str = strrchr(fPath.c_str(), '/');
391 if (str) { 378 if (str) {
392 str += 1; // skip the '/' 379 str += 1; // skip the '/'
393 } 380 }
394 return str; 381 return str;
395 } 382 }
396 virtual const char* getFilePath() const { 383
384 virtual const char* getFilePath() const SK_OVERRIDE {
397 return fPath.c_str(); 385 return fPath.c_str();
398 } 386 }
399 387
400 private: 388 private:
401 SkString fPath; 389 SkString fPath;
402 390
403 typedef FamilyTypeface INHERITED; 391 typedef FamilyTypeface INHERITED;
404 }; 392 };
405 393
406 /////////////////////////////////////////////////////////////////////////////// 394 ///////////////////////////////////////////////////////////////////////////////
407 /////////////////////////////////////////////////////////////////////////////// 395 ///////////////////////////////////////////////////////////////////////////////
408 396
409 static bool get_name_and_style(const char path[], SkString* name, 397 static bool get_name_and_style(const char path[], SkString* name,
410 SkTypeface::Style* style, 398 SkTypeface::Style* style,
411 bool* isFixedWidth, bool isExpected) { 399 bool* isFixedWidth, bool isExpected) {
412 SkString fullpath; 400 SkString fullpath;
413 GetFullPathForSysFonts(&fullpath, path); 401 GetFullPathForSysFonts(&fullpath, path);
414 402
415 SkMMAPStream stream(fullpath.c_str()); 403 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
416 if (stream.getLength() > 0) { 404 if (stream.get()) {
417 return find_name_and_attributes(&stream, name, style, isFixedWidth); 405 return find_name_and_attributes(stream, name, style, isFixedWidth);
406 } else {
407 if (isExpected) {
408 SkDebugf("---- failed to open <%s> as a font", fullpath.c_str());
409 }
410 return false;
418 } 411 }
419 else {
420 SkFILEStream stream(fullpath.c_str());
421 if (stream.getLength() > 0) {
422 return find_name_and_attributes(&stream, name, style, isFixedWidth);
423 }
424 }
425
426 if (isExpected) {
427 SkDebugf("---- failed to open <%s> as a font", fullpath.c_str());
428 }
429 return false;
430 } 412 }
431 413
432 // used to record our notion of the pre-existing fonts 414 // used to record our notion of the pre-existing fonts
433 struct FontInitRec { 415 struct FontInitRec {
434 const char* fFileName; 416 const char* fFileName;
435 const char* const* fNames; // null-terminated list 417 const char* const* fNames; // null-terminated list
436 }; 418 };
437 419
438 // deliberately empty, but we use the address to identify fallback fonts 420 // deliberately empty, but we use the address to identify fallback fonts
439 static const char* gFBNames[] = { NULL }; 421 static const char* gFBNames[] = { NULL };
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 // Make sure system fonts are loaded to comply with the assumption of 927 // Make sure system fonts are loaded to comply with the assumption of
946 // unique id offset by one in find_uniqueID. 928 // unique id offset by one in find_uniqueID.
947 load_system_fonts(); 929 load_system_fonts();
948 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWi dth)); 930 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWi dth));
949 } else { 931 } else {
950 return NULL; 932 return NULL;
951 } 933 }
952 } 934 }
953 935
954 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 936 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
955 SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); 937 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
956 SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); 938 return stream.get() ? SkFontHost::CreateTypefaceFromStream(stream) : NULL;
957 // since we created the stream, we let go of our ref() here
958 stream->unref();
959 return face;
960 } 939 }
961 940
962 /////////////////////////////////////////////////////////////////////////////// 941 ///////////////////////////////////////////////////////////////////////////////
963 // Function from SkTypeface_android.h 942 // Function from SkTypeface_android.h
964 /////////////////////////////////////////////////////////////////////////////// 943 ///////////////////////////////////////////////////////////////////////////////
965 944
966 struct FBScriptInfo { 945 struct FBScriptInfo {
967 const FallbackScripts fScript; 946 const FallbackScripts fScript;
968 const char* fScriptID; 947 const char* fScriptID;
969 const SkTypeface::Style fStyle; 948 const SkTypeface::Style fStyle;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 const char* fontsdir) { 1121 const char* fontsdir) {
1143 gTestMainConfigFile = mainconf; 1122 gTestMainConfigFile = mainconf;
1144 gTestFallbackConfigFile = fallbackconf; 1123 gTestFallbackConfigFile = fallbackconf;
1145 gTestFontFilePrefix = fontsdir; 1124 gTestFontFilePrefix = fontsdir;
1146 SkASSERT(gTestMainConfigFile); 1125 SkASSERT(gTestMainConfigFile);
1147 SkASSERT(gTestFallbackConfigFile); 1126 SkASSERT(gTestFallbackConfigFile);
1148 SkASSERT(gTestFontFilePrefix); 1127 SkASSERT(gTestFontFilePrefix);
1149 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", 1128 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s",
1150 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) ); 1129 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) );
1151 } 1130 }
OLDNEW
« no previous file with comments | « trunk/src/core/SkStream.cpp ('k') | trunk/src/ports/SkFontHost_ascender.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698