00001 #include "CDrawBuffer.h"
00002 #include "FontControl.h"
00003 #include <qfontmetrics.h>
00004 #include <qpainter.h>
00005 #include <qpixmap.h>
00006 #include <qimage.h>
00007
00008 CDrawBuffer::~CDrawBuffer()
00009 {
00010 while (!segs.isEmpty()) segs.erase(0);
00011 }
00012
00013 void CDrawBuffer::setright(CDrawBuffer& rhs, int f)
00014 {
00015 int i;
00016 len = rhs.len;
00017 fc = rhs.fc;
00018 m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
00019 while (!segs.isEmpty())
00020 {
00021 segs.erase(0);
00022 }
00023 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); )
00024 {
00025 CList<textsegment>::iterator next = iter;
00026 iter++;
00027 if (iter == rhs.segs.end() || iter->start > f)
00028 {
00029 int st = next->start-f;
00030 if (st < 0) st = 0;
00031
00032 CStyle _style = next->style;
00033 segs.push_back(textsegment(st,next->style));
00034 }
00035 }
00036 for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i];
00037 (*this)[i-f] = '\0';
00038 len = i;
00039 }
00040
00041 CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
00042 {
00043 int i;
00044
00045 len = rhs.len;
00046 m_ascent = rhs.m_ascent;
00047 m_descent = rhs.m_descent;
00048 m_lineSpacing = rhs.m_lineSpacing;
00049 m_lineExtraSpacing = rhs.m_lineExtraSpacing;
00050 m_showPartial = rhs.m_showPartial;
00051 while (!segs.isEmpty())
00052 {
00053 segs.erase(0);
00054 }
00055 for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++)
00056 {
00057 segs.push_back(*iter);
00058 }
00059 for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i];
00060 (*this)[i] = '\0';
00061 len = i;
00062
00063 return *this;
00064 }
00065
00066 CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp)
00067 {
00068 int i;
00069 while (!segs.isEmpty())
00070 {
00071 segs.erase(0);
00072 }
00073 segs.push_back(textsegment(0, CStyle()));
00074 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i];
00075 (*this)[i] = '\0';
00076 len = i;
00077 return *this;
00078 }
00079
00080 void CDrawBuffer::empty()
00081 {
00082 m_bSop = false;
00083 m_bEop = false;
00084 m_bBop = false;
00085 len = 0;
00086 (*this)[0] = 0;
00087 while (!segs.isEmpty())
00088 {
00089 segs.erase(0);
00090 }
00091 segs.push_back(textsegment(0,CStyle()));
00092 m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
00093 m_bEof = false;
00094 }
00095
00096 void CDrawBuffer::setendpara(const CStyle& _style)
00097 {
00098 m_bEop = true;
00099 if (len == 0)
00100 {
00101 segs.first().start = 0;
00102 segs.first().style = _style;
00103 }
00104 }
00105
00106 void CDrawBuffer::addch(tchar ch, CStyle _style)
00107 {
00108 if (len == 0)
00109 {
00110 segs.first().start = 0;
00111 segs.first().style = _style;
00112 }
00113 else if (_style != segs.last().style)
00114 {
00115 segs.push_back(textsegment(len, _style));
00116 }
00117 (*this)[len++] = ch;
00118 }
00119
00120 void CDrawBuffer::truncate(int n)
00121 {
00122 len = n;
00123 (*this)[n] = 0;
00124 }
00125
00126 int CDrawBuffer::width(int availht, int numchars, bool onscreen, int scwidth, unsigned short _lborder, unsigned short _rborder)
00127 {
00128 int gzoom = fc->gzoom();
00129 int currentx = 0, end = 0;
00130 QString text = (numchars < 0) ? toQString(data()) : toQString(data(), numchars);
00131 CList<textsegment>::iterator textstart = segs.begin();
00132 int extraspace = 0;
00133 bool just = (onscreen && !m_bEop && textstart->style.getJustify() == m_AlignJustify);
00134 int spaces = 0;
00135 int spacesofar = 0;
00136 int spacenumber = 0;
00137 int nonspace = 0;
00138 if (just)
00139 {
00140 for (int i = 0; i < len; i++)
00141 {
00142 if ((*this)[i] != ' ')
00143 {
00144 nonspace = i;
00145 break;
00146 }
00147 }
00148 #ifdef _WINDOWS
00149 for (i = nonspace; i < len; i++)
00150 #else
00151 for (int i = nonspace; i < len; i++)
00152 #endif
00153 {
00154 if ((*this)[i] == ' ')
00155 {
00156 spaces++;
00157 }
00158 }
00159 if (spaces == 0)
00160 {
00161 just = false;
00162 }
00163 else
00164 {
00165 extraspace = (scwidth - (_lborder+_rborder) - rightMargin() - leftMargin() - width(availht));
00166 if (extraspace == 0) just = false;
00167 }
00168 }
00169 CList<textsegment>::iterator textend = textstart;
00170 do
00171 {
00172 textend++;
00173 end = (textend != segs.end()) ? textend->start : len;
00174 if (numchars >= 0 && end > numchars)
00175 {
00176 end = numchars;
00177 }
00178 CStyle currentstyle = textstart->style;
00179 if (currentstyle.isPicture())
00180 {
00181 if (currentstyle.canScale())
00182 {
00183 int ht = (gzoom*currentstyle.getPicture()->height())/100;
00184 int wt = (gzoom*currentstyle.getPicture()->width())/100;
00185 if (ht > availht)
00186 {
00187 wt = (wt*availht)/ht;
00188 }
00189 currentx += wt;
00190 }
00191 else
00192 {
00193 currentx += currentstyle.getPicture()->width();
00194 }
00195 }
00196 else
00197 {
00198 if (currentstyle.isMono() && !fc->hasCourier())
00199 {
00200 int cw = (7*fc->getsize(currentstyle))/10;
00201 currentx += cw*(end-textstart->start);
00202 }
00203 else
00204 {
00205 QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
00206
00207 QString str = text.mid(textstart->start, end-textstart->start);
00208 QFontMetrics fm(f);
00209 if (just)
00210 {
00211 int lastspace = -1;
00212 int nsp = 0;
00213 int cx = currentx;
00214 while ((nsp = str.find(" ", lastspace+1)) >= 0)
00215 {
00216 if (nsp > nonspace)
00217 {
00218 spacenumber++;
00219 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
00220 QString nstr = str.mid(lastspace+1, nsp-lastspace);
00221 int lw = fm.width(nstr);
00222 cx += lw+nexttoadd;
00223 spacesofar += nexttoadd;
00224 lastspace = nsp;
00225 }
00226 else
00227 {
00228 QString nstr = str.mid(lastspace+1, nsp-lastspace);
00229
00230 int lw = fm.width(nstr);
00231 cx += lw;
00232 lastspace = nsp;
00233 }
00234 }
00235 QString nstr = str.right(str.length()-1-lastspace);
00236 cx += fm.width(nstr);
00237 currentx = cx;
00238 }
00239 else
00240 {
00241 currentx += fm.width(str);
00242 }
00243 }
00244 }
00245 textstart = textend;
00246 }
00247 while (textend != segs.end() && end != numchars && textstart->start < len);
00248 return currentx;
00249 }
00250
00251 int CDrawBuffer::charwidth(int numchars, CStyle& currentstyle)
00252 {
00253 if (currentstyle.isPicture())
00254 {
00255 int gzoom = fc->gzoom();
00256 if (currentstyle.canScale())
00257 {
00258 return (gzoom*currentstyle.getPicture()->width())/100;
00259 }
00260 else
00261 {
00262 return currentstyle.getPicture()->width();
00263 }
00264 }
00265 else
00266 {
00267 if (currentstyle.isMono() && !fc->hasCourier())
00268 {
00269 return (7*fc->getsize(currentstyle))/10;
00270 }
00271 else
00272 {
00273 QString text = QChar((data())[numchars]);
00274 QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
00275
00276 QFontMetrics fm(f);
00277 return fm.width(text);
00278 }
00279 }
00280 return 0;
00281 }
00282
00283 int CDrawBuffer::charwidth(int numchars)
00284 {
00285 int gzoom = fc->gzoom();
00286 int end = 0;
00287 QString text = QChar((data())[numchars]);
00288 CList<textsegment>::iterator textstart = segs.begin();
00289 CList<textsegment>::iterator textend = textstart;
00290 do
00291 {
00292 textend++;
00293 end = (textend != segs.end()) ? textend->start : len;
00294 if (end <= numchars)
00295 {
00296 textstart = textend;
00297 continue;
00298 }
00299 if (numchars >= 0 && end > numchars)
00300 {
00301 end = numchars;
00302 }
00303 CStyle currentstyle = textstart->style;
00304 if (currentstyle.isPicture())
00305 {
00306 if (currentstyle.canScale())
00307 {
00308 return (gzoom*currentstyle.getPicture()->width())/100;
00309 }
00310 else
00311 {
00312 return currentstyle.getPicture()->width();
00313 }
00314 }
00315 else
00316 {
00317 if (currentstyle.isMono() && !fc->hasCourier())
00318 {
00319 return (7*fc->getsize(currentstyle))/10;
00320 }
00321 else
00322 {
00323 QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
00324
00325 QFontMetrics fm(f);
00326 return fm.width(text);
00327 }
00328 }
00329 textstart = textend;
00330 }
00331 while (textend != segs.end() && textstart->start < len);
00332 return 0;
00333 }
00334
00335
00336
00337 int CDrawBuffer::leftMargin()
00338 {
00339 return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6;
00340 }
00341
00342 int CDrawBuffer::rightMargin()
00343 {
00344 return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6;
00345 }
00346
00347 int CDrawBuffer::offset(int scwidth, unsigned short _lborder, unsigned short _rborder, int availht)
00348 {
00349 int currentx = _lborder;
00350 switch(segs.begin()->style.getJustify())
00351 {
00352 case m_AlignRight:
00353 {
00354 currentx = scwidth - _rborder - rightMargin() - width(availht);
00355 }
00356 break;
00357 case m_AlignCentre:
00358 {
00359 currentx = (
00360 scwidth - _lborder -_rborder +
00361 leftMargin() - rightMargin()
00362 - width(availht))/2 + _lborder;
00363 }
00364 break;
00365 case m_AlignJustify:
00366 case m_AlignLeft:
00367 case m_AlignNone:
00368 currentx = _lborder + leftMargin();
00369 break;
00370 }
00371 return currentx;
00372 }
00373
00374 void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned short _lborder, unsigned short _rborder, const QColor& _bg, int availht)
00375 {
00376 CList<textsegment>::iterator textstart = segs.begin();
00377 QColor paperColour = QColor(qRgb(textstart->style.pRed(),
00378 textstart->style.pGreen(),
00379 textstart->style.pBlue()));
00380
00381 Highlight(_p, !(paperColour == _bg), _lborder, _y, scwidth-(_lborder+_rborder), paperColour);
00382
00383 int gzoom = fc->gzoom();
00384 int currentx = offset(scwidth, _lborder, _rborder, availht);
00385 if (!m_hastext)
00386 {
00387 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++)
00388 {
00389 CStyle currentstyle = iter->style;
00390 if (currentstyle.isPicture())
00391 {
00392 CStyle currentstyle = segs.begin()->style;
00393 int ht = (gzoom*currentstyle.getPicture()->height())/100;
00394 int wt = (gzoom*currentstyle.getPicture()->width())/100;
00395 bool willscale = false;
00396 if (ht > availht)
00397 {
00398 wt = (wt*availht)/ht;
00399 ht = availht;
00400 willscale = true;
00401 }
00402
00403 QPixmap pc;
00404 if ((willscale || gzoom != 100) && currentstyle.canScale())
00405 {
00406 QImage im = currentstyle.getPicture()->smoothScale(wt,ht);
00407 pc.convertFromImage(im);
00408 }
00409 else
00410 {
00411 pc.convertFromImage(*currentstyle.getPicture());
00412 }
00413 int yoffset = pc.height()/2;
00414 _p->drawPixmap( currentx, _y-yoffset, pc );
00415 currentx += pc.width();
00416 }
00417 }
00418 return;
00419 }
00420 QString text = toQString(data());
00421 int extraspace = 0;
00422 bool just = (!m_bEop && textstart->style.getJustify() == m_AlignJustify);
00423 int spaces = 0;
00424 int spacesofar = 0;
00425 int spacenumber = 0;
00426 int nonspace = 0;
00427 if (just)
00428 {
00429 for (int i = 0; i < len; i++)
00430 {
00431 if ((*this)[i] != ' ')
00432 {
00433 nonspace = i;
00434 break;
00435 }
00436 }
00437 #ifdef _WINDOWS
00438 for (i = nonspace; i < len; i++)
00439 #else
00440 for (int i = nonspace; i < len; i++)
00441 #endif
00442 {
00443 if ((*this)[i] == ' ')
00444 {
00445 spaces++;
00446 }
00447 }
00448 if (spaces == 0)
00449 {
00450 just = false;
00451 }
00452 else
00453 {
00454 extraspace = (scwidth - (_lborder+_rborder) - rightMargin() - leftMargin() - width(availht));
00455 if (extraspace == 0) just = false;
00456 }
00457 }
00458 CList<textsegment>::iterator textend = textstart;
00459
00460 bool drawBackground = false;
00461 do
00462 {
00463 textend++;
00464 int end = (textend != segs.end()) ? textend->start : len;
00465 CStyle currentstyle = textstart->style;
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 QColor bgColour = QColor(qRgb(currentstyle.bRed(),
00476 currentstyle.bGreen(),
00477 currentstyle.bBlue()));
00478 drawBackground = !(bgColour == _bg);
00479
00480
00481
00482 QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
00483
00484
00485 _p->setFont(f);
00486 QString str = text.mid(textstart->start, end-textstart->start);
00487 #if defined(OPIE) || !defined(USEQPE)
00488 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
00489 #else
00490 _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
00491 #endif
00492 int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2;
00493
00494 if (_bMono)
00495 {
00496
00497 Highlight(_p, drawBackground, currentx, _y, str.length()*_charWidth, bgColour);
00498 if (currentstyle.isUnderline())
00499 {
00500 _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset);
00501 }
00502 if (currentstyle.isStrikethru())
00503 {
00504 int ascent = fc->ascent(currentstyle)/3;
00505 _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset);
00506 }
00507 for (int i = 0; i < str.length(); i++)
00508 {
00509 _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i]));
00510 }
00511 currentx += str.length()*_charWidth;
00512 }
00513 else
00514 {
00515 if (currentstyle.isPicture())
00516 {
00517 int ht = (gzoom*currentstyle.getPicture()->height())/100;
00518 int wt = (gzoom*currentstyle.getPicture()->width())/100;
00519 bool willscale = false;
00520 if (ht > availht)
00521 {
00522 wt = (wt*availht)/ht;
00523 ht = availht;
00524 willscale = true;
00525 }
00526 int ascent = fc->ascent(currentstyle)/2;
00527 int yoffset = ht/2 + ascent;
00528
00529 QPixmap pc;
00530 if ((willscale || gzoom != 100) && currentstyle.canScale())
00531 {
00532 QImage im = currentstyle.getPicture()->smoothScale(wt,ht);
00533 pc.convertFromImage(im);
00534 }
00535 else
00536 {
00537 pc.convertFromImage(*currentstyle.getPicture());
00538 }
00539 _p->drawPixmap( currentx, _y-yoffset, pc );
00540 currentx += wt;
00541 }
00542 else
00543 {
00544 if (currentstyle.isMono() && !fc->hasCourier())
00545 {
00546 int cw = (7*fc->getsize(currentstyle))/10;
00547 int w = cw*(end-textstart->start);
00548 Highlight(_p, drawBackground, currentx, _y, w, bgColour);
00549 if (currentstyle.isUnderline())
00550 {
00551 _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset);
00552 }
00553 if (currentstyle.isStrikethru())
00554 {
00555 int ascent = fc->ascent(currentstyle)/3;
00556 _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset);
00557 }
00558 QString str = text.mid(textstart->start, end-textstart->start);
00559
00560 for (unsigned int i = 0; i < str.length(); i++)
00561 {
00562 #ifdef _WINDOWS
00563 _p->drawText( currentx, _y+voffset, QString(str.at(i)));
00564 #else
00565 _p->drawText( currentx, _y+voffset, QString(str[i]));
00566 #endif
00567 currentx += cw;
00568 }
00569 }
00570 else
00571 {
00572 QFontMetrics fm(f);
00573 int w;
00574 if (just)
00575 {
00576 int lastspace = -1;
00577 int nsp = 0;
00578 int cx = currentx;
00579 while ((nsp = str.find(" ", lastspace+1)) >= 0)
00580 {
00581 if (nsp+textstart->start >= nonspace)
00582 {
00583 spacenumber++;
00584 int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
00585 QString nstr = str.mid(lastspace+1, nsp-lastspace);
00586
00587 int lw = fm.width(nstr);
00588 Highlight(_p, drawBackground, cx, _y, lw, bgColour);
00589 _p->drawText( cx, _y+voffset, nstr);
00590 Highlight(_p, drawBackground, cx+lw, _y, nexttoadd, bgColour);
00591 cx += lw+nexttoadd;
00592 spacesofar += nexttoadd;
00593 lastspace = nsp;
00594 }
00595 else
00596 {
00597 QString nstr = str.mid(lastspace+1, nsp-lastspace);
00598
00599 int lw = fm.width(nstr);
00600 Highlight(_p, drawBackground, cx, _y, lw, bgColour);
00601 _p->drawText( cx, _y+voffset, nstr);
00602 cx += lw;
00603 lastspace = nsp;
00604 }
00605 }
00606 QString nstr = str.right(str.length()-1-lastspace);
00607 int lw = fm.width(nstr);
00608 Highlight(_p, drawBackground, cx, _y, lw, bgColour);
00609 _p->drawText( cx, _y+voffset, nstr);
00610 cx += lw;
00611 w = cx - currentx;
00612 }
00613 else
00614 {
00615 int lw = fm.width(str);
00616 Highlight(_p, drawBackground, currentx, _y, lw, bgColour);
00617 _p->drawText( currentx, _y+voffset, str);
00618 w = lw;
00619 }
00620 if (currentstyle.isUnderline())
00621 {
00622 _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset);
00623 }
00624 if (currentstyle.isStrikethru())
00625 {
00626 int ascent = fc->ascent(currentstyle)/3;
00627 _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset);
00628 }
00629 currentx += w;
00630 }
00631 }
00632 }
00633 textstart = textend;
00634 }
00635 while (textend != segs.end() && textstart->start < len);
00636
00637
00638
00639
00640
00641
00642 }
00643
00644 void CDrawBuffer::Highlight(QPainter* _p, bool drawBackground, int _x, int _y, int w, QColor bgColour)
00645 {
00646 if (drawBackground)
00647 {
00648 _p->fillRect(_x, _y-m_ascent, w, m_lineSpacing, bgColour);
00649 }
00650 }
00651
00652 CStyle CDrawBuffer::laststyle()
00653 {
00654 return segs.last().style;
00655 }
00656
00657 CStyle CDrawBuffer::firststyle()
00658 {
00659 return segs.first().style;
00660 }
00661
00662 linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt, size_t& offset, size_t& pictgt, QImage*& img, size_t& tabletgt)
00663 {
00664 linkType ret = eNone;
00665 int end = 0;
00666 CStyle currentstyle;
00667 CList<textsegment>::iterator textstart = segs.begin();
00668 CList<textsegment>::iterator textend = textstart;
00669 do
00670 {
00671 textend++;
00672 end = (textend != segs.end()) ? textend->start : len;
00673 currentstyle = textstart->style;
00674
00675
00676
00677
00678
00679 textstart = textend;
00680 }
00681 while (textend != segs.end() && end <= numchars);
00682 img = currentstyle.getPicture();
00683 if (currentstyle.getPictureLink())
00684 {
00685 pictgt = currentstyle.getPictureLinkData();
00686 ret |= ePicture;
00687 }
00688 if (currentstyle.getLink())
00689 {
00690 tgt = currentstyle.getData();
00691 offset = currentstyle.getOffset();
00692 ret |= eLink;
00693 }
00694 if (currentstyle.isTable())
00695 {
00696 tabletgt = currentstyle.getTable();
00697 ret |= eTable;
00698 }
00699 return ret;
00700 }
00701
00702 void CDrawBuffer::resize(int availht)
00703 {
00704 int gzoom = fc->gzoom();
00705 m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
00706
00707
00708
00709
00710
00711 int t_lineSpacing = 0;
00712 m_hastext = false;
00713 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
00714 {
00715 CStyle _style = iter->style;
00716 if (!_style.isPicture())
00717 {
00718 m_hastext = true;
00719 break;
00720 }
00721 iter++;
00722 }
00723 if (m_hastext)
00724 {
00725 int p_linespacing = 0;
00726 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
00727 {
00728 CList<textsegment>::iterator next = iter;
00729 iter++;
00730 int st = next->start;
00731 if (st < 0) st = 0;
00732
00733 CStyle _style = next->style;
00734
00735 int linespacing, ascent, descent, extra;
00736
00737 ascent = fc->ascent(_style);
00738 descent = fc->descent(_style);
00739 linespacing = fc->lineSpacing(_style);
00740 extra = linespacing - ascent - descent;
00741
00742
00743
00744
00745
00746
00747 if (linespacing > t_lineSpacing) t_lineSpacing = linespacing;
00748 if (_style.isPicture())
00749 {
00750 int ht = (gzoom*_style.getPicture()->height())/100;
00751 int wt = (gzoom*_style.getPicture()->width())/100;
00752
00753 bool willscale = false;
00754 if (ht > availht)
00755 {
00756 wt = (wt*availht)/ht;
00757 ht = availht;
00758 willscale = true;
00759 }
00760 if (willscale || _style.canScale())
00761 {
00762 descent = ((gzoom*_style.getPicture()->height())/100-ascent)/2;
00763 ascent = ((gzoom*_style.getPicture()->height())/100+ascent)/2;
00764 }
00765 else
00766 {
00767 descent = (_style.getPicture()->height()-ascent)/2;
00768 ascent = (_style.getPicture()->height()+ascent)/2;
00769 }
00770 int lineSpacing = ascent+descent;
00771 if (lineSpacing > p_linespacing)
00772 {
00773 p_linespacing = lineSpacing;
00774 }
00775 extra = 0;
00776 }
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 if (ascent > m_ascent) m_ascent = ascent;
00788 if (descent > m_descent) m_descent = descent;
00789 if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra;
00790 m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing;
00791 }
00792 m_showPartial = (p_linespacing > t_lineSpacing);
00793 int lead = fc->getlead();
00794 if (lead != 0)
00795 {
00796 int xt = (lead*t_lineSpacing+5)/10;
00797 m_lineExtraSpacing += xt;
00798 m_lineSpacing += xt;
00799 }
00800 if (m_bSop)
00801 {
00802 int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10;
00803
00804 m_ascent += xt;
00805 m_lineSpacing += xt;
00806 }
00807 }
00808 else
00809 {
00810 m_showPartial = true;
00811 int maxheight = 0;
00812 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++)
00813 {
00814 CStyle _style = iter->style;
00815 if (_style.isPicture())
00816 {
00817 int ht = 0;
00818 if (_style.canScale())
00819 {
00820 ht = ((gzoom*_style.getPicture()->height())/100);
00821 }
00822 else
00823 {
00824 ht = _style.getPicture()->height();
00825 }
00826 if (ht > availht)
00827 {
00828 ht = availht;
00829 }
00830 if (ht > maxheight) maxheight = ht;
00831 }
00832 }
00833 m_ascent = maxheight/2;
00834 m_descent = maxheight-m_ascent;
00835 m_lineExtraSpacing = 0;
00836 m_lineSpacing = m_ascent+m_descent;
00837 }
00838 }
00839
00840 CStyle* CDrawBuffer::getNextLink(int& offset)
00841 {
00842 CStyle* ret = NULL;
00843 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); ++iter)
00844 {
00845 if (offset < iter->start && iter->style.getLink())
00846 {
00847 ret = &(iter->style);
00848 offset = iter->start;
00849 qDebug("Found a link at offset %d!", offset);
00850 break;
00851 }
00852 }
00853 return ret;
00854 }
00855
00856 int CDrawBuffer::invertLink(int offset)
00857 {
00858 for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); ++iter)
00859 {
00860 if (offset <= iter->start && iter->style.getLink())
00861 {
00862 iter->style.invert();
00863 unsigned long currentvalue = iter->style.getData();
00864 qDebug("Link data %u", currentvalue);
00865 CList<textsegment>::iterator next = iter;
00866 ++next;
00867 while (next != segs.end() && (currentvalue == next->style.getData()) && next->style.getLink())
00868 {
00869 next->style.invert();
00870 offset = next->start;
00871 iter++;
00872 next++;
00873 }
00874 return offset;
00875 }
00876 }
00877 qDebug("Failed to invert");
00878 return offset;
00879 }