Drop Caps (TRVLabel)

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Drop Caps (TRVLabel)

Post by standay »

Hi Sergey,

I've been reworking my code for drop caps. I'm using some code from the forum I found some time ago.

Code: Select all

  Lii := TRVLabelItemInfo.Create(rv.RVData);
  FI := TFontInfo.Create(nil);
  try
    FI.FontName := rv.Style.TextStyles[0].FontName;
    FI.Size := (rv.Style.TextStyles[0].Size * 3);
    FI.StyleName := 'InitCap';
    FI.Standard := False;
    Lii.VAlign := rvvaLeft ;
    Lii.TextStyleNo := rv.Style.FindTextStyle(FI);
    Lii.Text := rv.GetSelTextW; //Ch;
    Lii.OuterVSpacing := -4;
    Lii.SetExtraIntProperty( rvepOuterVSpacing , Lii.OuterVSpacing );
    rv.InsertItem('', Lii);
I ran into a problem where the drop cap in the rve looks OK, but in the print preview the vertical position is different. I've been using these lines to fix it

For the regular rve, I do this:

Code: Select all

TRVLabelItemInfo(rv.RVData.GetItem(i)).OuterVSpacing := -4;
But for the print preview I do this:

Code: Select all

TRVLabelItemInfo(rv.RVData.GetItem(i)).OuterVSpacing := 4;
I don't like using "magic numbers" (in this case plus and minus "4"). I've tried it without that but if I don't set the OuterVSpacing it doesn't position correctly. I've tried various combinations of RemoveInternalLeading and RemoveSpaceBelow and those didn't help.

I'll attach an example rvf file. Put it into the RichViewActionsTest demo and it should look like this:

correct.png
correct.png (35.42 KiB) Viewed 8472 times

Then, do a print preview and it looks like this:

incorrect.png
incorrect.png (19.28 KiB) Viewed 8472 times

I want the drop cap position in the print preview to match the regular rve. My current code is working but I have a feeling there may be a much better way.

Thanks Sergey

Stan
Attachments
Drop Cap Test.rvf
(2.54 KiB) Downloaded 759 times
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Drop Caps (TRVLabel)

Post by Sergey Tkachenko »

Margins are not supposed to be negative.
I have an alternative suggestion: instead of changing margins, you can use RemoveInternalLeading property.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Drop Caps (TRVLabel)

Post by standay »

Sergey Tkachenko wrote: Thu Mar 16, 2023 8:53 am Margins are not supposed to be negative.
I have an alternative suggestion: instead of changing margins, you can use RemoveInternalLeading property.
Hi Sergey,

I'm setting both RemoveInternalLeading and RemoveSpaceBelow to true. That seems to take care of the regular rve so I removed setting OuterVSpacing to -4.

However, I still have to set OuterVSpacing to +4 for drop caps in the print preview to align them to match what I see in the rve (to keep them from sitting too high relative to the other para text). +4 seems to be the value needed regardless of font or font size.

Is it correct to have to adjust OuterVSpacing for print preview? I'm thinking it may have to do with dpi but I don't know.

Stan
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Drop Caps (TRVLabel)

Post by Sergey Tkachenko »

There is a bug: RemoveInternalLeading is processed incorrectly on printing, so the label is drawn higher than it should.
Quick fix: open RVLabelItem.pas. In TRVLabelItemInfo.Print, remove the line

Code: Select all

Y := Y + RV_YToDevice(YOffs, sad);
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Drop Caps (TRVLabel)

Post by standay »

Hi Sergey,

Yes, that fixed the print preview! I no longer have to set OuterVSpacing and it all works! Thanks.

One more related question. I have RemoveSpaceBelow set to true. I would expect that to eliminate the space below the drop cap, but no matter what I do, I get this:

Image23.png
Image23.png (3.42 KiB) Viewed 8415 times

What I want (and would expect RemoveSpaceBelow := true to do) is this (image was edited to show what I'm after):

Image25.png
Image25.png (3.27 KiB) Viewed 8415 times

Any ideas on how to achieve that?

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Drop Caps (TRVLabel)

Post by Sergey Tkachenko »

This property is applied only if Label.UseTypoMetric = True (it should be the default value, and it makes no sense to set it to False).

Please note that this property does not remove the whole space below the baseline. It removes only a difference between a font descent (from TEXTMETRIC) and a typographic font descent (from OUTLINETEXTMETRIC). This is a small value. In your document, 1 pixel.

Also, when Label.UseTypoMetric = True, RemoveInternalLeading removes a difference between a font ascent (from TEXTMETRIC) and a typographic font ascent (from OUTLINETEXTMETRIC). Label.UseTypoMetric = False, it removes an internal leading (from TEXTMETRIC). Normally, it should be the same, but it's not necessary.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Drop Caps (TRVLabel)

Post by standay »

OK, thanks. I get the best results with RemoveInternalLeading := true; RemoveSpaceBelow := true; UseTypoMetric := false. I think that's about the closest I can get.

Thanks Sergey

Stan
Post Reply