1 //
2 // Copyright (c) 2008-2017 the Urho3D project.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 //
22 
23 #pragma once
24 
25 #include "../UI/FontFace.h"
26 
27 namespace Urho3D
28 {
29 
30 class FreeTypeLibrary;
31 class Texture2D;
32 
33 /// Free type font face description.
34 class URHO3D_API FontFaceFreeType : public FontFace
35 {
36 public:
37     /// Construct.
38     FontFaceFreeType(Font* font);
39     /// Destruct.
40     ~FontFaceFreeType();
41 
42     /// Load font face.
43     virtual bool Load(const unsigned char* fontData, unsigned fontDataSize, float pointSize);
44     /// Return pointer to the glyph structure corresponding to a character. Return null if glyph not found.
45     virtual const FontGlyph* GetGlyph(unsigned c);
46 
47     /// Return if font face uses mutable glyphs.
HasMutableGlyphs()48     virtual bool HasMutableGlyphs() const { return hasMutableGlyph_; }
49 
50 private:
51     /// Setup next texture.
52     bool SetupNextTexture(int textureWidth, int textureHeight);
53     /// Load char glyph.
54     bool LoadCharGlyph(unsigned charCode, Image* image = 0);
55     /// Smooth one row of a horizontally oversampled glyph image.
56     void BoxFilter(unsigned char* dest, size_t destSize, const unsigned char* src, size_t srcSize);
57 
58     /// FreeType library.
59     SharedPtr<FreeTypeLibrary> freeType_;
60     /// FreeType face. Non-null after creation only in dynamic mode.
61     void* face_;
62     /// Load mode.
63     int loadMode_;
64     /// Use subpixel glyph positioning?
65     bool subpixel_;
66     /// Oversampling level.
67     int oversampling_;
68     /// Ascender.
69     float ascender_;
70     /// Has mutable glyph.
71     bool hasMutableGlyph_;
72     /// Glyph area allocator.
73     AreaAllocator allocator_;
74 };
75 
76 }
77