Comments (6)
That’s a good point.
from bgrabitmap.
In fact, you can get TextSize with line breaks by specifying the maximum width parameter:
function TextSize(sUTF8: string; AMaxWidth: integer): TSize; override;
Though you would have a paragraph spacing of zero.
from bgrabitmap.
I wrote the following two functions to measure multi-line strings. The first takes a TStrings as argument; the other takes a string.
function BgraTextMultilineSize(const ABgraBitmap: TBgraBitmap;
const AStrings: TStrings; const AParagraphSpacing: Single = 0.0): TSize;
var TextLineSize: TSize;
i: Integer;
begin
Result := Size(0, 0);
if AStrings.Count > 0 then
begin
for i := 0 to AStrings.Count-1 do
begin
TextLineSize := ABgraBitmap.TextSize(AStrings[i]);
Result := Size( Max(Result.Width,TextLineSize.Width),
Result.Height + TextLineSize.Height );
end;
Inc(Result.cy, Round(AParagraphSpacing*i));
end;
end;
function BgraTextMultilineSize(const ABgraBitmap: TBgraBitmap;
const AStr: String; const AParagraphSpacing: Single = 0.0): TSize;
var TmpStrings: TStringList;
begin
if AStr.IsEmpty then Exit( Size(0,0) );
TmpStrings := TStringList.Create();
TmpStrings.Text := AStr;
Result := BgraTextMultilineSize(ABgraBitmap, TmpStrings, AParagraphSpacing);
TmpStrings.Free();
end;
But it would be nice if this functionality was integrated into the library.
from bgrabitmap.
I see. So you would like to be able to have a non zero paragraph spacing I suppose.
Alright then.
from bgrabitmap.
What about this signature?
function TBGRABitmap.TextSizeMultiline(sUTF8: string; AMaxWidth: single = EmptySingle; AParagraphSpacing: single = 0): TSize;
from bgrabitmap.
Done on dev branch
from bgrabitmap.
Related Issues (20)
- BGRABitmap and FPC 3.2-fixes HOT 5
- compile error on bgrapixel.inc HOT 5
- Maintain the "bit format" of a file between reading and subsequent writing HOT 5
- Error: Duplicate identifier "FResolutionUnit" HOT 4
- Cannot compile package BGRABitmapPack 11.5.8 HOT 4
- Avoid WideString, use UnicodeString HOT 3
- libwebp.pas fails to compile if -Mobjfpc was not used at compilation. HOT 1
- Draw image center/cover no-repeat HOT 3
- Compile error with new visibility check on FPC trunk. HOT 1
- Function 'round' causing problems HOT 17
- libavif.pas fails to compile (mode Delphi) HOT 4
- crash on loading WEBP image on Windows-10 x64 (32bit EXE) when no DLL file is present (it must show nice msg about missing DLL) HOT 12
- -dBGRABITMAP_CORE and Canvas2D HOT 2
- Gradient text and last version 11.6. HOT 3
- Inconsistent kerning of TextSize HOT 1
- Can't close a Form after using draw() onto a TImage.Canvas HOT 3
- Support Inkscape Filters HOT 7
- Add line spacing setting
- Lazarus 3.2 and fpc 3.2.2 HOT 2
- BGRABitmapPack pulls too many libraries HOT 23
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bgrabitmap.