Recent

Author Topic: Draw Curved Text  (Read 23833 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #15 on: April 19, 2015, 12:48:54 am »
Here a screenshot.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Draw Curved Text
« Reply #16 on: April 19, 2015, 01:57:17 am »
I saw a small typo in BezierTextOut related to ptCnt:
Code: [Select]
  with ACanvas do
  begin
    SetLength(flatPts, ptCnt);
    SetLength(types, ptCnt);
    SetLength(distances, ptCnt);

    flatPts := GetBezierPolyline(BezierPoints);
    ptCnt := Length(flatPts);
    if ptCnt < 1 then Exit;

changed the order to as I assume you intended to do:
Code: [Select]
  with ACanvas do
  begin
    flatPts := GetBezierPolyline(BezierPoints);
    ptCnt := Length(flatPts);
    if ptCnt < 1 then Exit;

    SetLength(flatPts, ptCnt);
    SetLength(types, ptCnt);
    SetLength(distances, ptCnt);

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #17 on: April 19, 2015, 06:06:13 am »
Yes, you are right.

finalpatch

  • New Member
  • *
  • Posts: 12
Re: Draw Curved Text
« Reply #18 on: April 19, 2015, 11:43:58 am »
Here a screenshot.

Hi Typo,

I made a version using aggpas.

finalpatch

  • New Member
  • *
  • Posts: 12
Re: Draw Curved Text
« Reply #19 on: April 19, 2015, 11:58:48 am »
Here a screenshot.

Hi Typo,

I made a version using aggpas.

The main difference of the agg version is that its glyph shapes are actually warped by the curve too (rather than only the placement and orientation).

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #20 on: April 19, 2015, 12:21:30 pm »
Please remove my unit from your demo and add only AGGBezierTextOut demo here:

http://bugs.freepascal.org/view.php?id=27899

finalpatch

  • New Member
  • *
  • Posts: 12
Re: Draw Curved Text
« Reply #21 on: April 19, 2015, 12:34:37 pm »
Please remove my unit from your demo and add only AGGBezierTextOut demo here:

http://bugs.freepascal.org/view.php?id=27899

Hi Typo,

I'm not sure I get what you mean.  Are you against my demo project including your code? It was just for the sake of having a side by side comparison of the 2 methods. If this upsets you I apologize for that (but I don't know how to delete the attachment in the previous post).  I also don't have an account in the Lazarus bug tracker (and don't plan to register one) so I can't do anything there. But you are free to do anything you feel like with that agg curved text rendering code.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #22 on: April 19, 2015, 12:37:07 pm »
OK, if you agree I will add it.

finalpatch

  • New Member
  • *
  • Posts: 12
Re: Draw Curved Text
« Reply #23 on: April 19, 2015, 12:53:14 pm »
OK, if you agree I will add it.

Cool!  Just keep in mind (maybe i should have added a comment) that this code is only for demo purpose (many things are hard coded, no sanity check, unoptimized) and should not be used in production code directly (for example one obviously should not construct and destruct the font engine in every call to this function).

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #24 on: April 19, 2015, 12:59:17 pm »
Well, maybe it is not a good idea to use aggpas for this.

finalpatch

  • New Member
  • *
  • Posts: 12
Re: Draw Curved Text
« Reply #25 on: April 19, 2015, 01:17:59 pm »
Well, maybe it is not a good idea to use aggpas for this.

Hi Typo, I do believe aggpas is a very good fit for this particular problem. This is because like I said before aggpas not only takes care of glyph positioning and orientation but also the shape of the glyphs so its result is more mathematically accurate.  This is especially noticeable when the curve has sharper turns.  What I was saying is that my code is a rather rough demo that only serves the purpose of showing people how this could be done.  There is no doubt with some refinement  one can make a very robust, generic and efficient function out of it (Although I don't have time for this).

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Draw Curved Text
« Reply #26 on: April 19, 2015, 03:50:08 pm »
Here a screenshot.

Hi Typo,

I made a version using aggpas.

The main difference of the agg version is that its glyph shapes are actually warped by the curve too (rather than only the placement and orientation).

The agg version is more than 10 times slower than Typo's, and it does not take ACanvas.Font properties - font name, style, size, and color - into consideration.

Both have an issue with cursive fonts.

Typo's version shifts the location where letters are printed on subsequent calls.

Edit:
In the first image Typo's version shows the letter T (in Text) at two different angles. Other tests showed the letter O (in Out) at a different angle. The agg version stayed black and bold (whence it's longer).

In the second image I changed the hardcoded font name in the agg version to use a cursive font for this test.
« Last Edit: April 19, 2015, 04:16:51 pm by engkin »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #27 on: April 19, 2015, 04:41:21 pm »
When I add the code below just at the end of BezierTexOut procedure, I have not this issue anymore.

Code: [Select]
   //reset font orientation
    ACanvas.Font.Orientation := 0;  <<<<<<<<  add this line

    //debug only - draw the path from the points ...
    //with flatPts[0] do ACanvas.moveto(X,Y);
    //for i := 1 to ptCnt -1 do with flatPts[i] do ACanvas.lineto(X,Y);
« Last Edit: April 19, 2015, 04:46:17 pm by typo »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Draw Curved Text
« Reply #28 on: April 19, 2015, 04:44:19 pm »
engkin can you test typo's with a bigger tolerance in the the GetBezierPolyline function? ee change the
Code: [Select]
cBezierTolerance = 0.00001; const to something like 0.001?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Draw Curved Text
« Reply #29 on: April 19, 2015, 04:55:23 pm »
Well, I have just tested and the result is in the attached image.

 

TinyPortal © 2005-2018