Lazarus

Free Pascal => Windows => Topic started by: mobilevil on April 03, 2018, 09:51:17 am

Title: unicode ExtTextOut
Post by: mobilevil on April 03, 2018, 09:51:17 am
Hello,
I am trying to fix a printing library's unicode issue.
it is using ExtTextOut to print a string with character #251 with font winglings. but it is printing blank.
I tested with Canvas.TextOut and found that the print out is right if I change the text from String to WideString.

so I go back to the library and found that by doing the same String to WideString change, it still doesn't work.

Seems I need ExtTextOutW, but how can I access it in lazarus? looks like it is defined in unifunc.inc.

procedure TForm1.Button1Click(Sender: TObject);
var
  wstr:widestring;
  str:string;
  therect:TRect;
begin
  wstr:='AB'#251#252;
  str:='AB'#251#252;
  paintbox1.Canvas.Font.Name:='WingDings';
  PaintBox1.Canvas.TextOut(0,0, wstr);

  therect:=PaintBox1.Canvas.ClipRect;
  ExtTextOut(PaintBox1.Canvas.Handle,0,20,0, @therect, pchar(str),4,nil);

end;     
Title: Re: unicode ExtTextOut
Post by: GetMem on April 03, 2018, 09:55:43 am
Try  ExtTextOutW instead of ExtTextOut and PWideChar(wstr) instead of PChar.
Title: Re: unicode ExtTextOut
Post by: taazz on April 03, 2018, 10:06:25 am
unifunc.inc is been linked in the windows.pp unit (uses windows) of for a better declaration use something like
Code: Pascal  [Select][+][-]
  1. function ExtTextOutW(aDC: HDC; aX, aY: Integer; aOptions: UINT; aRect: LPRECT; aText: LPCWSTR; aCount: UINT; aDx: LPINT): BOOL; external 'gdi32.dll' name 'ExtTextOutW';
in any of your units and you are good to go. The funny thing is that fpc comes with jwawindows unit which has a proper declaration although a bit of questionable implementation.
Title: Re: unicode ExtTextOut
Post by: mobilevil on April 03, 2018, 10:34:47 am
thanks you guys are faster then the printing library's support lol
and by using the windows unit, ExtTextOut is able to print the characters with string!? :o

looks like by using the windows unit, the windows API is handling the ExtTextOut, but without the windows unit, it is handled by lazarus/fpc's own implementation?


unit Unit1;

{$mode objfpc}{$H+}
{$i C:\fpcupdeluxe\fpcsrc\rtl\win\wininc\unifun.inc}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  LCLType, LCLIntf
  , Windows
  ;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    PaintBox1: TPaintBox;
    procedure Button1Click(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  wstr:widestring;
  str:string;
  therect:TRect;
begin
  wstr:='AB'#251#252;
  str:='AB'#251#252;
  paintbox1.Canvas.Font.Name:='WingDings';
  PaintBox1.Canvas.TextOut(0,0, wstr);

  therect:=PaintBox1.Canvas.ClipRect;
  ExtTextOut(PaintBox1.Canvas.Handle,0,20,0, @therect, pchar(str),4,nil);
  ExtTextOutW(PaintBox1.Canvas.Handle,0,40,0, @therect, PWideChar(wstr),4, nil);

end;

end.
Title: Re: unicode ExtTextOut
Post by: GetMem on April 03, 2018, 10:43:55 am
In the code you posted above ExtTextOutW overwrites ExtTextOut:
Code: Pascal  [Select][+][-]
  1.  ExtTextOut(PaintBox1.Canvas.Handle,0,20,0, @therect, pchar(str),4,nil);
  2.  ExtTextOutW(PaintBox1.Canvas.Handle,0,40,0, @therect, PWideChar(wstr),4, nil);

Did you try without  ExtTextOutW?
Title: Re: unicode ExtTextOut
Post by: mobilevil on April 03, 2018, 10:50:47 am
In the code you posted above ExtTextOutW overwrites ExtTextOut:
Code: Pascal  [Select][+][-]
  1.  ExtTextOut(PaintBox1.Canvas.Handle,0,20,0, @therect, pchar(str),4,nil);
  2.  ExtTextOutW(PaintBox1.Canvas.Handle,0,40,0, @therect, PWideChar(wstr),4, nil);

Did you try without  ExtTextOutW?

no they don't overwrite the drawing. note they prints in different Y position.
and yes I tried to remove the ExtTextOutW call, it is really the use of windows unit causing the different.
with windows unit, ExtTextOut prints the tick fine.
without windows unit, ExtTextOut cannot print the tick.
Title: Re: unicode ExtTextOut
Post by: GetMem on April 03, 2018, 10:53:31 am
Quote
no they don't overwrite the drawing. note they prints in different Y position.
True. I did not notice the different y position.

Quote
and yes I tried to remove the ExtTextOutW call, it is really the use of windows unit causing the different.
with windows unit, ExtTextOut prints the tick find.
without windows unit, ExtTextOut cannot print the tick.
OK. Thanks for the feedback.
TinyPortal © 2005-2018