Page 1 of 1

Calculating Content Width

Posted: Fri Jul 08, 2011 6:17 pm
by pdcuser
At my work, we have built our on custom label built using TRichView. We are using the TRVReportHelper to paint to the label's canvas. It has become necessary to identify the width and height of the content being painted so that we can calculate the size to make the label.

Currently, we successfully calculate the height of the content by painting to a temporary bitmap and returning RVReportHelper.GetLastPageHeight.

Now, I am working on calculating the width. Assuming the following guidelines are always true, what is the best way to do this:

- The content will not word wrap. It will consume only one line.
- The content will not contain any non-text items.

Posted: Sun Jul 10, 2011 9:24 am
by Sergey Tkachenko
After formatting, RVReportHelper.RichView.RVData.DocumentWidth+RVReportHelper.RichView.LeftMargin+RVReportHelper.RichView.RightMargin

Posted: Mon Jul 11, 2011 9:28 pm
by pdcuser
This always returns the width of the bitmap's canvas. For future reference, I was able to solve this one via:

Code: Select all

  Width := rvh.RichView.LeftMargin + rvh.RichView.RightMargin;
  for I := 0 to rvh.RichView.RVData.DrawItems.Count - 1 do
    Width := Width + rvh.RichView.RVData.DrawItems[I].Width;

Posted: Wed Jul 13, 2011 7:03 pm
by Sergey Tkachenko
Use this code:

Code: Select all

Width := 0;
for I := 0 to rvh.RichView.RVData.DrawItems.Count - 1 do 
  if rvh.RichView.RVData.DrawItems[I].Left+rvh.RichView.RVData.DrawItems[I].Width>Width then
    Width := rvh.RichView.RVData.DrawItems[I].Left+rvh.RichView.RVData.DrawItems[I].Width;
inc(Width, rvh.RichView.RightMargin);