Calculating Content Width

General TRichView support forum. Please post your questions here
Post Reply
pdcuser
Posts: 17
Joined: Tue Jan 17, 2006 9:00 pm

Calculating Content Width

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

After formatting, RVReportHelper.RichView.RVData.DocumentWidth+RVReportHelper.RichView.LeftMargin+RVReportHelper.RichView.RightMargin
pdcuser
Posts: 17
Joined: Tue Jan 17, 2006 9:00 pm

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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);
Post Reply