Canvas drawing - certain textout's not appearing?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Sharpenski
Newbie
Newbie
Posts: 36
Joined: Wed Aug 24, 2016 12:00 am

Canvas drawing - certain textout's not appearing?

Post by Sharpenski » Tue Dec 06, 2016 10:14 am

The following code is used in my program to draw annotations on a chart canvas:

Code: Select all

With ChartEB do
  begin

    Canvas.Font.Assign(FontDialog1.Font); // Take this out, text appears, otherwise not

    // Vacuum Level (Evac)
    with Canvas.Pen do
    begin
      Color := clBlack;
      Style := psSolid;
      Width := 2;
    end;
    Canvas.MoveTo(ChartRect.Left, LeftAxis.CalcPosValue(0));
    Canvas.LineTo(ChartRect.Right, LeftAxis.CalcPosValue(0));
    Canvas.Pen.Width := 1;
    //ShowMessage('Evac: ' + IntToStr(StrToPxWidth('Evac', Canvas.Font.Size)));
    Canvas.TextOut(
      ChartRect.Right - StrToPxWidth('Evac', Canvas.Font.Size),
      LeftAxis.CalcPosValue(0) - (2 * Canvas.Font.Size),
      'Evac'
    );

    // Ef (Tip WF + CPD)
    Canvas.Pen.Color := clGreen; Canvas.Font.Color := clGreen;
    //Canvas.Pen.Handle := ExtCreatePen();
    Canvas.Pen.Style := psDash;
    Canvas.MoveTo(ChartRect.Left, LeftAxis.CalcPosValue(eF));
    Canvas.LineTo(ChartRect.Right, LeftAxis.CalcPosValue(eF));
    //ShowMessage('Ef: ' + IntToStr(StrToPxWidth('Ef', Canvas.Font.Size)));
    Canvas.TextOut(
      ChartRect.Right - StrToPxWidth(ShiftLabel('Ef', 1), Canvas.Font.Size),
      LeftAxis.CalcPosValue(eF) - (2 * Canvas.Font.Size),
      'Ef'
    );
    Canvas.Pen.Style := psSolid;
...

The second label appears regardless of whether the canvas font is set but the first does not appear unless I comment out the assignment - I don't understand this. Could you please tell me what the problem is and how I can get round it?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Canvas drawing - certain textout's not appearing?

Post by Yeray » Mon Dec 12, 2016 8:48 am

Hello,

It looks similar to this thread:
http://bugs.teechart.net/show_bug.cgi?id=473

Adding this code before calling TextOut solves the problem:

Code: Select all

    if FontDialog1.Font.Color=clNone then
      Canvas.Font.Color:=clBlack
    else
    if (Cardinal(FontDialog1.Font.Color)>={$IFDEF D7}clSystemColor{$ELSE}$80000000{$ENDIF}) and
       (Cardinal({$IFDEF D6}clMenuBar{$ELSE}clInfoBk{$ENDIF})>=Cardinal(FontDialog1.Font.Color)) then
      Canvas.Font.Color:=ColorToRGB(FontDialog1.Font.Color)
    else
      Canvas.Font.Color:=FontDialog1.Font.Color;
We'll check if something similar can be done internally.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply