RichText::GetWidth now supports tables

git-svn-id: svn://ultimatepp.org/upp/trunk@7361 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-05-06 09:44:51 +00:00
parent 612aab8425
commit 6d19d6a002
3 changed files with 27 additions and 2 deletions

View file

@ -185,6 +185,8 @@ private:
int GetVertMove(int pos, int gx, RichContext rc, int dir) const;
RichHotPos GetHotPos(int x, PageY y, int tolerance, RichContext rc) const;
void AdjustSel(Rect& sel) const;
int GetWidth(const RichStyles& st) const;
void GatherValPos(Vector<RichValPos>& f, RichContext rc, int pos, int type) const;
void ClearSpelling();
@ -206,7 +208,7 @@ public:
const RichTxt& Get(int i, int j) const { return cell[i][j].text; }
void SetQTF(int i, int j, const char *qtf);
void SetFormat(int i, int j, const RichCell::Format& fmt);
const RichCell::Format& GetFormat(int i, int j) { return cell[i][j].format; }
const RichCell::Format& GetFormat(int i, int j) const { return cell[i][j].format; }
bool operator()(int i, int j) const { return ci[i][j].valid; }
void SetSpan(int i, int j, int vspan, int hspan);
Size GetSpan(int i, int j) const;

View file

@ -172,6 +172,29 @@ void RichTable::Paint(PageDraw& pw, RichContext rc, const PaintInfo& _pi) const
pw.tracer->EndTable(rc.py);
}
int RichTable::GetWidth(const RichStyles& st) const
{
Size sz = GetSize();
Buffer<int> col(sz.cx, 0);
for(int x = 0; x < sz.cx; x++)
for(int y = 0; y < sz.cy; y++) {
const RichCell::Format& fmt = GetFormat(y, x);
col[x] = max(col[x], Get(y, x).GetWidth(st)
+ fmt.border.left + fmt.border.right + fmt.margin.left + fmt.margin.right);
}
int sum = 0;
for(int i = 0; i < sz.cx; i++)
sum += format.column[i];
int maxcx = 0;
for(int i = 0; i < sz.cx; i++)
maxcx = max(maxcx, (col[i] * sum + format.column[i] - 1) / format.column[i]);
return maxcx + (sz.cx + 1) * format.grid + format.lm + format.rm;
}
PageY RichTable::GetHeight(RichContext rc) const
{
PageY pyy = Realize(rc).pyy;

View file

@ -14,7 +14,7 @@ int RichTxt::GetWidth(const RichStyles& st) const
cx = max(cx, ccx);
}
else
return 10000;
return GetTable(i).GetWidth(st);
}
return cx;
}