Code Monkey home page Code Monkey logo

Comments (6)

circular17 avatar circular17 commented on May 30, 2024

That’s a good point.

from bgrabitmap.

circular17 avatar circular17 commented on May 30, 2024

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.

josiasmat avatar josiasmat commented on May 30, 2024

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.

circular17 avatar circular17 commented on May 30, 2024

I see. So you would like to be able to have a non zero paragraph spacing I suppose.

Alright then.

from bgrabitmap.

circular17 avatar circular17 commented on May 30, 2024

What about this signature?
function TBGRABitmap.TextSizeMultiline(sUTF8: string; AMaxWidth: single = EmptySingle; AParagraphSpacing: single = 0): TSize;

from bgrabitmap.

circular17 avatar circular17 commented on May 30, 2024

Done on dev branch

from bgrabitmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.