1 /*
2  * Vertical Device Metrics
3  *
4  * Copyright © 1997-1998  Herbert Duerr
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free Softaware
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #include "ttf.h"
23 
VdmxTable(RandomAccessFile & f,int offset,int length)24 VdmxTable::VdmxTable(RandomAccessFile &f, int offset, int length):
25 	RandomAccessFile(f, offset, length)
26 {
27 	/* int version = */ readUShort();
28 	nRecords = readSShort();
29 	nRatios = readUShort();
30 }
31 
32 int
getYmax(int pelHeight,int xres,int yres,int * ymax,int * ymin)33 VdmxTable::getYmax(int pelHeight, int xres, int yres, int *ymax, int *ymin)
34 {
35 	uint16_t offset = 0;
36 
37 	for (int i = nRatios; --i >= 0;) {
38 		/* uint8_t charSet = */ readUByte();
39 		uint8_t xRatio = readUByte();
40 		uint8_t yStartRatio= readUByte();
41 		uint8_t yEndRatio = readUByte();
42 		uint16_t tmp = readUShort();
43 
44 		if ((yres * xRatio >= xres * yStartRatio) &&
45 		    (yres * xRatio <= xres * yEndRatio)) {
46 			offset = tmp;
47 			break;
48 		}
49 	}
50 
51 	if (offset == 0)
52 		return 0;
53 
54 	seekAbsolute(offset);
55 
56 	int nrecs = readUShort();
57 	uint8_t startSize = readUByte();
58 	uint8_t endSize = readUByte();
59 
60 	if (pelHeight < startSize || pelHeight > endSize)
61 		return 0;
62 
63 	// XXX: should be a binary search
64 	while (--nrecs >= 0) {
65 		uint16_t ph = readUShort();
66 		int16_t y1 = readSShort();
67 		int16_t y2 = readSShort();
68 
69 		if (pelHeight == ph) {
70 			*ymax = y1;
71 			*ymin = y2;
72 			return 1;
73 		}
74 	}
75 
76 	return 1;
77 }
78