EldoS | Feel safer!

Software components for data protection, secure storage and transfer

PDF WidgetProps truncate text

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#13715
Posted: 06/18/2010 17:31:14
by L S (Standard support level)
Joined: 04/27/2010
Posts: 6

Hi

The Widgets Header, AlgorithmInfo and SignerInfo are truncated to 10 characters. I have tried both with and without AutoSize and AutoText, but the strings are truncated either way (se attached sample). Any ideas?

Sig.WidgetProps.AutoSize := false;
Sig.WidgetProps.AutoPos := false;
Sig.WidgetProps.Height := 100;
Sig.WidgetProps.Width := 250;
Sig.WidgetProps.OffsetX := 100;
Sig.WidgetProps.OffsetY := 400;
Sig.WidgetProps.AutoText := false;
Sig.WidgetProps.Header := '12345678901234567890';
Sig.WidgetProps.AlgorithmInfo := '12345678901234567890'; Sig.WidgetProps.SignerInfo := '12345678901234567890';




LS
#13716
Posted: 06/19/2010 07:12:26
by Dmytro Bogatskyy (EldoS Corp.)

Quote
Sig.WidgetProps.AutoSize := false;
Sig.WidgetProps.AutoPos := false;
Sig.WidgetProps.Height := 100;
Sig.WidgetProps.Width := 250;
Sig.WidgetProps.OffsetX := 100;
Sig.WidgetProps.OffsetY := 400;
Sig.WidgetProps.AutoText := false;
Sig.WidgetProps.Header := '12345678901234567890';
Sig.WidgetProps.AlgorithmInfo := '12345678901234567890'; Sig.WidgetProps.SignerInfo := '12345678901234567890';

Did you set any other property too?
With code above I get a stretched text see the first image (it is ok as AutoFontSize property is true by default).
If to set Sig.WidgetProps.AutoFontSize property to false the signature will look like on second image. And it seems to be ok.
What SecureBlackbox version are you using? Also it could be a problem with a document, could you please post it here or to helpdesk.


#13718
Posted: 06/19/2010 17:47:46
by L S (Standard support level)
Joined: 04/27/2010
Posts: 6

I copied the sample code from TinySigner MainForm and also set:

Code
SimpleFont := TElPDFSimpleFont.Create;
SimpleFont.BaseFont := 'Helvetica';
Sig.WidgetProps.AddFont(SimpleFont);
SimpleFont.EncodingObject := TElPDFEncoding.Create;
Sig.WidgetProps.AddFontObject(SimpleFont.EncodingObject);
SimpleFont.EncodingObject.BaseEncoding := 'WinAnsiEncoding';
Sig.WidgetProps.OnConvertStringToAnsi := UTF8ToWin1252;


And I also set text like this:
Sig.WidgetProps.Header := MultiByteToUTF8('12345678901234567890');

I also copied the UTF8ToWin1252 and MultiByteToUTF8 from TinySigner MainForm, and it seems that this functions are causing my problem:

Code
function MultiByteToUTF8(const Str: string): string;
var
  WStr: WideString;
  Size, Sz: integer;
begin
  Result := '';
  Size := Length(Str);
  if Size <= 0 then
    Exit;

  SetLength(WStr, Size);
  Sz := MultiByteToWideChar(CP_ACP, 0, @Str[1], Size, @WStr[1], Size);
  SetLength(WStr, Sz);
  Size := Length(WStr);
  if Size <= 0 then
    Exit;

  Sz := WideCharToMultiByte(CP_UTF8, 0, @WStr[1], Size, nil, 0, nil, nil);
  SetLength(Result, Sz);
  Sz := WideCharToMultiByte(CP_UTF8, 0, @WStr[1], Size, @Result[1], Length(Result),
    nil, nil);
  SetLength(Result, Sz);
end;

function TPDFSignerClass.UTF8ToWin1252(Sender: TObject; const Str: string): ByteArray;
var
  WStr: WideString;
  Size, Sz: integer;
begin
  Result := nil;
  Size := Length(Str);
  if Size <= 0 then
    Exit;

  SetLength(WStr, Size);
  Sz := MultiByteToWideChar(CP_UTF8, 0, @Str[1], Size, @WStr[1], Size);
  SetLength(WStr, Sz);
  Size := Length(WStr);
  if Size <= 0 then
    Exit;

  Sz := WideCharToMultiByte(1252, 0, @WStr[1], Size, nil, 0, nil, nil) + 1;
  SetLength(Result, Sz);
  Sz := WideCharToMultiByte(1252, 0, @WStr[1], Size, @Result[0], Length(Result),
    nil, nil);
  SetLength(Result, Sz);
end;


LS
#13719
Posted: 06/20/2010 06:16:17
by Dmytro Bogatskyy (EldoS Corp.)

Are you using delphi 2009/2010?
If yes then a problem in unicode strings.
You don't need to use MultiByteToUTF8 function, simply assign:
Sig.WidgetProps.Header := '12345678901234567890';
And UTF8ToWin1252 replace with a method:
Code
function TPDFSignerClass.UTF16ToWin1252(Sender: TObject; const WStr: string): ByteArray;
var
  Size, Sz: integer;
begin
  Result := nil;
  Size := Length(WStr);
  if Size <= 0 then
    Exit;

  Sz := WideCharToMultiByte(1252, 0, @WStr[1], Size, nil, 0, nil, nil) + 1;
SetLength(Result, Sz);
  Sz := WideCharToMultiByte(1252, 0, @WStr[1], Size, @Result[0], Length(Result),
nil, nil);
  SetLength(Result, Sz);
end;

I'll fix samples accordingly. Thank you.
#13721
Posted: 06/20/2010 15:15:10
by L S (Standard support level)
Joined: 04/27/2010
Posts: 6

Perfect :-)

Yes, I am using Delphi 2010


LS
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 1906 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!