Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: Arabic text, problem on Linux
« Last post by marius.maximus on Today at 10:50:09 am »
I take font from this web page https://arbfonts.com/the-sans-plain-3-font-download.html?preview=%D8%B3%D8%B7%D9%88%D8%B9+1
I am 100% sure this font is used on my Linux after delete .ttf I have squares instead of letters ;)

I open this font in online editor, in my opinion is OK
I use this font in Qt application on Windows and is OK

In Arabic, the appearance of a letter depends on its position , the character at the beginning, middle and end of the word looks different.
In my APP on Linux the Arabic  letter is always the same regardless of position
2
Thank you all for the replies. For my own purposes, TRon's suggested workaround is the best option, since it keeps everything within a single line of code. I'll be using that until the issue itself is fixed:

[...]
Another solution/workaround:
Code: Pascal  [Select][+][-]
  1. uses
  2.   types;
  3. var
  4.   a : String;
  5. begin
  6.   for a in TStringDynArray.Create('pear','apple','banana','pineapple','orange')
  7.     do writeLn(a);
  8. end.
  9.  

This looks like iteration of a set of strings. I thought things in set had to be ordinal values? Did something change?
[...]

I might be using the wrong terminology. I'm a self-taught amateur and not really on the up-and-up.

Is there any good reason to use for.. in to iterate through an array instead of using a for loop with index? I’m only familiar with using for.. in in the context of things like sets where the number of items is unknown. I’ve also seen it used for fields in an sql dataset.

There are a few reasons, but the specific scenario that prompted me to open this thread is that such a for-in loop is the most compact way to add strings to a TStringList on the fly for testing and debugging purposes. If I used a for-to loop, I'd have to define my constant array somewhere else, which can't be done within in the vicinity of my loop, which means I'd have to jump back and forth a lot during testing. Writing the array as part of a for-in loop makes it possible to have everything in one place.

Aside from the specific scenario of having the array defined within the loop, there are sometimes very simple loops where the index serves no purpose beyond retrieving the item at that index, so a for-in loop performs that step implicitly and is easier to read and write. Compare:

Code: Pascal  [Select][+][-]
  1. for item in MyArray do SomeProcedure(item);

versus

Code: Pascal  [Select][+][-]
  1. for idx:=Low(MyArray) to High(MyArray) do SomeProcedure(MyArray[idx]);
3
General / Re: Arabic text, problem on Linux
« Last post by Thaddy on Today at 10:33:18 am »
I suspect it is merely a font issue.
4
Thanks for sharing KodeZwerg.
You are welcome!
Your method would indeed give the exact size, without any margin.
I forgot the "font-astic" word but it aint called margins :D
While we're at it, maybe it would make sense to return a bounding rectangle, because FirstX may not be zero. So the origin could be adjusted (maybe vertically as well).
Heres a different version that does do same but faster:
Code: Pascal  [Select][+][-]
  1. procedure ExactTextPixels(const AFont: TFont; const AText: string; out AWidth, AHeight: Integer);
  2. var
  3.   Bitmap: TBitmap;
  4.   PixelX, PixelY, // for the scanning
  5.   LeftX, RightX, TopY, BottomY, // store each direction to accurate output AWidth and AHeight
  6.   SizeX, SizeY: Integer; // initial bitmap size
  7. begin
  8.   // Initialize the output values
  9.   AWidth := 0;
  10.   AHeight := 0;
  11.  
  12.   // Create a bitmap and canvas
  13.   Bitmap := TBitmap.Create;
  14.   try
  15.     // Set the font for the canvas
  16.     Bitmap.Canvas.Font := AFont;
  17.  
  18.     // Calculate the needed dimension and add more space for non-normal fonts or font styles
  19.     SizeX := Bitmap.Canvas.TextWidth(AText) * 3;
  20.     SizeY := Bitmap.Canvas.TextHeight(AText) * 3;
  21.     Bitmap.SetSize(SizeX, SizeY);
  22.  
  23.     // Clear the bitmap and draw the text onto the bitmap,
  24.     // ensure that we got 2 different colors to check for one of them
  25.     Bitmap.Canvas.Brush.Color := clWhite;
  26.     Bitmap.Canvas.FillRect(Bitmap.Canvas.ClipRect);
  27.     Bitmap.Canvas.Font.Color := clBlack;
  28.     Bitmap.Canvas.TextOut(0, 0, AText);
  29.  
  30.     // Initialize scan variables in opposite manner to use Min() and Max() correct
  31.     LeftX := Bitmap.Width;
  32.     RightX := 0;
  33.     TopY := Bitmap.Height;
  34.     BottomY := 0;
  35.  
  36.     // Scan the bitmap from left to right
  37.     for PixelX := 0 to Pred(Bitmap.Width) do
  38.       for PixelY := 0 to Pred(Bitmap.Height) do
  39.         if Bitmap.Canvas.Pixels[PixelX, PixelY] <> clWhite then
  40.           LeftX := Min(LeftX, PixelX);
  41.  
  42.     // Scan the bitmap from right to left
  43.     for PixelX := Pred(Bitmap.Width) downto 0 do
  44.       for PixelY := 0 to Pred(Bitmap.Height) do
  45.         if Bitmap.Canvas.Pixels[PixelX, PixelY] <> clWhite then
  46.           RightX := Max(RightX, PixelX);
  47.  
  48.     // Scan the bitmap from top to bottom
  49.     for PixelY := 0 to Pred(Bitmap.Height) do
  50.       for PixelX := 0 to Pred(Bitmap.Width) do
  51.         if Bitmap.Canvas.Pixels[PixelX, PixelY] <> clWhite then
  52.           TopY := Min(TopY, PixelY);
  53.  
  54.     // Scan the bitmap from bottom to top
  55.     for PixelY := Pred(Bitmap.Height) downto 0 do
  56.       for PixelX := 0 to Pred(Bitmap.Width) do
  57.         if Bitmap.Canvas.Pixels[PixelX, PixelY] <> clWhite then
  58.           BottomY := Max(BottomY, PixelY);
  59.  
  60.     // Calculate the width and height based on the scan results
  61.     AWidth := Succ(RightX - LeftX);
  62.     AHeight := Succ(BottomY - TopY);
  63.  finally
  64.     Bitmap.Free;
  65.  end;
  66. end;
