int TableCell::GetWidth(int zoom) const { int cx = 0; for(int i = 0; i < par.GetCount(); i++) cx = max(cx, par[i].GetWidth(zoom)); cx += DocZoom(zoom, style.leftwidth) + DocZoomLn(zoom, style.rightwidth) + DocZoom(zoom, style.leftspace) + DocZoom(zoom, style.rightspace); return cx; }
void Table::FrameTab(int zoom, Draw& w, bool was, int x, int y, int yp, int cx) const { if(!was) return; DrawFatFrame(w, x + DocZoom(zoom, GetLm()), yp, cx - DocZoom(zoom, GetLm()) - DocZoom(zoom, GetRm()) - (zoom < 1024) * DocZoom(zoom, GetFrameWidth()), y - yp + (zoom >= 1024) * DocZoom(zoom, GetFrameWidth()), GetFrameColor(), DocZoomLn(zoom, GetFrameWidth())); }
void Paragraph::GetValueRects(int zoom, Draw& w, int x, int& y, int cx, Vector<ValueRect>& vr) const { ParaRect pr(w, vr); int bi = style.bullet ? style.bulletindent : 0; pr.lm = DocZoom(zoom, style.lm + bi); pr.liney = y; pr.px = x; cx -= DocZoom(zoom, style.lm + style.rm + bi); Format(pr, max(1, cx), zoom); y = pr.liney; }
void TableCell::GetValueRects(int zoom, Draw& w, int x, int y, int cx, int cy, int pcy, Vector<ValueRect>& vr) const { if(pcy > cy) pcy = cy; int lm = DocZoom(zoom, style.leftwidth) + DocZoom(zoom, style.leftspace); x += lm; cx -= lm + DocZoomLn(zoom, style.rightwidth) + DocZoom(zoom, style.rightspace); int tm = DocZoom(zoom, style.topwidth) + DocZoom(zoom, style.topspace); switch(style.align) { case ALIGN_TOP: y += tm; break; case ALIGN_CENTER: y += (cy - pcy) / 2 + tm; break; case ALIGN_BOTTOM: y += cy - pcy - DocZoomLn(zoom, style.bottomwidth) - DocZoom(zoom, style.bottomspace); break; } for(int i = 0; i < par.GetCount(); i++) { const Paragraph& p = par[i]; y += DocZoom(zoom, p.GetBefore()); p.GetValueRects(zoom, w, x, y, cx, vr); y += DocZoom(zoom, p.GetAfter()); } }
void Document::Paint(int zoom, Draw& w, int x, int y, int cx, int cy, int y0, Cache& cache, Color paper) const { int yp = 0; for(int i = 0; i < item.GetCount() && yp < y0 + cy; i++) { const Item& m = item[i]; int h = GetHeight(zoom, i, cx, cache); int yo = yp + y - y0; if((yp += h) <= y0) continue; if(m.type == PARAGRAPH) { const Paragraph& p = m.data.LastCell().Par(); p.Paint(zoom, w, x, yo + DocZoom(zoom, p.GetBefore()), cx, paper); } else m.data.Paint(zoom, w, x, yo + DocZoom(zoom, m.data.GetBefore()), cx); } }
int Document::Paint(int zoom, Draw& w, int x, int y, int cx, Color paper) const { for(int i = 0; i < item.GetCount(); i++) { const Item& m = item[i]; if(m.type == PARAGRAPH) { const Paragraph& p = m.data.LastCell().Par(); y += DocZoom(zoom, p.GetBefore()); y = p.Paint(zoom, w, x, y, cx, paper); y += DocZoom(zoom, p.GetAfter()); } else { y += DocZoom(zoom, m.data.GetBefore()); y = m.data.Paint(zoom, w, x, y, cx); y += DocZoom(zoom, m.data.GetAfter()); } } return y; }
void Paragraph::Paint(int zoom, int angle, Draw& w, int x, int y, int cx) const { ParaAngle pp(w); int bi = style.bullet ? style.bulletindent : 0; double pan = 2 * M_PI * angle / 3600; pp.sinf = sin(pan); pp.cosf = cos(pan); pp.angle = angle; pp.posx = x; pp.posy = y; pp.y = 0; pp.lm = DocZoom(zoom, style.lm + bi); cx -= DocZoom(zoom, style.lm + style.rm + bi); bool r = Format(pp, max(1, cx), zoom); /* if(pp.yp > 0 && style.bullet) style.bullet.Paint(w, x + DocZoom(zoom, style.lm), y, DocZoom(zoom, style.bulletindent), pp.bh, Black, White, 0);*/ }
int Paragraph::GetHeight(int zoom, int cx) const { ParaHeight pp; pp.cy = 0; cx -= DocZoom(zoom, style.lm + style.rm + style.bulletindent); if(cx <= 0) return 0; Format(pp, cx, zoom); LLOG("ParaHeight " << pp.cy); return pp.cy; }
Vector<ValueRect> Document::GetValueRects(int zoom, Draw& w, int x, int y, int cx) const { Vector<ValueRect> vr; for(int i = 0; i < item.GetCount(); i++) { const Item& m = item[i]; if(m.type == PARAGRAPH) { const Paragraph& p = m.data.LastCell().Par(); y += DocZoom(zoom, p.GetBefore()); p.GetValueRects(zoom, w, 0, y, cx, vr); y += DocZoom(zoom, p.GetAfter()); } else { y += DocZoom(zoom, m.data.GetBefore()); m.data.GetValueRects(zoom, w, x, y, cx, vr); y += DocZoom(zoom, m.data.GetAfter()); } } return vr; }
int Document::GetHeight(int zoom, int cx) const { int cy = 0; for(int i = 0; i < item.GetCount(); i++) { const Item& m = item[i]; if(m.type == PARAGRAPH) { const Paragraph& p = m.data.LastCell().Par(); cy += DocZoom(zoom, p.GetBefore()); cy += p.GetHeight(zoom, cx); cy += DocZoom(zoom, p.GetAfter()); } else { cy += DocZoom(zoom, m.data.GetBefore()); cy += m.data.GetHeight(zoom, cx); cy += DocZoom(zoom, m.data.GetAfter()); } } return cy; }
int TableCell::GetHeight(int zoom, int cx) const { cx -= DocZoom(zoom, style.leftwidth) + DocZoomLn(zoom, style.rightwidth) + DocZoom(zoom, style.leftspace) + DocZoom(zoom, style.rightspace); int cy = DocZoom(zoom, style.topwidth) + DocZoomLn(zoom, style.bottomwidth) + DocZoom(zoom, style.topspace) + DocZoom(zoom, style.bottomspace); for(int i = 0; i < par.GetCount(); i++) { const Paragraph& p = par[i]; cy += p.GetHeight(zoom, cx) + DocZoom(zoom, p.GetBefore()) + DocZoom(zoom, p.GetAfter()); } return paintrect ? max(cy, paintrect.RatioSize(cx, 0).cy) : cy; }
inline void Paragraph::ParaPaint::Put(int px, int py, Part *ip, Part **ibeg, Part **i, const char *text) { if(!ip) return; const Paragraph::Part *p = (const Paragraph::Part *) ip->voidptr; if(p->pr) p->pr.Paint(draw, px, py - ip->ascent, ip->width, ip->ascent, ip->color, paper); else draw.DrawText(px, py - ip->ascent + DocZoom(zoom, p->delta), text + (ibeg - info), ip->font, ip->color, i - ibeg); }
int Paragraph::GetWidth(int zoom) const { const Part *pptr = part.Begin(); const Part *plim = part.End(); int cx = DocZoom(zoom, style.indent); while(pptr != plim) { if(pptr->pr) cx += pptr->pr && !pptr->sz.cx ? pptr->pr.GetStdSize().cx : DocZoom(zoom, pptr->sz.cx); else { FontInfo pf = Font(pptr->font).Height(DocZoom(zoom, pptr->font.GetHeight())).Info(); const char *s = pptr->text; int n = pptr->text.GetLength(); while(n--) { cx += pf[*s == 31 ? 32 : ToUnicode((byte) *s, CHARSET_DEFAULT)]; s++; } } pptr++; } return cx + style.lm + style.rm + (style.bullet ? style.bulletindent : 0); }
void Table::GetValueRects(int zoom, Draw& w, int x, int& y, int cx, Vector<ValueRect>& vr) const { int zfw = DocZoomLn(zoom, GetFrameWidth()); int li = 0; cx -= 2 * zfw + DocZoom(zoom, GetLm()) + DocZoom(zoom, GetRm()); y += zfw; while(li < GetRows()) { Vector<Line> line; int span = 0; for(;;) { int k = li + line.GetCount(); if(k >= GetRows() || line.GetCount() && !KeepLine(k) && span <= 0) break; span = max((line.Add() = GetLine(zoom, k, cx, NULL)).span, span); span--; } y += Span(line); RectLines(zoom, w, x, y, li, line, vr); li += line.GetCount(); } y += zfw; }
int Table::GetHeight(int zoom, int cx) const { int cy = 0; int ln = 0; cx -= DocZoomLn(zoom, GetFrameWidth()) + DocZoomLn(zoom, GetFrameWidth()) + DocZoom(zoom, GetLm()) + DocZoom(zoom, GetRm()); cy += 2 * DocZoomLn(zoom, GetFrameWidth()); while(ln < GetRows()) { Vector<Line> line; int span = 0; for(;;) { int k = ln + line.GetCount(); if(ln + line.GetCount() >= GetRows() || line.GetCount() && !KeepLine(k) && span <= 0) break; span = max((line.Add() = GetLine(zoom, k, cx, NULL)).span, span); span--; } cy += Span(line); ln += line.GetCount(); } return cy; }
bool Paragraph::Paint(int zoom, Draw& w, int x, int y, int cx, int ymax, PaintInfo& pi, Color paper) const { ParaPaint pp(w); int bi = style.bullet ? style.bulletindent : 0; pp.zoom = zoom; pp.posx = x; pp.liney = y; pp.ymax = ymax; pp.lm = DocZoom(zoom, style.lm + bi); pp.yl = pi.yl; pp.yp = 0; pp.paper = paper; cx -= DocZoom(zoom, style.lm + style.rm + bi); bool r = Format(pp, max(1, cx), zoom); if(pi.yl == 0 && pp.yp > 0 && style.bullet) style.bullet.Paint(w, x + DocZoom(zoom, style.lm), y, style.bulletsize.cx ? DocZoom(zoom, style.bulletsize.cx) : pp.bh, style.bulletsize.cy ? DocZoom(zoom, style.bulletsize.cy) : pp.bh, style.bulletcolor, paper, 0); pi.ypos = pp.liney; pi.yl = pp.yp; return r; }
void Table::RectLine(int zoom, Draw& w, int x, int y, int i, const Line& ln, Vector<ValueRect>& vr) const { const Array<TableCell>& row = cell[i]; x += DocZoom(zoom, GetLm()) + DocZoomLn(zoom, GetFrameWidth()); for(int j = 0; j < row.GetCount(); j++) { const TableCell& cell = row[j]; const Cell& cl = ln.cell[j]; Size sz = cl.size; if(cl.paint) { int h = cl.span ? cl.spanh : ln.height; cell.GetValueRects(zoom, w, x, y, sz.cx, h, sz.cy, vr); } x += sz.cx; } }
int Document::GetHeight(int zoom, int i, int cx, Document::Cache& cache) const { if(cache.cx == cx && cache.zoom == zoom && i < cache.cy.GetCount() && !IsNull(cache.cy[i])) return cache.cy[i]; int cy; const Item& m = item[i]; if(m.type == PARAGRAPH) { const Paragraph& p = m.data.LastCell().Par(); cy = DocZoom(zoom, p.GetBefore()); cy += p.GetHeight(zoom, cx); cy += DocZoom(zoom, p.GetAfter()); } else { cy = DocZoom(zoom, m.data.GetBefore()); cy += m.data.GetHeight(zoom, cx); cy += DocZoom(zoom, m.data.GetAfter()); } if(cache.cx != cx || cache.zoom != zoom) { cache.Clear(); cache.cx = cx; cache.zoom = zoom; } cache.cy.DoIndex(i, Null) = cy; return cy; }
void Table::DrawLine(int zoom, Draw& w, int x, int y, int i, const Line& ln, int ymax, Vector<int> *yl) const { const Array<TableCell>& row = cell[i]; x += DocZoom(zoom, GetLm()) + DocZoomLn(zoom, GetFrameWidth()); if(yl) yl->SetCount(row.GetCount(), 0); for(int j = 0; j < row.GetCount(); j++) { const TableCell& cell = row[j]; const Cell& cl = ln.cell[j]; Size sz = cl.size; if(cl.paint) { TableCell::PaintInfo pi; int h = cl.span ? cl.spanh : ln.height; if(yl) { pi.yl = (*yl)[j]; if(ymax - y >= 0) h = min(ymax - y, h); } cell.Paint(zoom, w, x, y, sz.cx, h, sz.cy, GetFrameColor(), pi); if(yl) (*yl)[j] = pi.yl; } x += sz.cx; } }
bool Paragraph::Format(ParaTypo& pfmt, int cx, int zoom) const { int len = length + !!style.indent; Buffer<char> chr(len); Buffer<int> width(len); Buffer<ParaTypo::Part *> info(len); Buffer<ParaTypo::Part> pinfo(part.GetCount() + !!style.indent); const Part *pptr = part.Begin(); const Part *plim = part.End(); ParaTypo::Part *pp = pinfo; char *cp = chr; int *wp = width; ParaTypo::Part **ip = info; if(!IsNull(parafont)) { Font pf = parafont; // pf.Height(max(1, DocZoom(zoom, parafont.GetHeight()))); int n = DocZoom(zoom, parafont.GetHeight()); pf.Height(n ? n : 1); FontInfo f = pf.Info(); pfmt.SetMin(f.GetAscent(), f.GetDescent(), f.GetExternal()); } /* if(!IsNull(parafont)) { FontInfo f = w.GetFontInfo(parafont); pfmt.SetMin(DocZoom(zoom, f.GetAscent()), DocZoom(zoom, f.GetDescent()), DocZoom(zoom, f.GetExternal())); } */ if(style.indent) { static Part dummy; *cp++ = ' '; *wp++ = DocZoom(zoom, style.indent); pp->Set(Arial(0), Black); pp->voidptr = &dummy; *ip++ = pp; pp++; } while(pptr != plim) { if(pptr->pr) { *cp++ = '@'; Size sz = pptr->pr.GetStdSize(); *wp++ = pp->width = pptr->pr && !pptr->sz.cx ? sz.cx : DocZoom(zoom, pptr->sz.cx); *ip++ = pp; pp->ascent = minmax(pptr->pr && !pptr->sz.cy ? sz.cy : DocZoom(zoom, pptr->sz.cy), 0, 1000); pp->descent = 0; pp->external = pp->overhang = 0; pp->color = pptr->color; } else { Font font = pptr->font; font.Height(DocZoom(zoom, pptr->font.GetHeight())); FontInfo pf = pp->Set(font, pptr->color); const char *s = pptr->text; int n = pptr->text.GetLength(); while(n--) { *cp++ = *s; *wp++ = pf[*s == 31 ? 32 : ToUnicode((byte) *s, CHARSET_DEFAULT)]; *ip++ = pp; s++; } } pp->voidptr = (void *)pptr; pp++; pptr++; } return pfmt.Format(style.align, len, chr, width, info, cx); }
bool Table::Paint(int zoom, Draw& w, int x, int y, int cx, int ymax, PaintInfo& pi) const { int j; Vector<Line> header; int zfw = DocZoomLn(zoom, GetFrameWidth()); int tcx = cx - 2 * zfw - DocZoom(zoom, GetLm()) - DocZoom(zoom, GetRm()); bool breakpage = pi.line != pi.oline; int pgcy = ymax - y; pi.oline = pi.line; if(pi.line) { int m = min(GetHeaderRows(), cell.GetCount()); for(j = 0; j < m; j++) header.Add() = GetLine(zoom, j, tcx, NULL); } int hdrcy = Span(header); if(hdrcy > ymax - y) { header.Clear(); hdrcy = 0; } int hg = hdrcy; int yp = y; y += zfw; bool was = false; if(y >= ymax) { pi.ypos = y; return true; } while(pi.line < GetRows() && y < ymax) { Vector<Line> line; Vector<int> *yl = &pi.yl; int span = 0; bool nospan = true; for(;;) { int k = pi.line + line.GetCount(); if(k >= GetRows() || line.GetCount() && !KeepLine(k) && span <= 0) break; span = max((line.Add() = GetLine(zoom, k, tcx, yl)).span, span); if(span) nospan = false; yl = NULL; span--; } hg += Span(line); int lhg = line.Top().height; if(hg + y + zfw > ymax) { if((!breakpage || lhg > style.breakcy && ymax - (y + hg - lhg) - zfw > style.breakpgcy) && nospan && line.GetCount() && hg + y + zfw - lhg <= ymax) { int yy = y + hdrcy; PaintLines(zoom, w, x, yy, 0, header, 0); yy = y + hdrcy; int i; for(i = 0; i < line.GetCount() - 1; i++) { DrawLine(zoom, w, x, yy, pi.line++, line[i], ymax, NULL); yy += line[i].height; } DrawLine(zoom, w, x, yy, pi.line, line[i], ymax, &pi.yl); breakpage = was = true; y = ymax; } if(breakpage) { FrameTab(zoom, w, was, x, y, yp, cx); pi.ypos = y; return true; } } y += hg; int yy = y; PaintLines(zoom, w, x, yy, pi.line, line, &pi.yl); PaintLines(zoom, w, x, yy, 0, header, 0); pi.yl.Clear(); header.Clear(); hg = 0; breakpage = was = true; pi.line += line.GetCount(); } FrameTab(zoom, w, was, x, y, yp, cx); pi.ypos = y + zfw; return false; }
bool TableCell::Paint(int zoom, Draw& w, int x, int y, int cx, int cy, int pcy, Color color, PaintInfo& pi) const { if(pcy > cy) pcy = cy; w.DrawRect(x, y, cx, cy, style.paper); int lw = DocZoom(zoom, style.leftwidth); int tw = DocZoom(zoom, style.topwidth); int rw = DocZoomLn(zoom, style.rightwidth); int bw = DocZoomLn(zoom, style.bottomwidth); int ls = DocZoom(zoom, style.leftspace); int ts = DocZoom(zoom, style.topspace); int rs = DocZoom(zoom, style.rightspace); int bs = DocZoom(zoom, style.bottomspace); Rect r(x + lw + ls, y + tw + ts, x + cx - rw - rs, y + cy - bw - bs); if(paintrect) { w.Clip(r); paintrect.Paint(w, r, color, style.paper); w.End(); } w.DrawRect(x, y, lw, cy, color); w.DrawRect(x, y, cx, tw, color); w.DrawRect(x + cx - rw, y, rw, cy, color); w.DrawRect(x, y + cy - bw, cx, bw, color); x = r.left; cx = r.Width(); switch(style.align) { case ALIGN_TOP: y = y + tw + ts; break; case ALIGN_CENTER: y = y + (cy - pcy) / 2 + tw + ts; break; case ALIGN_BOTTOM: y = y + cy - pcy - bw - bs; break; } int ymax = y + cy - bw - bs; int ypos = 0; for(int i = 0; i < par.GetCount(); i++) { const Paragraph& p = par[i]; int bef = DocZoom(zoom, p.GetBefore()); int aft = DocZoom(zoom, p.GetAfter()); if(ypos + bef - pi.yl + y > ymax) { pi.yl = ypos; return true; } ypos += bef; Paragraph::PaintInfo ppi; if(ypos >= pi.yl) { int py = y + ypos - pi.yl; if(p.Paint(zoom, w, x, py, cx, ymax, ppi, style.paper)) { pi.yl = ypos + ppi.yl; return true; } ypos += ppi.ypos - py; } else { int h = ypos < pi.yl ? p.GetHeight(zoom, cx) : 0; if(ypos + h > pi.yl) { ppi.yl = pi.yl - ypos; if(p.Paint(zoom, w, x, y, cx, ymax, ppi, style.paper)) { pi.yl = ypos + ppi.yl; return true; } } ypos += h; } ypos += aft; if(ypos - pi.yl + y > ymax) { pi.yl = ypos; return true; } } pi.yl = ypos; return false; }