Recent

Author Topic: [SOLVED] Splitting an image  (Read 12404 times)

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Splitting an image
« Reply #60 on: May 11, 2024, 03:36:35 pm »
I know I am a terrible forum member that keeps asking.


But is it possible to adjust the letters in the boxes zo they are centered?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

paweld

  • Hero Member
  • *****
  • Posts: 1422
Re: Splitting an image
« Reply #61 on: May 11, 2024, 04:31:11 pm »
check my example - there they are centered
Best regards / Pozdrawiam
paweld

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Splitting an image
« Reply #62 on: May 11, 2024, 04:35:56 pm »
i am looking at it....but don't know whee to look.
I am just a hobby programmer
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Splitting an image
« Reply #63 on: May 11, 2024, 04:51:13 pm »
First off all I am glad that it works now for you and that you actually read the source to (de)activate proper compile setting :D
I know I am a terrible forum member that keeps asking.


But is it possible to adjust the letters in the boxes zo they are centered?
With my example you have 2 options, try to draw it quick with disadvantage as of right now to be drawn centered
or you turn Speedmode off and get a centered variation that also is filling out the available space.

If you really want "small" letters than I would need to rethink my doing or you simply switch to the way faster always sharp rendered variant from paweld with 360 possible colorchanges on the fly :D
(because that it always look extra sharp I personal dislike it but the speed, omg, I do envy you so much ^_^)

Attached is my latest modifications, dont ask what I've changed, here and there some quirks :D
and again exemplary 2 images with the speed mode turned on and off.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paweld

  • Hero Member
  • *****
  • Posts: 1422
Re: Splitting an image
« Reply #64 on: May 12, 2024, 08:00:12 am »
Quote from: madref
I know I am a terrible forum member that keeps asking.
that's what the forum is for
Quote from: madref
But is it possible to adjust the letters in the boxes zo they are centered?
I took the liberty of slightly modifying @KodeZwerg's solution (I modified the latest version of the uFont.pas file) so that with “SpeedMode” the letters are centered.
Quote from: KodeZwerg
... but the speed, omg, I do envy you so much ^_^)
this is all thanks to the BGRABitmap component.
« Last Edit: May 12, 2024, 08:02:40 am by paweld »
Best regards / Pozdrawiam
paweld

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Splitting an image
« Reply #65 on: May 12, 2024, 11:31:22 am »
I took the liberty of slightly modifying @KodeZwerg's solution (I modified the latest version of the uFont.pas file) so that with “SpeedMode” the letters are centered.
Thank you very much, I should add an ultraspeed mode for your way :D The success rate (is font full drawn or does it gets cut) is pretty high for many fonts I've tested with.
In my personal opinion I do dislike it since its loosing its charme of being an rendered image instead of a clear and sharp drawn font but hey, it's not about me :D
Code: Pascal  [Select][+][-]
  1.             begin
  2.               LHighRes.SetSize(CCanvasWidth, CCanvasHeight);
  3.               LHighRes.Canvas.Brush.Color := $FEFEFE;
  4.               LHighRes.Canvas.FillRect(LHighRes.Canvas.ClipRect);
  5.               LHighRes.Canvas.Font := FFont;
  6.               LHighRes.Canvas.Font.Height := Pred(CCanvasHeight);
  7.               fw := LHighRes.Canvas.TextWidth(UTF8Copy(LWords[i], j, 1));
  8.               LHighRes.Canvas.TextRect(LHighRes.Canvas.ClipRect, Pred(Round((LHighRes.Width - fw) / 2.5)), 0, UTF8Copy(LWords[i], j, 1));
  9.             end;
Again very very slightly modified your way so they appear a mini bit more centered to the left side.

Cool contribution paweld!
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Splitting an image
« Reply #66 on: May 13, 2024, 12:33:22 am »
I tried the latest version of the uFont.pas but I get an error on these lines:
Code: Pascal  [Select][+][-]
  1.       function ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Int64; overload; inline;
  2.       function ScaleTo(const ACurrent, AMax, AScaleMax: Double; const AIncludeZero: Boolean = True): Int64; overload; inline;
  3.       function ScaleTo(const ACurrent, AMax, AScaleMax: Double; const AIncludeZero: Boolean = True): Double; overload; inline;
  4.       function ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Double; overload; inline;
  5.  


