Recent

Author Topic: [LazFreeType] Patches  (Read 41103 times)

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
[LazFreeType] Patches
« on: March 22, 2012, 02:15:30 am »
Here is a patch for LazFreeType, which adds :
- multiple font support
- rasterizer is now a class
- font metrics : ascent, descent, linespacing, linefullheight (which are pixel metrics)
- line ending support
- text alignment (left/center/right, top/baseline/bottom)
- charsPosition : returns the position of each char (x, width, top, bottom) taking alignment and line endings into account
- smalllinepadding : true by default, can be set to false to have the same result as in word processors
- textwidth/textheight
- drawing on lazintfimage optimized
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #1 on: March 22, 2012, 11:58:19 am »
Hello, thanks a lot, this will greatly help LCL-CustomDrawn =)

But there are some errors which I don't know how to solve:

    if (left > length(LineEnding)) and (pstr^ = LineEnding[1]) then
and
        if (pstr+(i-1))^ <> LineEnding[ i ] then

The [] array access is refused in platforms where the LineEnding is a single char like Mac OS X and Linux and prevents compilation.

/home/felipe/Programas/lazarus/components/lazutils/easylazfreetype.pas(976,40) Error: Illegal qualifier

And I'd prefer if we could work in the bug tracker. thanks,
« Last Edit: March 22, 2012, 12:02:33 pm by felipemdc »

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #2 on: March 22, 2012, 04:26:29 pm »
You can define a global string variable that is assigned the value of LineEnding.

I am a little bit lost with the bugtracker. If I apply the filter "LazFreeType", I get 3 entries. Is it right ?
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #3 on: March 23, 2012, 07:52:45 am »
thanks, I applied in rev 36242, but the example fails with multiple errors.

First I can't compile because of routiens which don't exist:

Code: [Select]
  drawer.FillPixels(TColorToFPColor(clWhite));
and
  drawer.DrawHorizLine(round(x+p[i].x),round(y+p[i].yBase),round(x+p[i].x+p[i].width), TColorToFPColor(clBlue));
Also it uses the font "MS Comic Sans" which obviously does not exist in other platforms.

And also uses fonts which I can't easily find in my system:
    //ftFont2.Name := 'timesi.ttf';
    //ftFont3.Name := 'verdana.ttf';

And even if I correct all of that it still crashes =/

