OLD | NEW |
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 "SkFontHost_FreeType_common.h" | 9 #include "SkFontHost_FreeType_common.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkDescriptor.h" | 12 #include "SkDescriptor.h" |
13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
14 #include "SkPaint.h" | 14 #include "SkPaint.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 #include "SkStream.h" | 16 #include "SkStream.h" |
17 #include "SkThread.h" | 17 #include "SkThread.h" |
18 #include "SkTSearch.h" | 18 #include "SkTSearch.h" |
19 #include "SkTypefaceCache.h" | 19 #include "SkTypefaceCache.h" |
20 #include "SkTArray.h" | 20 #include "SkTArray.h" |
21 | 21 |
22 #include <limits> | 22 #include <limits> |
23 | 23 |
24 #ifndef SK_FONT_FILE_PREFIX | 24 #ifndef SK_FONT_FILE_PREFIX |
25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" | 25 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/" |
26 #endif | 26 #endif |
27 #ifndef SK_FONT_FILE_DIR_SEPERATOR | |
28 # define SK_FONT_FILE_DIR_SEPERATOR "/" | |
29 #endif | |
30 | 27 |
31 bool find_name_and_attributes(SkStream* stream, SkString* name, | 28 bool find_name_and_attributes(SkStream* stream, SkString* name, |
32 SkTypeface::Style* style, bool* isFixedPitch); | 29 SkTypeface::Style* style, bool* isFixedPitch); |
33 | 30 |
34 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
35 | 32 |
36 /** The base SkTypeface implementation for the custom font manager. */ | 33 /** The base SkTypeface implementation for the custom font manager. */ |
37 class SkTypeface_Custom : public SkTypeface_FreeType { | 34 class SkTypeface_Custom : public SkTypeface_FreeType { |
38 public: | 35 public: |
39 SkTypeface_Custom(Style style, bool sysFont, bool isFixedPitch, const SkStri
ng familyName) | 36 SkTypeface_Custom(Style style, bool sysFont, bool isFixedPitch, const SkStri
ng familyName) |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 SkDebugf("---- failed to open <%s> as a font\n", path); | 316 SkDebugf("---- failed to open <%s> as a font\n", path); |
320 return false; | 317 return false; |
321 } | 318 } |
322 } | 319 } |
323 | 320 |
324 void load_directory_fonts(const SkString& directory) { | 321 void load_directory_fonts(const SkString& directory) { |
325 SkOSFile::Iter iter(directory.c_str(), ".ttf"); | 322 SkOSFile::Iter iter(directory.c_str(), ".ttf"); |
326 SkString name; | 323 SkString name; |
327 | 324 |
328 while (iter.next(&name, false)) { | 325 while (iter.next(&name, false)) { |
329 SkString filename(directory); | 326 SkString filename( |
330 filename.append(name); | 327 SkOSPath::SkPathJoin(directory.c_str(), name.c_str())); |
331 | 328 |
332 bool isFixedPitch; | 329 bool isFixedPitch; |
333 SkString realname; | 330 SkString realname; |
334 SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialize
d warning | 331 SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialize
d warning |
335 | 332 |
336 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { | 333 if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixe
dPitch)) { |
337 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; | 334 SkDebugf("------ can't load <%s> as a font\n", filename.c_str())
; |
338 continue; | 335 continue; |
339 } | 336 } |
340 | 337 |
(...skipping 10 matching lines...) Expand all Loading... |
351 fFamilies.push_back().reset(addTo); | 348 fFamilies.push_back().reset(addTo); |
352 } | 349 } |
353 addTo->appendTypeface(tf); | 350 addTo->appendTypeface(tf); |
354 } | 351 } |
355 | 352 |
356 SkOSFile::Iter dirIter(directory.c_str()); | 353 SkOSFile::Iter dirIter(directory.c_str()); |
357 while (dirIter.next(&name, true)) { | 354 while (dirIter.next(&name, true)) { |
358 if (name.startsWith(".")) { | 355 if (name.startsWith(".")) { |
359 continue; | 356 continue; |
360 } | 357 } |
361 SkString dirname(directory); | 358 SkString dirname( |
362 dirname.append(name); | 359 SkOSPath::SkPathJoin(directory.c_str(), name.c_str())); |
363 dirname.append(SK_FONT_FILE_DIR_SEPERATOR); | |
364 load_directory_fonts(dirname); | 360 load_directory_fonts(dirname); |
365 } | 361 } |
366 } | 362 } |
367 | 363 |
368 void load_system_fonts(const char* dir) { | 364 void load_system_fonts(const char* dir) { |
369 SkString baseDirectory(dir); | 365 SkString baseDirectory(dir); |
370 load_directory_fonts(baseDirectory); | 366 load_directory_fonts(baseDirectory); |
371 | 367 |
372 if (fFamilies.empty()) { | 368 if (fFamilies.empty()) { |
373 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString()
); | 369 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString()
); |
374 fFamilies.push_back().reset(family); | 370 fFamilies.push_back().reset(family); |
375 family->appendTypeface(SkNEW(SkTypeface_Empty)); | 371 family->appendTypeface(SkNEW(SkTypeface_Empty)); |
376 } | 372 } |
377 | 373 |
378 // Try to pick a default font. | 374 // Try to pick a default font. |
379 static const char* gDefaultNames[] = { | 375 static const char* gDefaultNames[] = { |
380 "Arial", "Verdana", "Times New Roman", NULL | 376 "Arial", "Verdana", "Times New Roman", "Droid Sans", NULL |
381 }; | 377 }; |
382 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { | 378 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { |
383 SkFontStyleSet_Custom* set = this->onMatchFamily(gDefaultNames[i]); | 379 SkFontStyleSet_Custom* set = this->onMatchFamily(gDefaultNames[i]); |
384 if (NULL == set) { | 380 if (NULL == set) { |
385 continue; | 381 continue; |
386 } | 382 } |
387 | 383 |
388 SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_We
ight, | 384 SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_We
ight, |
389 SkFontStyle::kNormal_Wi
dth, | 385 SkFontStyle::kNormal_Wi
dth, |
390 SkFontStyle::kUpright_S
lant)); | 386 SkFontStyle::kUpright_S
lant)); |
(...skipping 12 matching lines...) Expand all Loading... |
403 } | 399 } |
404 | 400 |
405 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; | 401 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; |
406 SkFontStyleSet_Custom* gDefaultFamily; | 402 SkFontStyleSet_Custom* gDefaultFamily; |
407 SkTypeface* gDefaultNormal; | 403 SkTypeface* gDefaultNormal; |
408 }; | 404 }; |
409 | 405 |
410 SkFontMgr* SkFontMgr::Factory() { | 406 SkFontMgr* SkFontMgr::Factory() { |
411 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); | 407 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); |
412 } | 408 } |
OLD | NEW |