5
General / Re: Arabic text, problem on Linux
« Last post by AlexTP on Today at 10:25:48 am »
Post the code snippet which renders the text. It can be different functions: TCanvas.TextOut, DrawText, ExtTextOut etc.
6
As you mentioned, TeeChart is excellent for creating and visualizing charts and graphs. It offers a wide range of features for data representation, but it’s not specifically designed for image manipulation. For image manipulation tasks (such as zooming, panning, and drawing), consider using specialized image processing libraries or tools. These libraries are better suited for working with ordinary image files.
7
The problem is that if a files moves package, stale builded files from previous builds might not be  cleaned out anymore.

I usually first try to micro manage by  removing .o and .ppu from packages where the units have been removed. Only a quick attempt, no night work.

Because if that fails I delete all of them and then rebuild IDE and projects. Since that costs about a minute, you can't spend more than a minute manually fixing anyway.

8
General / Arabic text, problem on Linux
« Last post by marius.maximus on Today at 10:04:39 am »
On Linux I have wrong arabic text
picture: https://i.imgur.com/Yb4lXsw.png

Correct version (from Windows)
picture: https://i.imgur.com/NlgJGMj.png

I have correct font
And font has correct chars, but Lazarus app on Linux uses only main form of char

for example char `seen-arab` has 4 forms:
seen-arab
seen-arab.fina
seen-arab.init
seen-arab.medi
https://i.imgur.com/1jtNnRQ.png

but my app use only `seen-arab`

9
Is there any good reason to use for.. in to iterate through an array instead of using a for loop with index? I’m only familiar with using for.. in in the context of things like sets where the number of items is unknown. I’ve also seen it used for fields in an sql dataset.

Abstraction of iteration?
Prevent errors through wrong index, especially with nested loops?
Less defined local variables (the index) improves readability of function head?
Readability in the iteration itself?

Code: [Select]
for i := 0 to Pred(Length(A)) do begin
   item := A[i];
   item.DoSomething;
end;

for i := 0 to Pred(Length(A)) do begin
   A[i].DoSomething;
end;

for item in A do begin
   item.DoSomething;
end;
10
There's some useful information in this thread.

There is a 3rd known way for this error. But it (probably) does not apply here.
The error can happen with 2 files in the same package. If the have circular references, and use inline in a very specific way.
They will both be build, but later one of them will give this error. (At least that was possible with older fpc)

I was actually able to solve the issue by changing the circular dependency in said unit. Then it occured with another unit, where again I moved the dependency from interface to implementation, and simply checked the type of the now more generic parameter.
Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018