#0 SYSTEM_HANDLEERRORADDRFRAME$LONGINT$POINTER$POINTER at :0
#1 SYSTEM_HANDLEERRORFRAME$LONGINT$POINTER at :0
#2 TFREETYPEDRAWER__DRAWTEXT((ANSISTRING) 0x1993f68, (TFREETYPERENDERABLEFONT) 0x1988560, 72.6666641, 54.84375, {RED = 0, GREEN = 0, BLUE = 0, ALPHA = 65535}, [FTARIGHT], (TFREETYPEDRAWER) 0x1995700) at easylazfreetype.pas:296
#3 TFREETYPEDRAWER__DRAWTEXT((ANSISTRING) 0x2c7168, (TFREETYPERENDERABLEFONT) 0x1988560, 172, 54.84375, {RED = 0, GREEN = 0, BLUE = 0, ALPHA = 65535}, [FTARIGHT], (TFREETYPEDRAWER) 0x1995700) at easylazfreetype.pas:283
#4 TFORM1__FORMPAINT((^TOBJECT) 0x197f630, (TFORM1) 0x197f630) at :0
#5 TCUSTOMCONTROL__PAINT((TCUSTOMCONTROL) 0x197f630) at ./include/customcontrol.inc:79
#6 TCUSTOMFORM__PAINTWINDOW(30624256, (TCUSTOMFORM) 0x197f630) at ./include/customform.inc:1115
#7 TWINCONTROL__PAINTHANDLER({MSG = 15, DC = 30624256, PAINTSTRUCT = 0x19a8b10, RESULT = 0}, (TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:4721
#8 TWINCONTROL__WMPAINT({MSG = 15, DC = 30624256, PAINTSTRUCT = 0x19a8b10, RESULT = 0}, (TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:6606
#9 TCUSTOMCONTROL__WMPAINT({MSG = 15, DC = 30624256, PAINTSTRUCT = 0x19a8b10, RESULT = 0}, (TCUSTOMCONTROL) 0x197f630) at ./include/customcontrol.inc:112
#10 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#11 TWINCONTROL__WNDPROC({MSG = 15, WPARAM = 30624256, LPARAM = 26905360, RESULT = 0, WPARAMLO = 18944, WPARAMHI = 467, LPARAMLO = 35600, LPARAMHI = 410, RESULTLO = 0, RESULTHI = 0}, (TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:5276
#12 TCUSTOMFORM__WNDPROC({MSG = 15, WPARAM = 30624256, LPARAM = 26905360, RESULT = 0, WPARAMLO = 18944, WPARAMHI = 467, LPARAMLO = 35600, LPARAMHI = 410, RESULTLO = 0, RESULTHI = 0}, (TCUSTOMFORM) 0x197f630) at ./include/customform.inc:1414
#13 DELIVERMESSAGE((^TOBJECT) 0x197f630, void) at lclmessageglue.pas:117
#14 LCLSENDPAINTMSG((^TCONTROL) 0x197f630, 30624256, (PPAINTSTRUCT) 0x19a8b10) at lclmessageglue.pas:796
#15 CARBONCOMMON_DRAW((CFSTRINGREF) 0xbfffefc0, (CFSTRINGREF) 0x1b0f200, (^TCARBONWIDGET) 0x19cb060) at ./carbon/carbonprivatecommon.inc:117
#16 DispatchEventToHandlers at :0
#17 SendEventToEventTargetInternal at :0
#18 SendEventToEventTargetWithOptions at :0
#19 HIView::SendDraw at :0
#20 HIView::RecursiveDrawComposited at :0
#21 HIView::RecursiveDrawComposited at :0
#22 HIView::RecursiveDrawComposited at :0
#23 HIView::RecursiveDrawComposited at :0
#24 HIView::DrawComposited at :0
#25 HIView::Draw at :0
#26 HIView::Render at :0
#27 WindowData::PrepareForVisibility at :0
#28 _ShowHideWindows at :0
#29 ShowWindow at :0
#30 TCARBONWINDOW__SHOWHIDE(true, (TCARBONWINDOW) 0x19cb060) at ./carbon/carbonprivatewindow.inc:1697
#31 TCARBONWSCUSTOMFORM__SHOWHIDE((^TWINCONTROL) 0x197f630, (pvmt) 0x1e4f8a0) at ./carbon/carbonwsforms.pp:293
#32 TWINCONTROL__DOSENDSHOWHIDETOINTERFACE((TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:8139
#33 TWINCONTROL__CMSHOWINGCHANGED({MSG = 45081, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, LPARAMLO = 0, LPARAMHI = 0, RESULTLO = 0, RESULTHI = 0}, (TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:8323
#34 TCUSTOMFORM__CMSHOWINGCHANGED({MSG = 45081, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, LPARAMLO = 0, LPARAMHI = 0, RESULTLO = 0, RESULTHI = 0}, (TCUSTOMFORM) 0x197f630) at ./include/customform.inc:622
#35 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#36 TWINCONTROL__WNDPROC({MSG = 45081, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, LPARAMLO = 0, LPARAMHI = 0, RESULTLO = 0, RESULTHI = 0}, (TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:5276
#37 TCUSTOMFORM__WNDPROC({MSG = 45081, WPARAM = 0, LPARAM = 0, RESULT = 0, WPARAMLO = 0, WPARAMHI = 0, LPARAMLO = 0, LPARAMHI = 0, RESULTLO = 0, RESULTHI = 0}, (TCUSTOMFORM) 0x197f630) at ./include/customform.inc:1414
#38 TCONTROL__PERFORM(45081, 0, 0, (TCONTROL) 0x197f630) at ./include/control.inc:1464
#39 CHANGESHOWING(true, (POINTER) 0xbffff838) at ./include/wincontrol.inc:4269
#40 TWINCONTROL__UPDATESHOWING((TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:4319
#41 TCUSTOMFORM__UPDATESHOWING((TCUSTOMFORM) 0x197f630) at ./include/customform.inc:2630
#42 TWINCONTROL__DOALLAUTOSIZE((TWINCONTROL) 0x197f630) at ./include/wincontrol.inc:3535
#43 TCONTROL__ENABLEAUTOSIZING((TCONTROL) 0x197f630) at ./include/control.inc:5402
#44 TCONTROL__SETVISIBLE(true, (TCONTROL) 0x197f630) at ./include/control.inc:4248
#45 TCUSTOMFORM__SETVISIBLE(true, (TCUSTOMFORM) 0x197f630) at ./include/customform.inc:472
#46 TCUSTOMFORM__SHOW((TCUSTOMFORM) 0x197f630) at ./include/customform.inc:2164
#47 TAPPLICATION__RUN((TAPPLICATION) 0x1940360) at ./include/application.inc:1401
#48 PASCALMAIN at lazfreetypetest.lpr:17
#49 SYSTEM_FPC_SYSTEMMAIN$LONGINT$PPCHAR$PPCHAR at :0
#50 _start at :0
#51 start at :0

