2
#include "GlobalParams.h"
3
#include "UnicodeMap.h"
11
const int font_num=13;
13
static Fonts fonts[font_num+1]={
14
{"Courier", "Courier" },
15
{"Courier-Bold", "Courier"},
16
{"Courier-BoldOblique", "Courier"},
17
{"Courier-Oblique", "Courier"},
18
{"Helvetica", "Helvetica"},
19
{"Helvetica-Bold", "Helvetica"},
20
{"Helvetica-BoldOblique", "Helvetica"},
21
{"Helvetica-Oblique", "Helvetica"},
22
{"Symbol", "Symbol" },
23
{"Times-Bold", "Times" },
24
{"Times-BoldItalic", "Times" },
25
{"Times-Italic", "Times" },
26
{"Times-Roman", "Times" },
30
#define xoutRound(x) ((int)(x + 0.5))
33
GooString* HtmlFont::DefaultFont=new GooString("Times"); // Arial,Helvetica,sans-serif
35
HtmlFontColor::HtmlFontColor(GfxRGB rgb){
36
r=static_cast<int>(255*rgb.r);
37
g=static_cast<int>(255*rgb.g);
38
b=static_cast<int>(255*rgb.b);
39
if (!(Ok(r)&&Ok(b)&&Ok(g))) {printf("Error : Bad color \n");r=0;g=0;b=0;}
42
GooString *HtmlFontColor::convtoX(unsigned int xcol) const{
43
GooString *xret=new GooString();
47
if ((k>=0)&&(k<10)) tmp=(char) ('0'+k); else tmp=(char)('a'+k-10);
50
if ((k>=0)&&(k<10)) tmp=(char) ('0'+k); else tmp=(char)('a'+k-10);
55
GooString *HtmlFontColor::toString() const{
56
GooString *tmp=new GooString("#");
57
GooString *tmpr=convtoX(r);
58
GooString *tmpg=convtoX(g);
59
GooString *tmpb=convtoX(b);
69
HtmlFont::HtmlFont(GooString* ftname,int _size, GfxRGB rgb){
70
//if (col) color=HtmlFontColor(col);
71
//else color=HtmlFontColor();
72
color=HtmlFontColor(rgb);
74
GooString *fontname = NULL;
77
fontname = new GooString(ftname);
78
FontName=new GooString(ftname);
92
if (strstr(fontname->lowerCase()->getCString(),"bold")) bold=gTrue;
94
if (strstr(fontname->lowerCase()->getCString(),"italic")||
95
strstr(fontname->lowerCase()->getCString(),"oblique")) italic=gTrue;
98
while (strcmp(ftname->getCString(),fonts[i].Fontname)&&(i<font_num))
105
if (!DefaultFont) DefaultFont=new GooString(fonts[font_num].name);
109
HtmlFont::HtmlFont(const HtmlFont& x){
116
if (x.FontName) FontName=new GooString(x.FontName);
120
HtmlFont::~HtmlFont(){
121
if (FontName) delete FontName;
124
HtmlFont& HtmlFont::operator=(const HtmlFont& x){
125
if (this==&x) return *this;
132
if (FontName) delete FontName;
133
if (x.FontName) FontName=new GooString(x.FontName);
137
void HtmlFont::clear(){
138
if(DefaultFont) delete DefaultFont;
145
This function is used to compare font uniquily for insertion into
146
the list of all encountered fonts
148
GBool HtmlFont::isEqual(const HtmlFont& x) const{
149
return ((size==x.size) &&
150
(lineSize==x.lineSize) &&
151
(pos==x.pos) && (bold==x.bold) && (italic==x.italic) &&
152
(color.isEqual(x.getColor())));
156
This one is used to decide whether two pieces of text can be joined together
157
and therefore we don't care about bold/italics properties
159
GBool HtmlFont::isEqualIgnoreBold(const HtmlFont& x) const{
160
return ((size==x.size) &&
161
(!strcmp(fonts[pos].name, fonts[x.pos].name)) &&
162
(color.isEqual(x.getColor())));
165
GooString* HtmlFont::getFontName(){
166
if (pos!=font_num) return new GooString(fonts[pos].name);
167
else return new GooString(DefaultFont);
170
GooString* HtmlFont::getFullName(){
172
return new GooString(FontName);
173
else return new GooString(DefaultFont);
176
void HtmlFont::setDefaultFont(GooString* defaultFont){
177
if (DefaultFont) delete DefaultFont;
178
DefaultFont=new GooString(defaultFont);
182
GooString* HtmlFont::getDefaultFont(){
186
// this method if plain wrong todo
187
GooString* HtmlFont::HtmlFilter(Unicode* u, int uLen) {
188
GooString *tmp = new GooString();
193
// get the output encoding
194
if (!(uMap = globalParams->getTextEncoding())) {
198
for (int i = 0; i < uLen; ++i) {
201
case '"': tmp->append("""); break;
202
case '&': tmp->append("&"); break;
203
case '<': tmp->append("<"); break;
204
case '>': tmp->append(">"); break;
207
// convert unicode to string
208
if ((n = uMap->mapUnicode(u[i], buf, sizeof(buf))) > 0) {
219
GooString* HtmlFont::simple(HtmlFont* font, Unicode* content, int uLen){
220
GooString *cont=HtmlFilter (content, uLen);
222
/*if (font.isBold()) {
223
cont->insert(0,"<b>",3);
224
cont->append("</b>",4);
226
if (font.isItalic()) {
227
cont->insert(0,"<i>",3);
228
cont->append("</i>",4);
234
HtmlFontAccu::HtmlFontAccu(){
235
accu=new GVector<HtmlFont>();
238
HtmlFontAccu::~HtmlFontAccu(){
239
if (accu) delete accu;
242
int HtmlFontAccu::AddFont(const HtmlFont& font){
243
GVector<HtmlFont>::iterator i;
244
for (i=accu->begin();i!=accu->end();i++)
246
if (font.isEqual(*i))
248
return (int)(i-(accu->begin()));
252
accu->push_back(font);
253
return (accu->size()-1);
256
// get CSS font name for font #i
257
GooString* HtmlFontAccu::getCSStyle(int i, GooString* content){
259
GooString *iStr=GooString::fromInt(i);
262
tmp = new GooString("<span class=\"ft");
265
tmp->append(content);
266
tmp->append("</span>");
268
tmp = new GooString("");
269
tmp->append(content);
276
// get CSS font definition for font #i
277
GooString* HtmlFontAccu::CSStyle(int i){
278
GooString *tmp=new GooString();
279
GooString *iStr=GooString::fromInt(i);
281
GVector<HtmlFont>::iterator g=accu->begin();
284
GooString *Size=GooString::fromInt(font.getSize());
285
GooString *colorStr=font.getColor().toString();
286
GooString *fontName=font.getFontName();
292
tmp->append("{font-size:");
294
if( font.getLineSize() != -1 )
296
lSize = GooString::fromInt(font.getLineSize());
297
tmp->append("px;line-height:");
301
tmp->append("px;font-family:");
302
tmp->append(fontName); //font.getFontName());
303
tmp->append(";color:");
304
tmp->append(colorStr);
308
tmp->append("<fontspec id=\"");
310
tmp->append("\" size=\"");
312
tmp->append("\" family=\"");
313
tmp->append(fontName); //font.getFontName());
314
tmp->append("\" color=\"");
315
tmp->append(colorStr);