Forum > Windows

unicode ExtTextOut

(1/2) > >>

mobilevil:
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:
Try  ExtTextOutW instead of ExtTextOut and PWideChar(wstr) instead of PChar.

taazz:
unifunc.inc is been linked in the windows.pp unit (uses windows) of for a better declaration use something like

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

mobilevil:
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:
In the code you posted above ExtTextOutW overwrites ExtTextOut:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ExtTextOut(PaintBox1.Canvas.Handle,0,20,0, @therect, pchar(str),4,nil); ExtTextOutW(PaintBox1.Canvas.Handle,0,40,0, @therect, PWideChar(wstr),4, nil);
Did you try without  ExtTextOutW?

Navigation

[0] Message Index

[#] Next page

Go to full version