blob: 6bd3532d66f03d330af27fc0d8e868511485aaa3 [file] [log] [blame]
george@mozilla.comc59b5da2012-08-23 00:39:08 +00001/*
2 * Copyright 2006-2012 The Android Open Source Project
3 * Copyright 2012 Mozilla Foundation
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SKFONTHOST_FREETYPE_COMMON_H_
10#define SKFONTHOST_FREETYPE_COMMON_H_
11
12#include "SkGlyph.h"
13#include "SkScalerContext.h"
reed@google.com0da48612013-03-19 16:06:52 +000014#include "SkTypeface.h"
15
george@mozilla.comc59b5da2012-08-23 00:39:08 +000016#include <ft2build.h>
17#include FT_FREETYPE_H
18
19#ifdef SK_DEBUG
20 #define SkASSERT_CONTINUE(pred) \
21 do { \
22 if (!(pred)) \
23 SkDebugf("file %s:%d: assert failed '" #pred "'\n", __FILE__, __LINE__); \
24 } while (false)
25#else
26 #define SkASSERT_CONTINUE(pred)
27#endif
28
29
30class SkScalerContext_FreeType_Base : public SkScalerContext {
reed@google.com0da48612013-03-19 16:06:52 +000031protected:
george@mozilla.comc59b5da2012-08-23 00:39:08 +000032 // See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
33 // This value was chosen by eyeballing the result in Firefox and trying to match it.
34 static const FT_Pos kBitmapEmboldenStrength = 1 << 6;
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000035
reed@google.com0da48612013-03-19 16:06:52 +000036 SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc)
37 : INHERITED(typeface, desc)
george@mozilla.comc59b5da2012-08-23 00:39:08 +000038 {}
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000039
bungeman@google.coma76de722012-10-26 19:35:54 +000040 void generateGlyphImage(FT_Face face, const SkGlyph& glyph);
sugoi@google.com66a58ac2013-03-05 20:40:52 +000041 void generateGlyphPath(FT_Face face, SkPath* path);
george@mozilla.comc59b5da2012-08-23 00:39:08 +000042 void emboldenOutline(FT_Face face, FT_Outline* outline);
reed@google.com0da48612013-03-19 16:06:52 +000043
44private:
45 typedef SkScalerContext INHERITED;
46};
47
48class SkTypeface_FreeType : public SkTypeface {
49protected:
bungeman@google.comfe747652013-03-25 19:36:11 +000050 SkTypeface_FreeType(Style style, SkFontID uniqueID, bool isFixedPitch)
reed@google.comb4162b12013-07-02 16:32:29 +000051 : INHERITED(style, uniqueID, isFixedPitch)
52 , fGlyphCount(-1)
53 {}
reed@google.com0da48612013-03-19 16:06:52 +000054
55 virtual SkScalerContext* onCreateScalerContext(
56 const SkDescriptor*) const SK_OVERRIDE;
57 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
reed@google.com2689f612013-03-20 20:01:47 +000058 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
59 SkAdvancedTypefaceMetrics::PerGlyphInfo,
60 const uint32_t*, uint32_t) const SK_OVERRIDE;
reed@google.com38c37dd2013-03-21 15:36:26 +000061 virtual int onGetUPEM() const SK_OVERRIDE;
62
reed@google.comb4162b12013-07-02 16:32:29 +000063 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
64 int glyphCount) const SK_OVERRIDE;
65 virtual int onCountGlyphs() const SK_OVERRIDE;
66
reed@google.com0da48612013-03-19 16:06:52 +000067private:
reed@google.comb4162b12013-07-02 16:32:29 +000068 mutable int fGlyphCount;
69
reed@google.com0da48612013-03-19 16:06:52 +000070 typedef SkTypeface INHERITED;
george@mozilla.comc59b5da2012-08-23 00:39:08 +000071};
72
73#endif // SKFONTHOST_FREETYPE_COMMON_H_