PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PlatformFont_RTL.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/platforms/sdl/PlatformFont.h
4// Purpose: Contains platform-specific font class.
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PLATFORMFONT_H__
28#define __PLATFORMFONT_H__
29
30#include "../../objects/PFont.h"
31#include "../../objects/PColor.h"
32#include "../../utility/rc_ptrs.h"
33#include "../../base/PEBLObject.h"
34
35#include "SDLUtility.h"
36
37
38#ifdef PEBL_OSX
39#include "SDL.h"
40#include "SDL_ttf.h"
41#else
42#include "SDL.h"
43#include "SDL_ttf.h"
44#endif
45
46
47//This is a modified platform font that attempts to use harfbuzz renderer
48//to support RTL and other craziness
49
50
51#include <ft2build.h>
52#include FT_FREETYPE_H
53#include FT_OUTLINE_H
54#include <harfbuzz/hb.h>
55#include <harfbuzz/hb-ft.h>
56
57
58
63
64class PlatformFont: virtual public PFont
65{
66
67public:
68 // PlatformFont();
69 PlatformFont(const std::string & filename);
70 PlatformFont(const std::string & filename, int style, int size, PColor fgcolor, PColor bgcolor, bool aa);
72 virtual ~PlatformFont();
73
74 virtual void SetFontColor (PColor color);
75 virtual void SetBackgroundColor (PColor color);
76// virtual PColor GetFontColor () const {return SDLUtility::SDLColorToPColor(mSDL_FGColor);}
77// virtual PColor GetBackgroundColor() const {return SDLUtility::SDLColorToPColor(mSDL_BGColor);}
78
80 //SDL_Texture * DrawTextHB(const std::wstring & text);
81 SDL_Texture * RenderTexture(const std::wstring & text);
82 SDL_Texture * RenderText(const std::wstring & text);
83
84 unsigned int GetTextWidth(const std::string & text);
85 unsigned int GetTextHeight(const std::string & text);
86 unsigned int GetPosition(const std::string & text, unsigned int x);
87 virtual std::string ObjectName() const{return "Platform Font";};
88
89protected:
90 virtual std::ostream & SendToStream(std::ostream& out) const;
91
92private:
93
94 std::string StripText(const std::string & text);
95
96 char* mBuffer; //buffer to hold font cached memory.
97 FT_Library * mLibrary;// FT library reference
98 //TTF_Font * mTTF_Font;
99 FT_Face * mFace; //freetype face
100 bh_font_t * mHBFont; //harfbuzz font
101
102 SDL_Color mSDL_FGColor;
103 SDL_Color mSDL_BGColor;
104};
105
106
107#endif
Definition PFont.h:53
PlatformFont(const std::string &filename, int style, int size, PColor fgcolor, PColor bgcolor, bool aa)
unsigned int GetTextHeight(const std::string &text)
SDL_Surface * RenderText(const std::string &text)
This takes care of all the busy work of rendering the text.
virtual std::string ObjectName() const
virtual void SetBackgroundColor(PColor color)
SDL_Texture * RenderTexture(const std::wstring &text)
This takes care of all the busy work of rendering the text.
PlatformFont(const std::string &filename)
unsigned int GetTextWidth(const std::string &text)
unsigned int GetPosition(const std::string &text, unsigned int x)
virtual std::ostream & SendToStream(std::ostream &out) const
This sends the font descriptions to the specified stream.
virtual void SetFontColor(PColor color)
virtual ~PlatformFont()
Copy constructor.
PlatformFont(PlatformFont &font)