[go: up one dir, main page]

Menu

[r239]: / tags / 1.1.3 / src / util.cpp  Maximize  Restore  History

Download this file

86 lines (68 with data), 2.6 kB

 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
/** @file
* libLASi provides a C++ output stream interface for writing multi-language Postscript documents.
* Copyright (C) 2003 Larry Siden.
* See README file in project root directory for copyright and contact info.
* See COPYING file in project root for terms of re-distribution.
*/
#include "util.h"
#include <sstream>
#include <iostream>
#include <ft2build.h>
#include FT_FREETYPE_H
using namespace std;
static const std::string glyph_format_to_string(const FT_Glyph_Format format) {
if (0 == format)
return "none";
string s;
s.append(1, (char)((format & 0xff000000) >> 24));
s.append(1, (char)((format & 0x00ff0000) >> 16));
s.append(1, (char)((format & 0x0000ff00) >> 8));
s.append(1, (char)((format & 0x000000ff)));
return s;
}
static const std::string tag_to_string(const int tag) {
switch (tag & 0x03) {
case FT_Curve_Tag_On:
return "on";
case FT_Curve_Tag_Conic:
return "conic";
case FT_Curve_Tag_Cubic:
return "cubic";
default:
ostringstream ostr;
ostr << "0x" << hex << (int) tag << dec;
return ostr.str();
}
}
ostream& operator<<(ostream& os, const FT_Library ft_library) {
os << "ft_library=" << hex << (unsigned char&)ft_library << dec << endl;
FT_Int amajor, aminor, apatch;
FT_Library_Version(ft_library, &amajor, &aminor, &apatch);
os << "FreeType lib version " << amajor << "." << aminor << "-" << apatch << endl;
return os;
}
ostream& operator<<(ostream& os, const FT_Face ft_face) {
os << "ft_face=" << hex << (unsigned char&)ft_face << dec << endl;
os << "family name: " << ft_face->family_name << endl;
os << "style name: " << ft_face->family_name << endl;
return os;
}
ostream& operator<<(ostream& os, const FT_Glyph ft_glyph) {
os << "ft_glyph=" << hex << (unsigned char&)ft_glyph << dec << endl;
os << "glyph format is " << glyph_format_to_string(ft_glyph->format) << endl;
return os;
}
ostream& operator<<(ostream& os, const FT_Outline outline) {
os << "n_contours=" << outline.n_contours << ", n_points=" << outline.n_points << endl;
//const FT_Vector* pEndVector = &outline.points[outline.n_points];
int ipt = 0; // i-th point in outline.points[]
for (int iContour=0 ; iContour < outline.n_contours ; ++iContour) {
os << "countour[" << iContour << "]=" << outline.contours[iContour] << endl;
for (; ipt <= outline.contours[iContour] ; ++ipt) {
const FT_Vector ftvec = outline.points[ipt];
const char tag = outline.tags[ipt];
os << ftvec.x / 64.0 << " " << ftvec.y / 64.0 << " " << tag_to_string(tag) << endl;
}
}
return os;
}