Hello,
has anything changed in the way of changing font and font size programmatically?
I'm trying the current RV version and my application seems to be "broken" partly.
I'm creating the rvActions and the controls for the ToolBar at run-time:
Code: Select all
myRVActionFont: TrvActionFontEx;
myRVActionFont := rvActionsResource.rvActionFontEx1;
myRVActionFont.Control := myRichViewEdit;
myRichViewEdit.OnCurTextStyleChanged := myRichViewEditCurTextStyleChanged;
procedure myRichViewEditCurTextStyleChanged(Sender: TObject);
var
TempStyle: TFontInfo;
begin
TempStyle := myRichViewEdit.Style.TextStyles[myRichViewEdit.CurTextStyleNo];
cxFontNameComboBox.FontName := TempStyle.FontName;
cxSpinEditFontSize.Value := TempStyle.Size;
end;
Then reading the font related user settings and setting them, if the RichViewEdit is empty:
Code: Select all
var
myTextStyle: TFontInfo;
myIndexNewTextStyle: integer;
begin
myTextStyle := TFontInfo.Create(nil);
try
myTextStyle.FontName := DefaultUserFont; // Calibri
myTextStyle.Size := DefaultUserFontSize; // 11
myTextStyle.Color := DefaultUserFontColor; // clBlack
if assigned(cxColorComboBoxSchriftfarbe) then begin
cxColorComboBoxSchriftfarbe.ColorValue := myTextStyle.Color;
end;
cxFontNameComboBox.FontName := myTextStyle.FontName;
cxSpinEditFontSize.Value := myTextStyle.Size;
if assigned(myRichViewEdit.Style) then begin
if myRichViewEdit.Style.TextStyles.FindSuchStyle(0, myTextStyle, RVAllFontInfoProperties) <= 0 then begin
myRichViewEdit.Style.TextStyles.Add;
myIndexNewTextStyle := myRichViewEdit.Style.TextStyles.Count-1;
myRichViewEdit.Style.TextStyles[myIndexNewTextStyle].Assign(myTextStyle);
myRichViewEdit.Style.TextStyles[myIndexNewTextStyle].Standard := false;
end;
with rvetRVActionSchriftart do begin
UserInterface := False;
ValidProperties := [rvfimFontName, rvfimColor, rvfimSize];
Font.Name := myTextStyle.FontName;
Font.Color := myTextStyle.Color;
Font.Size := myTextStyle.Size;
Execute;
UserInterface := True;
end;
myRichViewEdit.ClearUndo;
end;
finally
FreeAndNil(myTextStyle);
end;
end;
After this my controls have correct values (color, font name, size) and also when I start to type, everything looks fine within the RichViewEdit, but when I do a right click -> "font" menu, the UserInterface of the font action shows, that the font size is 1, while the font name and color are correct here as well.
That's the first problem.
If the RichViewEdit is not empty, I'm calling the myRichViewEditCurTextStyleChanged procedure. The text that was saved with older versions looks fine, the controls too and also the UserInterface has correct values.
Once I add something after the existing text though, the new content has again the size of 1 (not always though, didn't figure out when exactly it happens, but it happens).
That's the second problem.
When I select some text - not matter if formatted correctly (size 11) or not (size 1) - and try to change the font size via the cxSpinEdit, nothing happens, while in the past the new size was applied correctly.
That's the third problem, although they all are probably related.
Changing the font name via the cxFontCombobox still works as before.
That's how I'm doing it:
Code: Select all
with myRVActionFont do begin
UserInterface := False;
ValidProperties := [rvfimFontName];
Font.Name := cxFontNameComboBox.FontName;
Execute;
UserInterface := True;
end;
TempInteger := Integer(cxSpinEditFontSize.EditValue);
with myRVActionFont do begin
UserInterface := False;
ValidProperties := [rvfimSize];
Font.Size := TempInteger;
Execute;
UserInterface := True;
end;
The only difference I've noticed: when changing the size myRichViewEdit.OnCurTextStyleChanged isn't being fired anymore, while it still is being fired when changing the font name or the color.
I went through the changelogs and the only somewhat related change I've found is: "A new text property is added: FontSizeDouble." but judging by the description this shouldn't cause such a behaviour, I think.
Any idea what is going wrong and how to fix it?