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

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

Issue 20672004: Implement onGetTableTags and onGetTableData on Windows. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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 | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 FT_Error setupSize(); 196 FT_Error setupSize();
197 void getBBoxForCurrentGlyph(SkGlyph* glyph, FT_BBox* bbox, 197 void getBBoxForCurrentGlyph(SkGlyph* glyph, FT_BBox* bbox,
198 bool snapToPixelBoundary = false); 198 bool snapToPixelBoundary = false);
199 // Caller must lock gFTMutex before calling this function. 199 // Caller must lock gFTMutex before calling this function.
200 void updateGlyphIfLCD(SkGlyph* glyph); 200 void updateGlyphIfLCD(SkGlyph* glyph);
201 }; 201 };
202 202
203 /////////////////////////////////////////////////////////////////////////// 203 ///////////////////////////////////////////////////////////////////////////
204 /////////////////////////////////////////////////////////////////////////// 204 ///////////////////////////////////////////////////////////////////////////
205 205
206 #include "SkStream.h"
207
208 struct SkFaceRec { 206 struct SkFaceRec {
209 SkFaceRec* fNext; 207 SkFaceRec* fNext;
210 FT_Face fFace; 208 FT_Face fFace;
211 FT_StreamRec fFTStream; 209 FT_StreamRec fFTStream;
212 SkStream* fSkStream; 210 SkStream* fSkStream;
213 uint32_t fRefCnt; 211 uint32_t fRefCnt;
214 uint32_t fFontID; 212 uint32_t fFontID;
215 213
216 // assumes ownership of the stream, will call unref() when its done 214 // assumes ownership of the stream, will call unref() when its done
217 SkFaceRec(SkStream* strm, uint32_t fontID); 215 SkFaceRec(SkStream* strm, uint32_t fontID);
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 // we cache this value, using -1 as a sentinel for "not computed" 1395 // we cache this value, using -1 as a sentinel for "not computed"
1398 if (fGlyphCount < 0) { 1396 if (fGlyphCount < 0) {
1399 AutoFTAccess fta(this); 1397 AutoFTAccess fta(this);
1400 FT_Face face = fta.face(); 1398 FT_Face face = fta.face();
1401 // if the face failed, we still assign a non-negative value 1399 // if the face failed, we still assign a non-negative value
1402 fGlyphCount = face ? face->num_glyphs : 0; 1400 fGlyphCount = face ? face->num_glyphs : 0;
1403 } 1401 }
1404 return fGlyphCount; 1402 return fGlyphCount;
1405 } 1403 }
1406 1404
1405 int SkTypeface_FreeType::onGetTableTags(SkFontTableTag tags[]) const {
1406 AutoFTAccess fta(this);
1407 FT_Face face = fta.face();
1408
1409 FT_ULong tableCount = 0;
1410 FT_Error error;
1411
1412 // When 'tag' is NULL, returns number of tables in 'length'.
1413 error = FT_Sfnt_Table_Info(face, 0, NULL, &tableCount);
1414 if (error) {
1415 return 0;
1416 }
1417
1418 if (tags) {
1419 for (FT_ULong tableIndex = 0; tableIndex < tableCount; ++tableIndex) {
1420 FT_ULong tableTag;
1421 FT_ULong tablelength;
1422 error = FT_Sfnt_Table_Info(face, tableIndex, &tableTag, &tablelength );
1423 if (error) {
1424 return 0;
1425 }
1426 tags[tableIndex] = static_cast<SkFontTableTag>(tableTag);
1427 }
1428 }
1429 return tableCount;
1430 }
1431
1432 size_t SkTypeface_FreeType::onGetTableData(SkFontTableTag tag, size_t offset,
1433 size_t length, void* data) const
1434 {
1435 AutoFTAccess fta(this);
1436 FT_Face face = fta.face();
1437
1438 FT_ULong tableLength = 0;
1439 FT_Error error;
1440
1441 // When 'length' is 0 it is overwritten with the full table length; 'offset' is ignored.
1442 error = FT_Load_Sfnt_Table(face, tag, 0, NULL, &tableLength);
1443 if (error) {
1444 return 0;
1445 }
1446
1447 if (offset > tableLength) {
1448 return 0;
1449 }
1450 FT_ULong size = SkTMin(length, tableLength - offset);
1451 if (NULL != data) {
1452 error = FT_Load_Sfnt_Table(face, tag, offset, reinterpret_cast<FT_Byte*> (data), &size);
1453 if (error) {
1454 return 0;
1455 }
1456 }
1457
1458 return size;
1459 }
1460
1407 /////////////////////////////////////////////////////////////////////////////// 1461 ///////////////////////////////////////////////////////////////////////////////
1408 /////////////////////////////////////////////////////////////////////////////// 1462 ///////////////////////////////////////////////////////////////////////////////
1409 1463
1410 /* Export this so that other parts of our FonttHost port can make use of our 1464 /* Export this so that other parts of our FonttHost port can make use of our
1411 ability to extract the name+style from a stream, using FreeType's api. 1465 ability to extract the name+style from a stream, using FreeType's api.
1412 */ 1466 */
1413 bool find_name_and_attributes(SkStream* stream, SkString* name, 1467 bool find_name_and_attributes(SkStream* stream, SkString* name,
1414 SkTypeface::Style* style, bool* isFixedPitch) { 1468 SkTypeface::Style* style, bool* isFixedPitch) {
1415 FT_Library library; 1469 FT_Library library;
1416 if (FT_Init_FreeType(&library)) { 1470 if (FT_Init_FreeType(&library)) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 *style = (SkTypeface::Style) tempStyle; 1513 *style = (SkTypeface::Style) tempStyle;
1460 } 1514 }
1461 if (isFixedPitch) { 1515 if (isFixedPitch) {
1462 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1516 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1463 } 1517 }
1464 1518
1465 FT_Done_Face(face); 1519 FT_Done_Face(face);
1466 FT_Done_FreeType(library); 1520 FT_Done_FreeType(library);
1467 return true; 1521 return true;
1468 } 1522 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698