Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Font Size Issue on Resize
Mon, Jan 9 2017 2:10 PMPermanent Link

R&D team @ Environment Canada

Hello, I have an issue on the project I am working on where font sizes seem to go to default size when I resize and redraw text to the screen.  I created a new project to make sure it wasn't something else I was doing.

This project has 2 panels top/bottom with a sizer inbetween.  The splitter correctly resizes both panels.

This is the code I have.


procedure TForm1.Form1Create(Sender: TObject);
begin
  pntMain.Canvas.Font.Name := 'Arial';
  pntMain.Canvas.Font.Size := 14;
  drawText;
end;

procedure TForm1.drawText;
begin
  pntMain.Canvas.FillText(intToStr(pntMain.Canvas.Font.Size), 100, 100);
end;

procedure TForm1.BasicPanel1Size(Sender: TObject);
begin
  drawText;
end;


When the application starts a 14 is drawn at the correct size.  The moment I use the sizer the 14 immediately gets smaller (and I believe the font changes but it is hard to tell).  It is still writing 14 suggesting it is still set to a font size of 14 but it draws it as the default font.  If I instead put drawText; in the paintSize event it does not draw anything at all.


Steven Laroche, Environment Canada.
Mon, Jan 9 2017 3:20 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bruno,

<< Hello, I have an issue on the project I am working on where font sizes seem to go to default size when I resize and redraw text to the screen.  I created a new project to make sure it wasn't something else I was doing. >>

Here's the hot-fix:

WebUI unit:

procedure TCanvasElement.Reset;
begin
  FAlpha:=1;
  FCompositeOperation:=coSourceOver;
  FFillStyle:=dsColor;
  FFillColor:=clBlack;
  FFillGradient.Free;
  FFillGradient:=TCanvasGradient.Create(Self);
  FFillPattern.Free;
  FFillPattern:=TCanvasPattern.Create(Self);
  FLineCapStyle:=csButt;
  FLineJoinStyle:=jsMiter;
  FLineWidth:=1;
  FMiterLimit:=10;
  FShadowBlur:=0;
  FShadowColor:=clBlack;
  FShadowOffsetX:=0;
  FShadowOffsetY:=0;
  FStrokeStyle:=dsColor;
  FStrokeColor:=clBlack;
  FStrokeGradient.Free;
  FStrokeGradient:=TCanvasGradient.Create(Self);
  FStrokePattern.Free;
  FStrokePattern:=TCanvasPattern.Create(Self);
  FContext.font:=Font.GetStyle;  <<<<<<<<<<<<<<<<<<<<<<<<  Add this !!!!!
  FTextAlign:=taLeftJustify;
  FContext.textAlign:=TextAlignmentToStr(FTextAlign);
  FTextBaseLine:=blAlphabetic;
end;

A fix will be in 2.06.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 9 2017 3:51 PMPermanent Link

R&D team @ Environment Canada

Thank you, it works perfectly now, it also fixed a similar bug I couldn't figure out in another project.
Image