This affects only the example ... LCL-CustomDrawn works normally.

thanks,

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #4 on: March 23, 2012, 07:55:54 am »
Ah, also, it would be good to have a second drawer for Lazarus (in the same unit) which is based in TLazCanvas instead of TLazIntfImage. This is a good idea because TLazCanvas enforces clipping while TLazIntfImage leaves you free to draw everywhere (which violates clipping).

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #5 on: March 23, 2012, 08:19:15 am »
I am a little bit lost with the bugtracker. If I apply the filter "LazFreeType", I get 3 entries. Is it right ?

Yes, probably right. If you say how you are called in the bug tracker then I can simply assign the issues to you. Then you can just search for issues assigned to you.

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #6 on: March 23, 2012, 01:56:24 pm »
thanks, I applied in rev 36242, but the example fails with multiple errors.

First I can't compile because of routiens which don't exist:

Code: [Select]
  drawer.FillPixels(TColorToFPColor(clWhite));
and
  drawer.DrawHorizLine(round(x+p[i].x),round(y+p[i].yBase),round(x+p[i].x+p[i].width), TColorToFPColor(clBlue));
I've added these units in LazFreeTypeIntfDrawer. It is not in the patch ? Anyway here is a copy of it.
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #7 on: March 23, 2012, 02:44:59 pm »
I think I had some old PPUs somewhere because I tryed to apply your new unit but the diff result was empty, so it is already in SVN. But still, requiring having arial.ttf, timesi.ttf and verdana.ttf will make sure this can only be used in Windows ...

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #8 on: March 23, 2012, 04:55:02 pm »
I don't mind if you change this. I do not "want" it to be only on Windows. These are files that worked for me. What do you propose ? Maybe we could find automatically the font folder.

So did you manage to make it work ?
« Last Edit: March 23, 2012, 05:30:07 pm by circular »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #9 on: March 24, 2012, 08:36:18 pm »
Here is a second patch that adds the feature of getting information about a font.

New properties : VersionNumber, Family, and Information.
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #10 on: March 26, 2012, 02:29:42 pm »
Thanks, applied in rev 36345

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #11 on: April 03, 2012, 09:55:34 am »
@circular

What is you name in the Lazarus Bug Tracker?

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #12 on: April 08, 2012, 05:20:22 pm »
@felipemdc: it's "circular"

I wonder how to integrate font collection in LazFreeType. I propose this :

there would be a global collection, automatically created, called for example FreeTypeCollection. It would be possible to add a directory of font at program startup.

the TFreeTypeFont would have a Collection property which would be initialized with the global collection. But it could be assigned to another object, allowing to work with multiple font collections. When a collection with font is available, the TFreeTypeFont object could interpret the Name property as a familiy name, and take styles into account.

What do you think ?
Conscience is the debugger of the mind

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: [LazFreeType] Patches
« Reply #13 on: April 09, 2012, 02:24:36 pm »
In general yes, it would be great of LazFreeType could do the work of searching for the best font to use with a given set o characteristics (monospace, italic, bold, serif vs non-serif), although it should also still support simply giving the direct full path for the font like now.

About the directory of fonts, it should be a list of directories, never suppose that only 1 directory will contain all fonts.

Giuliano might have more feedback on this. Note also that we already have some code which does font selection in LCL-CustomDrawn.

circular

  • Hero Member
  • *****
  • Posts: 3047
    • Personal webpage
Re: [LazFreeType] Patches
« Reply #14 on: April 09, 2012, 08:20:47 pm »
In general yes, it would be great of LazFreeType could do the work of searching for the best font to use with a given set o characteristics (monospace, italic, bold, serif vs non-serif), although it should also still support simply giving the direct full path for the font like now.
Of course.

Quote
About the directory of fonts, it should be a list of directories, never suppose that only 1 directory will contain all fonts.
Yes, multiple call to AddFolder.

Quote
Giuliano might have more feedback on this.
Ok.

Quote
Note also that we already have some code which does font selection in LCL-CustomDrawn.
Which code ?
Conscience is the debugger of the mind