我是新来的unicode,所以我希望任何人都可以帮助我。我希望将unicode编写为PDF,现在我需要文本格式的unicode文本的宽度和高度。对于AnsiString我有这个功能在PDF类:使用unicode文本的PDF和TextWidth/TextHeight
function PDFClass.TextWidth(Text: AnsiString): Single;
var
i: integer;
ch: AnsiChar;
tmpWidth: Single;
chv: Integer;
begin
Result := 0;
for I := 1 to Length(Text) do
begin
ch := Text[i];
chv := CurrentFontObj.GetCharWidth(Text, I);
tmpWidth := chv * CurrentFontObj.Size/1000;
if FHorizontalScaling <> 100 then
tmpWidth := tmpWidth * FHorizontalScaling/100;
if tmpWidth > 0 then
tmpWidth := tmpWidth + FCharSpace
else
tmpWidth := 0;
if (ch = ' ') and (FWordSpace > 0) and (i <> Length(Text)) then
tmpWidth := tmpWidth + FWordSpace;
Result := Result + tmpWidth;
end;
Result := (Result/DocScale);
end;
function PDFClass.TextHeight(Text: AnsiString): Real;
begin
Result := CurrentFontObj.Size * CurrentFontObj.Ascent/1000;
end;
任何人都可以帮我使用此功能的Unicode文本?我在带有UnicodeString的C++ Builder 2009中使用这个组件。
CurrentFontObj是从类PDFFontObj
PDFFontObj = class(TObject)
private
Name: AnsiString;
Size: Single;
ArrIndex: Integer;
Saved: boolean;
OldName: AnsiString;
Ascent: Integer;
FActive: boolean;
IsUsed: boolean;
UniLen: Integer;
FontLen: Integer;
IsUnicode: boolean;
IsVertical: boolean;
OrdinalName: AnsiString;
IsStandard: boolean;
FontStyle: TFontStyles;
FontCharset: TFontCharset;
IsMonospaced: boolean;
OutTextM: OUTLINETEXTMETRIC;
ABCArray: array[0..255] of ABC;
Symbols: array of CDescript;
UnicodeTable: array of IndexedChar;
SymbolTable: array[32..255] of boolean;
function GetCharWidth(AText: AnsiString; APos: integer): integer;
function GetCodeByID(ID: Word): Word;
procedure CopyFontFetures(InFnt: PDFFontObj);
procedure GetFontFeatures;
procedure ParseFontName;
procedure ClearTables;
end;
function PDFFontObj.GetCharWidth(AText: AnsiString; APos: integer): integer;
var
ChCode: Byte;
begin
ChCode := Ord(AText[APos]);
if not IsMonospaced then
Result := ABCArray[ChCode].abcA + Integer(ABCArray[ChCode].abcB) + ABCArray[ChCode].abcC
else
Result := ABCArray[0].abcA + Integer(ABCArray[0].abcB) + ABCArray[0].abcC;
end;
你的问题是很难理解的,请注明哪些帮助,你需要用这个代码。它不会编译?你想支持字体包含的所有Unicode字形吗?还是其他什么东西? – mghie 2010-04-15 06:38:59
我想连续写3个文本,每个文本的颜色都不一样。为此,我需要每个字符串(文本)的像素宽度。对于AnsiString: int width = PDF-> CurrentPage-> TextWidth(_ansi_text_); 但我需要一个unicode文本的TextWidth,如: int width = PDF-> CurrentPage-> TextWidthUnicode(_unicode_text_with_chinese_signs_); TextWidthUnicode()(和高度)是我需要的。 我的问题是,“如何获得unicode文本的像素宽度?” :) – Katsumi 2010-04-15 07:16:44