Page 1 of 1

Canvas drawing - certain textout's not appearing?

Posted: Tue Dec 06, 2016 10:14 am
by 16479009
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?

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

Posted: Mon Dec 12, 2016 8:48 am
by yeray
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.