自己做的一个长篇文字转GIF图片的dll组件,请高手帮忙解决一下图片高度问题
由于文字大小、字体、换行,会导致图片高度动态变化。
现在的代码里高度一直不能准确。
代码如下。
使用了AAFONT GIFimage 控件
unit main;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AspTlb, dximg_TLB, Windows,StdVcl,SysUtils, Variants,Classes,
ExtCtrls, Graphics,AAFont, AACtrls,GIFImage;
type
Tdxasoimg = class(TASPObject, Idxasoimg)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function togif(const txt, fname, fsize, fcolor, bgcolor: WideString;
imgwidth: Integer): OleVariant; safecall;
end;
implementation
uses ComServ;
procedure Tdxasoimg.OnEndPage;
begin
inherited OnEndPage;
end;
procedure Tdxasoimg.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
//自动换行
function GetWrapText(const Line, BreakStr: string; BreakChars:
TSysCharSet; MaxCol: Integer): string;
const
QuoteChars = ['''', '"'];
var
Col, Pos: Integer;
LinePos, LineLen: Integer;
BreakLen, BreakPos: Integer;
QuoteChar, CurChar: Char;
ExistingBreak: Boolean;
DoubleCharBreak: Boolean;
begin
if MaxCol < 2 then MaxCol := 2;
Col := 1;
Pos := 1;
LinePos := 1;
BreakPos := 0;
QuoteChar := ' ';
ExistingBreak := False;
DoubleCharBreak := False;
LineLen := Length(Line);
BreakLen := Length(BreakStr);
Result := '';
while Pos <= LineLen do
begin
CurChar := Line[Pos];
if CurChar in LeadBytes then
begin
if Col >= MaxCol - 1 then
begin
DoubleCharBreak := True;
BreakPos := Pos - 1;
end;
Inc(Pos);
Inc(Col);
end
else if CurChar = BreakStr[1] then
begin
if QuoteChar = ' ' then
begin
ExistingBreak := CompareText(BreakStr, Copy(Line, Pos, BreakLen)) = 0;
if ExistingBreak then
begin
Inc(Pos, BreakLen - 1);
BreakPos := Pos;
end;
end
end
else if CurChar in BreakChars then
begin
if QuoteChar = ' ' then
BreakPos := Pos
end
else if CurChar in QuoteChars then
if CurChar = QuoteChar then
QuoteChar := ' '
else if QuoteChar = ' ' then
QuoteChar := CurChar;
Inc(Pos);
Inc(Col);
if (not (QuoteChar in QuoteChars) and (ExistingBreak or
((Col > MaxCol) and (BreakPos > LinePos)))) or DoubleCharBreak then
begin
Col := Pos - BreakPos;
Result := Result + Copy(Line, LinePos, BreakPos - LinePos + 1);
if not (CurChar in QuoteChars) then
while (Pos <= LineLen) and (Line[Pos] in BreakChars + [#13, #10]) do
Inc(Pos);
if not ExistingBreak and (Pos < LineLen) then
Result := Result + BreakStr;
Inc(BreakPos);
LinePos := BreakPos;
ExistingBreak := False;
DoubleCharBreak := False;
end;
end;
Result := Result + Copy(Line, LinePos, MaxInt);
end;