summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CDrawBuffer.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-reader/CDrawBuffer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.cpp277
1 files changed, 224 insertions, 53 deletions
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp
index ca220e6..77b76fb 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.cpp
+++ b/noncore/apps/opie-reader/CDrawBuffer.cpp
@@ -5,2 +5,4 @@
#include <qpixmap.h>
+#include <qimage.h>
+#include "useqpe.h"
#include "opie.h"
@@ -44,3 +46,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
int i;
-// qDebug("Trying 2");
+// //qDebug("Trying 2");
len = rhs.len;
@@ -62,3 +64,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
len = i;
-// qDebug("Tried 2");
+// //qDebug("Tried 2");
return *this;
@@ -82,2 +84,4 @@ void CDrawBuffer::empty()
{
+ m_bSop = false;
+ m_bEop = false;
len = 0;
@@ -113,7 +117,45 @@ void CDrawBuffer::truncate(int n)
-int CDrawBuffer::width(int numchars)
+int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _border)
{
+ int gzoom = fc->gzoom();
int currentx = 0, end = 0;
- QString text = toQString(data());
+ QString text = (numchars < 0) ? toQString(data()) : toQString(data(), numchars);
CList<textsegment>::iterator textstart = segs.begin();
+ int extraspace = 0;
+ bool just = (onscreen && !m_bEop && textstart->style.getJustify() == m_AlignJustify);
+ int spaces = 0;
+ int spacesofar = 0;
+ int spacenumber = 0;
+ int nonspace = 0;
+ if (just)
+ {
+ for (int i = 0; i < len; i++)
+ {
+ if ((*this)[i] != ' ')
+ {
+ nonspace = i;
+ break;
+ }
+ }
+#ifdef _WINDOWS
+ for (i = nonspace; i < len; i++)
+#else
+ for (int i = nonspace; i < len; i++)
+#endif
+ {
+ if ((*this)[i] == ' ')
+ {
+ spaces++;
+ }
+ }
+ if (spaces == 0)
+ {
+ just = false;
+ }
+ else
+ {
+ extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width());
+ if (extraspace == 0) just = false;
+ }
+ }
CList<textsegment>::iterator textend = textstart;
@@ -122,3 +164,3 @@ int CDrawBuffer::width(int numchars)
textend++;
- end = (textend != segs.end()) ? textend->start : length();
+ end = (textend != segs.end()) ? textend->start : len;
if (numchars >= 0 && end > numchars)
@@ -130,4 +172,11 @@ int CDrawBuffer::width(int numchars)
{
+ if (currentstyle.canScale())
+ {
+ currentx += (gzoom*currentstyle.getPicture()->width())/100;
+ }
+ else
+ {
currentx += currentstyle.getPicture()->width();
}
+ }
else
@@ -141,3 +190,3 @@ int CDrawBuffer::width(int numchars)
{
- QFont f(currentstyle.isMono() ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
+ QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
// f.setUnderline(currentstyle.isUnderline());
@@ -145,2 +194,34 @@ int CDrawBuffer::width(int numchars)
QFontMetrics fm(f);
+ if (just)
+ {
+ int lastspace = -1;
+ int nsp = 0;
+ int cx = currentx;
+ while ((nsp = str.find(" ", lastspace+1)) >= 0)
+ {
+ if (nsp > nonspace)
+ {
+ spacenumber++;
+ int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
+ QString nstr = str.mid(lastspace+1, nsp-lastspace);
+ int lw = fm.width(nstr);
+ cx += lw+nexttoadd;
+ spacesofar += nexttoadd;
+ lastspace = nsp;
+ }
+ else
+ {
+ QString nstr = str.mid(lastspace+1, nsp-lastspace);
+// qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr);
+ int lw = fm.width(nstr);
+ cx += lw;
+ lastspace = nsp;
+ }
+ }
+ QString nstr = str.right(str.length()-1-lastspace);
+ cx += fm.width(nstr);
+ currentx = cx;
+ }
+ else
+ {
currentx += fm.width(str);
@@ -148,5 +229,6 @@ int CDrawBuffer::width(int numchars)
}
+ }
textstart = textend;
}
- while (textend != segs.end() && end != numchars);
+ while (textend != segs.end() && end != numchars && textstart->start < len);
return currentx;
@@ -156,3 +238,3 @@ int CDrawBuffer::leftMargin()
{
- return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style))/6;
+ return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style)+3)/6;
}
@@ -161,8 +243,8 @@ int CDrawBuffer::rightMargin()
{
- return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style))/6;
+ return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style)+3)/6;
}
-int CDrawBuffer::offset(int scwidth)
+int CDrawBuffer::offset(int scwidth, unsigned char _border)
{
- int currentx = BORDER;
+ int currentx = _border;
switch(segs.begin()->style.getJustify())
@@ -171,3 +253,3 @@ int CDrawBuffer::offset(int scwidth)
{
- currentx = scwidth - BORDER - rightMargin() - width();
+ currentx = scwidth - _border - rightMargin() - width();
}
@@ -184,3 +266,3 @@ int CDrawBuffer::offset(int scwidth)
case m_AlignLeft:
- currentx = BORDER + leftMargin();
+ currentx = _border + leftMargin();
break;
@@ -190,26 +272,45 @@ int CDrawBuffer::offset(int scwidth)
-void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth)
+void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned char _border)
{
- int currentx = offset(scwidth);
+ int gzoom = fc->gzoom();
+ int currentx = offset(scwidth, _border);
QString text = toQString(data());
CList<textsegment>::iterator textstart = segs.begin();
-/*
- StyleType align = textstart->style.getJustify();
- switch (align)
+ int extraspace = 0;
+ bool just = (!m_bEop && textstart->style.getJustify() == m_AlignJustify);
+ int spaces = 0;
+ int spacesofar = 0;
+ int spacenumber = 0;
+ int nonspace = 0;
+ if (just)
{
- case CStyle::m_AlignRight:
+ for (int i = 0; i < len; i++)
{
- currentx = scwidth - width() - 2*BORDER;
- }
+ if ((*this)[i] != ' ')
+ {
+ nonspace = i;
break;
- case CStyle::m_AlignCentre:
+ }
+ }
+#ifdef _WINDOWS
+ for (i = nonspace; i < len; i++)
+#else
+ for (int i = nonspace; i < len; i++)
+#endif
+ {
+ if ((*this)[i] == ' ')
{
- currentx = (scwidth - width())/2 - BORDER;
+ spaces++;
+ }
+ }
+ if (spaces == 0)
+ {
+ just = false;
+ }
+ else
+ {
+ extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width());
+ if (extraspace == 0) just = false;
}
- break;
- case CStyle::m_AlignJustify:
- case CStyle::m_AlignLeft:
- break;
}
-*/
CList<textsegment>::iterator textend = textstart;
@@ -218,5 +319,5 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
textend++;
- int end = (textend != segs.end()) ? textend->start : length();
+ int end = (textend != segs.end()) ? textend->start : len;
CStyle currentstyle = textstart->style;
- QFont f((currentstyle.isMono() && fc->hasCourier()) ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
+ QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
// f.setUnderline(currentstyle.isUnderline());
@@ -225,3 +326,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
QString str = text.mid(textstart->start, end-textstart->start);
-#ifdef OPIE
+#if defined(OPIE) || !defined(USEQPE)
_p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100));
@@ -230,2 +331,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
#endif
+ int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2;
if (_bMono)
@@ -234,3 +336,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
{
- _p->drawLine( currentx, _y, currentx + str.length()*_charWidth, _y);
+ _p->drawLine( currentx, _y+voffset, currentx + str.length()*_charWidth, _y+voffset);
}
@@ -239,3 +341,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
int ascent = fc->ascent(currentstyle)/3;
- _p->drawLine( currentx, _y-ascent, currentx + str.length()*_charWidth, _y-ascent);
+ _p->drawLine( currentx, _y-ascent+voffset, currentx + str.length()*_charWidth, _y-ascent+voffset);
}
@@ -243,3 +345,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
{
- _p->drawText( currentx + i*_charWidth, _y, QString(str[i]));
+ _p->drawText( currentx + i*_charWidth, _y+voffset, QString(str[i]));
}
@@ -251,6 +353,19 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
{
+ int ht = (gzoom*currentstyle.getPicture()->height())/100;
+ int wt = (gzoom*currentstyle.getPicture()->width())/100;
int ascent = fc->ascent(currentstyle)/2;
- int yoffset = currentstyle.getPicture()->height()/2 + ascent;
- _p->drawPixmap( currentx, _y-yoffset, *(currentstyle.getPicture()));
- currentx += currentstyle.getPicture()->width();
+ int yoffset = ht/2 + ascent;
+
+ QPixmap pc;
+ if (gzoom != 100 && currentstyle.canScale())
+ {
+ QImage im = currentstyle.getPicture()->smoothScale(wt,ht);
+ pc.convertFromImage(im);
+ }
+ else
+ {
+ pc.convertFromImage(*currentstyle.getPicture());
+ }
+ _p->drawPixmap( currentx, _y-yoffset, pc );
+ currentx += wt;
}
@@ -264,3 +379,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
{
- _p->drawLine( currentx, _y, currentx + w, _y);
+ _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset);
}
@@ -269,3 +384,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
int ascent = fc->ascent(currentstyle)/3;
- _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
+ _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset);
}
@@ -273,5 +388,9 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
- for (int i = 0; i < str.length(); i++)
+ for (unsigned int i = 0; i < str.length(); i++)
{
- _p->drawText( currentx, _y, QString(str[i]));
+#ifdef _WINDOWS
+ _p->drawText( currentx, _y+voffset, QString(str.at(i)));
+#else
+ _p->drawText( currentx, _y+voffset, QString(str[i]));
+#endif
currentx += cw;
@@ -282,6 +401,45 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
QFontMetrics fm(f);
- int w = fm.width(str);
+ int w;
+ if (just)
+ {
+ int lastspace = -1;
+ int nsp = 0;
+ int cx = currentx;
+ while ((nsp = str.find(" ", lastspace+1)) >= 0)
+ {
+ if (nsp+textstart->start >= nonspace)
+ {
+ spacenumber++;
+ int nexttoadd = (extraspace*spacenumber+spaces/2)/spaces - spacesofar;
+ QString nstr = str.mid(lastspace+1, nsp-lastspace);
+// qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr);
+ int lw = fm.width(nstr);
+ _p->drawText( cx, _y+voffset, nstr);
+ cx += lw+nexttoadd;
+ spacesofar += nexttoadd;
+ lastspace = nsp;
+ }
+ else
+ {
+ QString nstr = str.mid(lastspace+1, nsp-lastspace);
+// qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr);
+ int lw = fm.width(nstr);
+ _p->drawText( cx, _y+voffset, nstr);
+ cx += lw;
+ lastspace = nsp;
+ }
+ }
+ QString nstr = str.right(str.length()-1-lastspace);
+ _p->drawText( cx, _y+voffset, nstr);
+ cx += fm.width(nstr);
+ w = cx - currentx;
+ }
+ else
+ {
+ _p->drawText( currentx, _y+voffset, str);
+ w = fm.width(str);
+ }
if (currentstyle.isUnderline())
{
- _p->drawLine( currentx, _y, currentx + w, _y);
+ _p->drawLine( currentx, _y+voffset, currentx + w, _y+voffset);
}
@@ -290,5 +448,4 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
int ascent = fc->ascent(currentstyle)/3;
- _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
+ _p->drawLine( currentx, _y-ascent+voffset, currentx + w, _y-ascent+voffset);
}
- _p->drawText( currentx, _y, str);
currentx += w;
@@ -299,3 +456,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
}
- while (textend != segs.end() && textstart->start < length()-1);
+ while (textend != segs.end() && textstart->start < len);
}
@@ -316,3 +473,3 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt)
textend++;
- end = (textend != segs.end()) ? textend->start : length();
+ end = (textend != segs.end()) ? textend->start : len;
currentstyle = textstart->style;
@@ -321,3 +478,3 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt)
if (currentstyle.getLink()) qDebug("Passed thru link");
- qDebug("islink:%d - %d", numchars, end);
+ //qDebug("islink:%d - %d", numchars, end);
*/
@@ -342,5 +499,5 @@ void CDrawBuffer::resize()
{
- int i;
+ int gzoom = fc->gzoom();
m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
- for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= length(); )
+ for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; )
{
@@ -359,6 +516,6 @@ void CDrawBuffer::resize()
extra = linespacing - ascent - descent;
- if (_style.isPicture())
+ if (_style.isPicture() && _style.canScale())
{
- descent = (_style.getPicture()->height()-ascent)/2;
- ascent = (_style.getPicture()->height()+ascent)/2;
+ descent = ((gzoom*_style.getPicture()->height())/100-ascent)/2;
+ ascent = ((gzoom*_style.getPicture()->height())/100+ascent)/2;
}
@@ -378,2 +535,16 @@ void CDrawBuffer::resize()
}
+ int lead = fc->getlead();
+ if (lead != 0)
+ {
+ int xt = (lead*m_lineSpacing+5)/10;
+ m_descent += xt;
+ m_lineSpacing += xt;
+ }
+ if (m_bSop)
+ {
+ int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10;
+// qDebug("ExtraSpace:%d", xt);
+ m_ascent += xt;
+ m_lineSpacing += xt;
+ }
}