summaryrefslogtreecommitdiff
path: root/src/vg/Font.h
blob: 2356c690d19527ef112fe9f497e408f1231fc91e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef __FONT_H
#define __FONT_H

/*------------------------------------------------------------------------
 *
 * OpenVG 1.1 Reference Implementation
 * -----------------------------------
 *
 * Copyright (c) 2007 The Khronos Group Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and /or associated documentation files
 * (the "Materials "), to deal in the Materials without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Materials,
 * and to permit persons to whom the Materials are furnished to do so,
 * subject to the following conditions: 
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Materials. 
 *
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
 * THE USE OR OTHER DEALINGS IN THE MATERIALS.
 *
 *//**
 * \file
 * \brief	VGContext class. Used for storing OpenVG state.
 * \note	
 *//*-------------------------------------------------------------------*/

#include "VG/openvg.h"
#include "Math.h"
#include "Array.h"
#include "Path.h"
#include "Image.h"

//==============================================================================================

namespace tgOpenVG
{

/*-------------------------------------------------------------------*//*!
* \brief	Storage and operations for VGFont.
* \param	
* \return	
* \note		
*//*-------------------------------------------------------------------*/

class Font
{
public:
	struct Glyph
	{
        enum State
        {
            GLYPH_UNINITIALIZED     = 0,
            GLYPH_PATH              = 1,
            GLYPH_IMAGE             = 2
        };
		Glyph()				{ m_state = GLYPH_UNINITIALIZED; m_path = m_image = VG_INVALID_HANDLE; m_isHinted = false; m_origin(0.0f, 0.0f); m_escapement(0.0f, 0.0f); }
        unsigned int m_index;
        State        m_state;
		VGPath		 m_path;
		VGImage		 m_image;
		bool		 m_isHinted;
		Vector2		 m_origin;
		Vector2		 m_escapement;
	};

	Font(int capacityHint);	//throws bad_alloc
	~Font();

	int				getNumGlyphs() const					{ int n=0; for(int i=0;i<m_glyphs.size();i++) { if(m_glyphs[i].m_state != Glyph::GLYPH_UNINITIALIZED) n++; } return n; }
	void			addReference()							{ m_referenceCount++; }
	int				removeReference()						{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }

	void			setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement);    //throws bad_alloc
	void			setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement);    //throws bad_alloc
    Glyph*          findGlyph(unsigned int index);
    void            clearGlyph(Glyph* g);
private:
	Font(const Font&);						//!< Not allowed.
	void operator=(const Font&);			//!< Not allowed.

    Glyph*          newGlyph();    //throws bad_alloc

	int				m_referenceCount;
	Array<Glyph>	m_glyphs;
};

//=======================================================================

}	//namespace tgOpenVG

//=======================================================================

#endif /* __FONT_H */