Inc(J,TempExtent.CX); if J > MaxExtent then begin J := TempExtent.CX; Insert(#13#10,TempStr,I+X); {Soft return} Inc(X,2); end; end; end; end; Texts.Text := TempStr; end; tcSelfAdapt: begin Texts.Text := AText; if Direction = tdVertChinese then begin //J := 0; //X := Length(WideString(Texts[0])); //TempStr := WideString(Texts[0]); TempStr := ''''''''; for I := 0 to Texts.Count - 1 do begin if Length(TempStr) < Length(WideString(Texts[I])) then TempStr := WideString(Texts[I]); //if X < Length(WideString(Texts[I])) then //begin // X := Length(WideString(Texts[I])); // J := I; //end; end; //TempStr := WideString(Texts[J]); if Length(TempStr) <> 0 then begin J := Floor(MaxExtent / Length(TempStr)); for I := ACanvas.Font.Size-1 downto 5 do begin Windows.GetTextMetrics(ACanvas.Handle,TextMetric); if TextMetric.tmHeight < J then Break else ACanvas.Font.Size := I; end; // if -ACanvas.Font.Height > J then // SetLogicFont(0,0); // else end; end else begin J := 0; S := ''''''''; for I := 0 to Texts.Count - 1 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(Texts[I]), Length(Texts[I]), TempExtent); if J < TempExtent.CX then begin S := Texts[I]; J := TempExtent.CX; end; end;
{for I := ACanvas.Font.Size-1 downto 5 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(S), Length(S), TempExtent); if TempExtent.CX < MaxExtent then Break else ACanvas.Font.Size := I; end;} Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(S), Length(S), TempExtent); if TempExtent.CX > MaxExtent then for I := -ACanvas.Font.Height downto 1 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(S), Length(S), TempExtent); if TempExtent.CX < MaxExtent then Break else SetLogicFont(I,0); end;
end; end; tcCalcRect: begin Texts.Text := AText; case Direction of tdVertChinese: begin TempStr := WideString(Texts[0]); for I := 1 to Texts.Count - 1 do begin if Length(TempStr) < Length(WideString(Texts[I])) then TempStr := WideString(Texts[I]); end; Windows.GetTextMetrics(ACanvas.Handle,TextMetric); ARect.Bottom := ARect.Top + Length(TempStr) * TextMetric.tmHeight; end; 0:{Horizontal} begin J := 0; for I := 0 to Texts.Count - 1 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(Texts[I]), Length(Texts[I]), TempExtent); if J < TempExtent.CX then J := TempExtent.CX; end; ARect.Right := ARect.Left + J; end; 1..45,-45..-1: begin J := 0; for I := 0 to Texts.Count - 1 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(Texts[I]), Length(Texts[I]), TempExtent); if J < TempExtent.CX then J := TempExtent.CX; end; ARect.Right := ARect.Left + Ceil(J*Scaler); end; 46..90,-90..-46: begin J := 0; for I := 0 to Texts.Count - 1 do begin Windows.GetTextExtentPoint32(ACanvas.Handle, PChar(Texts[I]), Length(Texts[I]), TempExtent); if J < TempExtent.CX then J := TempExtent.CX; end; ARect.Bottom := ARect.Top + Ceil(J*Scaler); end; end; end; else Texts.Text := AText; end;
{Initialize the origin point} case Direction of tdVertChinese: begin Windows.GetTextMetrics(ACanvas.Handle,TextMetric); Interval := TextMetric.tmMaxCharWidth + Windows.GetTextCharacterExtra(ACanvas.Handle); J := Interval * Texts.Count;
if taLeft in Aligns then X := ARect.Left + J - Interval else if taHorzCenter in Aligns then X := (ARect.Right + ARect.Left + J) shr 1 - Interval else {if taRight in Aligns} X := ARect.Right - Interval;
Y := ARect.Top + 2; end; 0:{Horizontal} begin Windows.GetTextMetrics(ACanvas.Handle,TextMetric); Interval := TextMetric.tmHeight;// + TextMetric.tmExternalLeading;
J := Interval * Texts.Count;
X := ARect.Left + 2;
if taBottom in Aligns then Y := ARect.Bottom - J else if taVertCenter in Aligns then Y := (ARect.Bottom + ARect.Top - J) shr 1 else {if taTop in Aligns then} Y := ARect.Top + 2;
if taBottom in Aligns then Y := ARect.Bottom - J else if taVertCenter in Aligns then Y := (ARect.Bottom + ARect.Top - J) shr 1 else {if taTop in Aligns then} Y := ARect.Top + 2;
if taRight in Aligns then X := ARect.Right - J else if taHorzCenter in Aligns then X := (ARect.Right + ARect.Left - J) shr 1 else {if taLeft in Aligns} X := ARect.Left +