23#include <tqfontmetrics.h>
24#include <tqfontdatabase.h>
38TQColor toColor(GfxRGB &rgb)
40 return TQColor(tqRound(rgb.r*255), tqRound(rgb.g*255), tqRound(rgb.b*255));
44bool DRect::operator ==( const DRect &r) const
46 return ( equal(_top, r._top) && equal(_bottom, r._bottom)
47 && equal(_left, r._left) && equal(_right, r._right) );
50bool DRect::isInside( const DRect &r, double percent) const
52 return ( more(r._top, _top, percent) && less(r._bottom, _bottom, percent)
53 && more(r._left, _left, percent)
54 && less(r._right, _right, percent) );
57void DRect::unite( const DRect &r)
59 if ( !r.isValid() ) return;
64 _left = kMin(_left, r._left);
65 _right = kMax(_right, r._right);
66 _top = kMin(_top, r._top);
67 _bottom = kMax(_bottom, r._bottom);
70TQString DRect::toString() const
72 if ( !isValid() ) return "invalid rect";
73 return TQString( "left=%1 right=%2 top=%3 bottom=%4").arg(_left).arg(_right)
74 .arg(_top).arg(_bottom);
77bool DPath::isRectangle() const
79 if ( size()!=5 ) return false;
80 if ( !equal(at(0).x, at(3).x) || !equal(at(0).x, at(4).x) ) return false;
81 if ( !equal(at(0).y, at(1).y) || !equal(at(0).y, at(4).y) ) return false;
82 if ( !equal(at(1).x, at(2).x) || !equal(at(2).y, at(3).y) ) return false;
86DRect DPath::boundingRect() const
88 if ( size()==0 ) return DRect();
89 DRect r(at(0).x, at(0).x, at(0).y, at(0).y);
90 for (uint i=1; i<size(); i++) {
91 r.setTop( kMin(r.top(), at(i).y) );
92 r.setBottom( kMax(r.bottom(), at(i).y) );
93 r.setLeft( kMin(r.left(), at(i).x) );
94 r.setRight( kMax(r.right(), at(i).x) );
101TQDict<Font::Data> *Font::_dict = 0;
102const char *Font::FAMILY_DATA[Nb_Family] = {
103 "Times", "Helvetica", "Courier", "Symbol"
108 Q_ASSERT( _dict==0 );
109 _dict = new TQDict<Data>(100, false);
110 _dict->setAutoDelete( true);
120 : _pointSize(12), _color(TQt::black)
125Font::Font( const GfxState *state, double size)
127 if ( size<1 ) kdDebug(30516) << "very small font size=" << size << endl;
128 _pointSize = tqRound(size);
131 state->getFillRGB(&rgb);
132 _color = toColor(rgb);
134 GfxFont *font = state->getFont();
135 GString *gname = (font ? font->getName() : 0);
136 TQString name = (gname ? gname->getCString() : 0);
138 name = name.section( '+', 1, 1).lower();
139 if ( name.isEmpty() ) name = "##dummy";
149static const KnownData KNOWN_DATA[] = {
151 { "times-roman", Times, Regular, false },
152 { "times-bolditalic", Times, BoldItalic, false },
153 { "times-bold", Times, Bold, false },
154 { "times-italic", Times, Italic, false },
155 { "helvetica-bolditalic", Helvetica, BoldItalic, false },
156 { "helvetica-bold", Helvetica, Bold, false },
157 { "helvetica-italic", Times, Italic, false },
158 { "helvetica", Helvetica, Regular, false },
159 { "courier-bolditalic", Courier, BoldItalic, false },
160 { "courier-bold", Courier, Bold, false },
161 { "courier-italic", Courier, Italic, false },
162 { "courier", Courier, Regular, false },
163 { "symbol", Symbol, Regular, false },
166 { "cmr", Times, Regular, true },
167 { "cmbx", Times, Bold, true },
168 { "cmcsc", Times, Regular, true },
169 { "cmmi", Times, Italic, true },
170 { "cmtt", Courier, Regular, true },
171 { "cmsy", Symbol, Regular, true },
172 { "msbm", Times, Regular, true },
174 { 0, Nb_Family, Regular, false }
177void Font::init( const TQString &n)
180 _data = _dict->find(n);
184 name.replace( "oblique", "italic");
189 while ( KNOWN_DATA[i].name!=0 ) {
190 if ( name.find(KNOWN_DATA[i].name)!=-1 ) {
193 _data->family = FAMILY_DATA[KNOWN_DATA[i].family];
194 _data->style = KNOWN_DATA[i].style;
195 _data->latex = KNOWN_DATA[i].latex;
201 if ( _data->family.isEmpty() ) {
203 kdDebug(30516) << "unknown font : " << n << endl;
204 if ( name.find( "times")!=-1 )
205 _data->family = FAMILY_DATA[Times];
206 else if ( name.find( "helvetica")!=-1 )
207 _data->family = FAMILY_DATA[Helvetica];
208 else if ( name.find( "courier")!=-1 )
209 _data->family = FAMILY_DATA[Courier];
210 else if ( name.find( "symbol")!=-1 )
211 _data->family = FAMILY_DATA[Symbol];
214 TQStringList list = fdb.families();
215 list = list.grep(name, false);
216 if ( !list.isEmpty() ) {
217 _data->family = list[0];
218 kdDebug(30516) << "in TQt database as " << list[0] << endl;
221 kdDebug(30516) << "really unknown font !" << endl;
222 _data->family = name;
226 bool italic = ( name.find( "italic")!=-1 );
227 bool bold = ( name.find( "bold")!=-1 );
228 _data->style = toStyle(bold, italic);
229 _data->latex = false;
232 _dict->insert(name, _data);
236 if ( !_data->height.contains(_pointSize) ) {
237 TQFont font(_data->family, _pointSize,
238 (isBold(_data->style) ? TQFont::Bold : TQFont::Normal),
239 isItalic(_data->style));
240 TQFontMetrics fm(font);
241 _data->height.insert(_pointSize, fm.height());
245bool Font::operator ==( const Font &font) const
247 if ( _pointSize!=font._pointSize ) return false;
248 if ( _data->family!=font._data->family ) return false;
249 if ( _data->style!=font._data->style ) return false;
252 if ( _color!=font._color ) return false;
256bool Font::format(TQDomDocument &doc, TQDomElement &f,
257 uint pos, uint len, bool all) const
259 f.setAttribute( "id", 1);
260 if (!all) f.setAttribute( "pos", pos);
261 if (!all) f.setAttribute( "len", len);
263 TQDomElement element;
266 if ( all || _data->family!=def._data->family ) {
267 element = doc.createElement( "FONT");
268 element.setAttribute( "name", _data->family);
269 f.appendChild(element);
271 if ( all || _pointSize!=def._pointSize ) {
272 element = doc.createElement( "SIZE");
273 element.setAttribute( "value", _pointSize);
274 f.appendChild(element);
276 if ( all || isItalic(_data->style)!=isItalic(def._data->style) ) {
277 element = doc.createElement( "ITALIC");
278 element.setAttribute( "value", (isItalic(_data->style) ? 1 : 0));
279 f.appendChild(element);
281 if ( all || isBold(_data->style)!=isBold(def._data->style) ) {
282 element = doc.createElement( "WEIGHT");
283 element.setAttribute( "value",
284 (isBold(_data->style) ? TQFont::Bold : TQFont::Normal));
285 f.appendChild(element);
299 element = doc.createElement( "VERTALIGN");
300 element.setAttribute( "value", 0);
301 f.appendChild(element);
304 if ( all || _color!=def._color ) {
305 element = doc.createElement( "COLOR");
306 element.setAttribute( "red", _color.red());
307 element.setAttribute( "green", _color.green());
308 element.setAttribute( "blue", _color.blue());
309 f.appendChild(element);
313 element = doc.createElement( "TEXTBACKGROUNDCOLOR");
314 element.setAttribute( "red", 255);
315 element.setAttribute( "green",255);
316 element.setAttribute( "blue", 255);
317 f.appendChild(element);
320 return f.hasChildNodes();
323void Font::setFamily(FontFamily f)
327 while ( KNOWN_DATA[i].name!=0 ) {
328 if ( KNOWN_DATA[i].family==f ) {
329 if ( KNOWN_DATA[i].style==_data->style ) {
339 init(KNOWN_DATA[k].name);
343Link::Link( const DRect &rect, LinkAction &action, Catalog &catalog)
346 switch ( action.getKind() ) {
348 LinkGoTo &lgoto = static_cast<LinkGoTo &>(action);
349 LinkDest *dest = (lgoto.getDest() ? lgoto.getDest()->copy()
350 : catalog.findDest( lgoto.getNamedDest() ));
353 if ( dest->isPageRef() ) {
354 Ref pageref = dest->getPageRef();
355 page = catalog.findPage(pageref.num, pageref.gen);
356 } else page = dest->getPageNum();
360 _href = TQString( "bkm://") + pageLinkName(page);
366 LinkGoToR &lgotor = static_cast<LinkGoToR &>(action);
368 if ( lgotor.getFileName() )
369 _href += lgotor.getFileName()->getCString();
371 if ( lgotor.getDest() ) {
372 LinkDest *dest = lgotor.getDest()->copy();
373 if ( !dest->isPageRef() ) page = dest->getPageNum();
377 kdDebug(30516) << "link to filename \"" << _href << "\" (page "
378 << page << ")" <<endl;
383 LinkLaunch &llaunch = static_cast<LinkLaunch & >(action);
385 if ( llaunch.getFileName() )
386 _href += llaunch.getFileName()->getCString();
388 kdDebug(30516) << "link to launch/open \"" << _href << "\"" << endl;
393 LinkURI &luri = static_cast<LinkURI & >(action);
394 if ( luri.getURI() ) _href = luri.getURI()->getCString();
396 kdDebug(30516) << "link to URI \"" << _href << "\"" << endl;
403 kdDebug(30516) << "unsupported link=" << action.getKind() << endl;
408void Link::format(TQDomDocument &doc, TQDomElement &f, uint pos,
409 const TQString &text) const
411 f.setAttribute( "id", 4);
412 f.setAttribute( "pos", pos);
413 f.setAttribute( "len", 1);
415 TQDomElement v = doc.createElement( "VARIABLE");
416 TQDomElement element = doc.createElement( "TYPE");
417 element.setAttribute( "type", 9);
418 element.setAttribute( "key", "STRING");
419 element.setAttribute( "text", text);
420 v.appendChild(element);
421 element = doc.createElement( "LINK");
422 element.setAttribute( "linkName", text);
423 element.setAttribute( "hrefName", _href);
424 v.appendChild(element);
429TQString Link::pageLinkName(uint i)
431 return TQString( "page") + TQString::number(i);
|