Recent

Author Topic: unicode ExtTextOut  (Read 5712 times)

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
unicode ExtTextOut
« 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;     

balazsszekely

  • Guest
Re: unicode ExtTextOut
« Reply #1 on: April 03, 2018, 09:55:43 am »
Try  ExtTextOutW instead of ExtTextOut and PWideChar(wstr) instead of PChar.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: unicode ExtTextOut
« Reply #2 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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: unicode ExtTextOut
« Reply #3 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.

balazsszekely

  • Guest
Re: unicode ExtTextOut
« Reply #4 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?

mobilevil

  • Jr. Member
  • **
  • Posts: 69
    • http://www.kachun.com
Re: unicode ExtTextOut
« Reply #5 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.
« Last Edit: April 03, 2018, 10:55:24 am by mobilevil »

balazsszekely

  • Guest
Re: unicode ExtTextOut
« Reply #6 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