Why is of course the question
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Splitting an image
« Reply #67 on: May 13, 2024, 12:38:25 am »
...but I get an error on these lines...
Since you are not a coder you do not know this little thingy, without knowing the error there is not much we can talk about.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Splitting an image
« Reply #68 on: May 13, 2024, 12:41:33 am »
Here are the errors
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Splitting an image
« Reply #69 on: May 13, 2024, 12:56:32 am »
Here are the errors
Okay, it is strange but I accept that your version is not compatible to mine, no worries, fixing it is quit easy.
Make this:
Code: Pascal  [Select][+][-]
  1.       function ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Int64; overload; inline;
  2.       function ScaleTo(const ACurrent, AMax, AScaleMax: Double; const AIncludeZero: Boolean = True): Int64; overload; inline;
  3.       function ScaleTo(const ACurrent, AMax, AScaleMax: Double; const AIncludeZero: Boolean = True): Double; overload; inline;
  4.       function ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Double; overload; inline;
  5.  
Look like this: (since the overloads I just prepared to be exported in my codelib)
Code: Pascal  [Select][+][-]
  1.       function ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Int64; inline;
When that is done, scroll very very down to the source where you find
Code: Pascal  [Select][+][-]
  1. function TImageFont.ScaleTo(const ACurrent, AMax, AScaleMax: Int64; const AIncludeZero: Boolean = True): Int64; overload; inline;
  2. begin
  3.   if AMax = 0 then
  4.     Result := 0
  5.   else
  6.   if ACurrent >= AMax then
  7.     begin
  8.       if AIncludeZero then
  9.         Result := AScaleMax
  10.       else
  11.         Result := Pred(AScaleMax);
  12.     end
  13.   else
  14.     if AIncludeZero then
  15.       Result := Round(ACurrent * AScaleMax / AMax)
  16.     else
  17.       Result := Round(ACurrent * Pred(AScaleMax) / AMax);
  18. end;
remove there the "overload;" in first line and delete all other "ScaleTo" variations.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Splitting an image
« Reply #70 on: May 15, 2024, 09:55:06 pm »
I thought it was solved but I noticed a strange behavior with the letter i.


All letters are nice and tight except the letter i.


See picture.


Is there a way to solve this?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: splitting an image
« Reply #71 on: May 15, 2024, 10:25:35 pm »
All letters are nice and tight except the letter i.
hmmm... I thought I've told that.
Problematic could be small printable chars that become "overstretched", like a dot become a gigantic cube.
Is there a way to solve this?
As of right now, no. Since the Stretch-To-Fit way does do exact what it should, it stretch the font to fit into the box by filling it out in all dimensions, without respecting proportions.
So when using the non-speed mode to stretch, than it is like it is, sorry mate.
Dangerous characters for stretching (depend on font) = i l 1 . , - _ : ; ' ^ ` ~ + ´ { ( [ ] ) } ² ³ |  (probably more small/thin characters that I forgot to mention)

Feel free to invent for those dangerous characters a separate way of how it's handled.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [NOT SOLVED] Splitting an image
« Reply #72 on: May 15, 2024, 10:38:48 pm »
By quick checking for some unicode replacement for letter "i" -> this works " Ⅰ "

//edit
added image with the dangerous characters rendered two times, once in speed mode and once without.
there you can see pretty good what the stretching does do to small/thin characters.
« Last Edit: May 15, 2024, 11:26:08 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

madref

  • Hero Member
  • *****
  • Posts: 1104
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: [NOT SOLVED] Splitting an image
« Reply #73 on: May 16, 2024, 12:34:42 am »
Maybe a silly option but is it possible to NOT stretch the letters but use a font size instead? and then center these letters?


Or am I asking to much?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sonoma 14.7.4
Lazarus 4.99 (rev main_4_99-1378-ga4855f6fa5) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [NOT SOLVED] Splitting an image
« Reply #74 on: May 16, 2024, 12:41:48 am »
Maybe a silly option but is it possible to NOT stretch the letters but use a font size instead? and then center these letters?


Or am I asking to much?
Watch image, what you want to have changed?
Its either stretched or centered but smaller.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

 

TinyPortal © 2005-2018