blob: 8ae872c1dac58130894f93c2cb5c5103d9e72f96 [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"
bungeman14df8332014-10-28 15:07:23 -070015#include "SkTypes.h"
reed@google.com0da48612013-03-19 16:06:52 +000016
george@mozilla.comc59b5da2012-08-23 00:39:08 +000017#include <ft2build.h>
18#include FT_FREETYPE_H
19
george@mozilla.comc59b5da2012-08-23 00:39:08 +000020class SkScalerContext_FreeType_Base : public SkScalerContext {
reed@google.com0da48612013-03-19 16:06:52 +000021protected:
george@mozilla.comc59b5da2012-08-23 00:39:08 +000022 // See http://freetype.sourceforge.net/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
23 // This value was chosen by eyeballing the result in Firefox and trying to match it.
24 static const FT_Pos kBitmapEmboldenStrength = 1 << 6;
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000025
reed@google.com0da48612013-03-19 16:06:52 +000026 SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc)
27 : INHERITED(typeface, desc)
george@mozilla.comc59b5da2012-08-23 00:39:08 +000028 {}
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000029
bungeman@google.coma76de722012-10-26 19:35:54 +000030 void generateGlyphImage(FT_Face face, const SkGlyph& glyph);
sugoi@google.com66a58ac2013-03-05 20:40:52 +000031 void generateGlyphPath(FT_Face face, SkPath* path);
reed@google.com0da48612013-03-19 16:06:52 +000032
33private:
34 typedef SkScalerContext INHERITED;
35};
36
37class SkTypeface_FreeType : public SkTypeface {
bungeman3a21d612014-07-11 08:52:26 -070038public:
39 /** For SkFontMgrs to make use of our ability to extract
40 * name and style from a stream, using FreeType's API.
41 */
bungeman14df8332014-10-28 15:07:23 -070042 class Scanner : ::SkNoncopyable {
43 public:
44 Scanner();
45 ~Scanner();
bungeman05773ed2015-05-13 10:57:09 -070046 struct AxisDefinition {
47 SkFourByteTag fTag;
48 SkFixed fMinimum;
49 SkFixed fDefault;
50 SkFixed fMaximum;
51 };
52 using AxisDefinitions = SkSTArray<4, AxisDefinition, true>;
bungeman14df8332014-10-28 15:07:23 -070053 bool recognizedFont(SkStream* stream, int* numFonts) const;
54 bool scanFont(SkStream* stream, int ttcIndex,
bungeman05773ed2015-05-13 10:57:09 -070055 SkString* name, SkFontStyle* style, bool* isFixedPitch,
56 AxisDefinitions* axes) const;
bungeman14df8332014-10-28 15:07:23 -070057 private:
58 FT_Face openFace(SkStream* stream, int ttcIndex, FT_Stream ftStream) const;
59 FT_Library fLibrary;
60 mutable SkMutex fLibraryMutex;
61 };
bungeman3a21d612014-07-11 08:52:26 -070062
reed@google.com0da48612013-03-19 16:06:52 +000063protected:
bungemana4c4a2d2014-10-20 13:33:19 -070064 SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch)
reed@google.comb4162b12013-07-02 16:32:29 +000065 : INHERITED(style, uniqueID, isFixedPitch)
66 , fGlyphCount(-1)
67 {}
reed@google.com0da48612013-03-19 16:06:52 +000068
69 virtual SkScalerContext* onCreateScalerContext(
mtklein36352bf2015-03-25 18:17:31 -070070 const SkDescriptor*) const override;
71 void onFilterRec(SkScalerContextRec*) const override;
reed39a9a502015-05-12 09:50:04 -070072 SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
73 PerGlyphInfo, const uint32_t*, uint32_t) const override;
mtklein36352bf2015-03-25 18:17:31 -070074 int onGetUPEM() const override;
reed@google.com35fe7372013-10-30 15:07:03 +000075 virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
mtklein36352bf2015-03-25 18:17:31 -070076 int32_t adjustments[]) const override;
reed@google.comb4162b12013-07-02 16:32:29 +000077 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
mtklein36352bf2015-03-25 18:17:31 -070078 int glyphCount) const override;
79 int onCountGlyphs() const override;
reed@google.comb4162b12013-07-02 16:32:29 +000080
mtklein36352bf2015-03-25 18:17:31 -070081 LocalizedStrings* onCreateFamilyNameIterator() const override;
bungeman@google.coma9802692013-08-07 02:45:25 +000082
mtklein36352bf2015-03-25 18:17:31 -070083 int onGetTableTags(SkFontTableTag tags[]) const override;
bungeman@google.comddc218e2013-08-01 22:29:43 +000084 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
mtklein36352bf2015-03-25 18:17:31 -070085 size_t length, void* data) const override;
bungeman@google.comddc218e2013-08-01 22:29:43 +000086
reed@google.com0da48612013-03-19 16:06:52 +000087private:
reed@google.comb4162b12013-07-02 16:32:29 +000088 mutable int fGlyphCount;
89
reed@google.com0da48612013-03-19 16:06:52 +000090 typedef SkTypeface INHERITED;
george@mozilla.comc59b5da2012-08-23 00:39:08 +000091};
92
93#endif // SKFONTHOST_FREETYPE_COMMON_H_