File: GlyphBoundaries.h

package info (click to toggle)
grcompiler 5.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,020 kB
  • sloc: cpp: 48,200; ansic: 7,670; sh: 4,427; makefile: 197; xml: 190; perl: 127; sed: 21
file content (149 lines) | stat: -rw-r--r-- 4,284 bytes parent folder | download | duplicates (2)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: GlyphBoundaries.h
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    A data structure that approximates the boundaries of the glyph.
-------------------------------------------------------------------------------*//*:End Ignore*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef GLYPHBOUND_INCLUDED
#define GLYPHBOUND_INCLUDED


const double gbcUndef = 123456.7;	// undefined value - hopefully this is large enough that
									//it will never be used for real

/*----------------------------------------------------------------------------------------------
Class: GlyphBoundCell
Description: A single cell of the glyph boundaries. 
Hungarian: gbcell
----------------------------------------------------------------------------------------------*/

class GlyphBoundaryCell
{
	friend class GlyphBoundaries;

	enum GbcIndices {
		// indices into enter/exit arrays:
		gbcMin = 0,
		gbcMax = 1,
	};

protected:
	GlyphBoundaryCell();
	void Initialize();
	void AddEntryMinMax(int gbcSide, int mVal);
	void AddExitMinMax( int gbcSide, int mVal);
	bool HasData();
	bool HasEntry(int nSide);
	bool HasExit(int nSide);

protected:
	// Instance variables:
	float m_dValues[8];	// 8: left, right, bottom, top, four diagonals

	// Where the glyph curve enters and exits the cell on each side;
	// these are in em-units
	int m_mEntry[4][2];	// 4: left, right, bottom, top, 2: min, max
	int m_mExit[4][2];
};


/*----------------------------------------------------------------------------------------------
Class: GlyphBoundaries
Description: A data structure that approximates the boundaries of the glyph
Hungarian: gbdy
----------------------------------------------------------------------------------------------*/

class GlyphBoundaries
{
	friend class GlyphBoundaryCell;

	enum {
		gbgridCellsH = 4,	// number of horizontal cells
		gbgridCellsV = 4	// number of vertical cells
	};

	enum GbcIndices {
		gbcLeft = 0,
		gbcRight,
		gbcBottom,
		gbcTop,
		gbcDPMin,	// minimal positively-sloped diagonal
		gbcDPMax,	// maximal positively-sloped diagonal
		gbcDNMin,	// minimal negatively-sloped diagonal
		gbcDNMax,	// maximal negatively-sloped diagonal
	};

public:
	//	Constructors & destructors:
	//GlyphBoundaries(GrcFont * pfont, gid16 wGlyphID)
	//	: m_pfont(pfont)
	//{
	//}

	~GlyphBoundaries()
	{
	}

	void Initialize(gid16 wGlyphID)
	{
		m_wGlyphID = wGlyphID;
	}

	void OverlayGrid(GrcFont * pfont, bool fComplex);
	int CellGridBitmap();

protected:
	// Cell data is in the order: (0,0), (1,0), (2,0), (3,0), (1,0), (1,1), ...
	// where (0,0) is the lower left cell, (3,3) is the upper right.
	int CellIndex(int x, int y) { return (y * gbgridCellsH) + x; }

	void NormalizePoint(int mx, int my, float * pdx, float * pdy);
	void UnnormalizePoint(float dx, float dy, int * pmx, int * pmy);
	void NormalizeSumAndDiff(int mSum, int mDiff, float * pdSum, float * pdDiff);
	void UnnormalizeSumAndDiff(float dSum, float dDiff, int * pmSum, int * pmDiff);
	void AddPoint(int icellX, int icellY, int mx, int my, float dx, float dy, bool fEntire);
	void AddEntryMinMax(int icellX, int icellY, int gbcSide, int mVal);
	void AddExitMinMax( int icellX, int icellY, int gbcSide, int mVal);

	void ClearSubBoxCells();
	void RoundSubBoxCells();

	// Compiler:
public:
	int OutputToGlat(GrcBinaryStream * pbstrm);
	static int OutputToGlatNonexistent(GrcBinaryStream * pbstrm);
	bool ComplexFit();
	void DebugXml(std::ofstream & strmOut);
protected:
	int OutputGlatFullDiagonals(GrcBinaryStream * pbstrm);
	int OutputGlatSubBox(GrcBinaryStream * pbstrm, int icellX, int icellY);

protected:
	//	Instance variables:
	GrcFont * m_pfont;
	utf16 m_wGlyphID;		// the glyph these are the boundaries for
	// Cache glyph metrics:
	int m_mxBbMin;
	int m_mxBbMax;
	int m_myBbMin;
	int m_myBbMax;

	// Values for full glyph
	GlyphBoundaryCell m_gbcellEntire;

	// Sub-box cells
	GlyphBoundaryCell m_rggbcellSub[gbgridCellsH * gbgridCellsV];
};


#endif // GLYPHBOUND_INCLUDED