forked from dstd/HtmlayoutDelphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmLite.pas
803 lines (669 loc) · 25 KB
/
HtmLite.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
unit HtmLite;
(*
HTMLayout License terms could be found here http://www.terrainformatica.com/htmlayout/prices.whtm
SDK - http://www.terrainformatica.com/htmlayout/HTMLayoutSDK.zip
Delphi binding of HTMLayout published under LGPL. Visit https://github.com/Keksov/HtmlayoutDelphi
This file contains object wrapper for function from include\htmlite.h
Most accurate documentation could be found in include\htmlite.h itself
*)
interface
{$IFDEF USER_DEFINES_INC}{$I user_defines.inc}{$ENDIF}
uses Classes, SysUtils, Windows, Messages, Math, Forms
, HtmlBehaviorH
, HtmLiteH
, HtmPrintH
, HtmlTypes
, HtmlLayoutH
, HtmlLayoutDomH
, HtmlElement
, HtmlDisplay
;
type
TProxyWindow = class;
//-- THTMLRenderer
THTMLRendererDCType = ( dtNone, dtScreen, dtPrinter );
{***************************************************************************
* THTMLRenderer
***************************************************************************}
THTMLRenderer = class
protected
Fproxy : TProxyWindow;
Fscreen : THTMLiteBase;
Fprinter : THTMPrintExBase;
Fdc : HDC;
FdcType : THTMLRendererDCType;
FhPixelsPerInch : double;
FvPixelsPerInch : double;
Fhtml : string;
Fwidth : integer;
Fheight : integer;
FuseDeviceDPI : boolean;
//Froot : HELEMENT;
//kdpi : double;
private
function getHWin() : THandle;
procedure setDC( aDc : HDC );
procedure setHtml( const aHtml : string );
// function getScreen() : THTMLiteBase;
function getPrinter() : THTMPrintExBase;
function getIsScreen() : boolean;
protected
procedure doOnDocumentComplete(); virtual;
procedure measureDocument();
// function renderScreen( aX, aY : integer ) : boolean;
// function renderPrinter( aX, aY : integer ) : boolean;
public
constructor Create(); overload;
constructor Create( aDc : HDC ); overload;
destructor Destroy(); override;
procedure render( const aHtml : string; aX, aY : integer ); overload;
procedure render( aX, aY : integer ); overload;
procedure render( aDC : HDC; const aHtml : string; aX, aY : integer ); overload;
procedure render( aDC : HDC; aX, aY : integer ); overload;
function renderScaled( const aHtml : string; aX, aY : integer; aScaledWidth, aScaledHeight : double ) : boolean; overload;
function renderScaled( aX, aY : integer; aScaledWidth, aScaledHeight : double ) : boolean; overload;
function renderScaled( const aHtml : string; aX, aY : integer; aScaleFactor : double ) : boolean; overload;
function renderScaled( aX, aY : integer; aScaleFactor : double ) : boolean; overload;
function renderScaled( aDc : HDC; const aHtml : string; aScaledRect : TRect ) : boolean; overload;
function renderScaled( aDc : HDC; aScaledRect : TRect ) : boolean; overload;
function deviceX( aValue : double ) : integer;
function deviceY( aValue : double ) : integer;
protected
property hwin : THandle read getHWin;
// property screen : THTMLiteBase read getScreen;
property printer : THTMPrintExBase read getPrinter;
// function load( const aData : string; aBaseURI : widestring = '' ) : boolean; overload;
// function render( aDc : HDC; aX, aY, aSx, aSy : integer ) : boolean; override;
public
property dc : HDC read Fdc write setDC;
property html : string read Fhtml write setHtml;
property width : integer read Fwidth;
property height : integer read Fheight;
property useDeviceDPI : boolean read FuseDeviceDPI write FuseDeviceDPI;
property hPixelsPerInch : double read FhPixelsPerInch;
property vPixelsPerInch : double read FvPixelsPerInch;
property isScreen : boolean read getIsScreen;
end;
//-- TProxyWindow
{***************************************************************************
* TProxyWindow
***************************************************************************}
//TProxyWindow = class( TForm )
TProxyWindow = class
protected
Frenderer : THTMLRenderer;
Finstance : Cardinal;
Fhandle : HWND;
FwindowClass : TWndClass;
protected
// procedure wndProc( var aMsg : TMessage ); override;
procedure setCallback( aCallback : HTMLayoutNotify; aCallbackParam : Pointer );
function htmlCallback( uMsg: UINT; wParam : WPARAM; lParam : LPARAM ) : LRESULT;
class function getWindow() : TProxyWindow;
procedure setHtml( aRenderer : THTMLRenderer; const aHtml : string );
public
constructor Create();
end;
implementation
var
ProxyWindow : TProxyWindow;
FhScreenPPI : double;
FvScreenPPI : double;
{*******************************************************************************
* CalculateDisplayPixelPerInch
*******************************************************************************}
procedure CalculateDisplayPixelPerInch();
const
MMPerInch = 25.4;
var
screenDc : HDC;
hRes, vRes : integer;
hSize, vSize : integer;
begin
screenDc := getDC(0);
try
if ( not GetPrimaryMonitorTrueSize( hSize, vSize ) ) then
begin
FhScreenPPI := GetDeviceCaps( screenDc, LOGPIXELSX );
FvScreenPPI := GetDeviceCaps( screenDc, LOGPIXELSY );
exit;
end;
hRes := GetDeviceCaps( screenDc, HORZRES );
vRes := GetDeviceCaps( screenDc, VERTRES );
FhScreenPPI := ( MMPerInch * hRes / hSize );
FvScreenPPI := ( MMPerInch * vRes / vSize );
finally
ReleaseDC( 0, screenDc );
end;
end;
//-- TProxyWindow
{*******************************************************************************
* HtmlCallbackProxy
*******************************************************************************}
function HtmlCallbackProxy( uMsg: UINT; wParam: WPARAM; lParam: LPARAM; vParam: Pointer ): LRESULT; stdcall;
begin
if vParam <> nil then
Result := TProxyWindow( vParam ).HtmlCallback( uMsg, wParam, lParam )
else
Result := 0;
end;
{*******************************************************************************
* WindowProc
*******************************************************************************}
function WindowProc( hwnd : HWND; uMsg : UINT; wParam : WPARAM; lParam : LPARAM ) : LRESULT; stdcall;
var
handled : BOOL;
begin
//try
Result := HTMLayoutProcND( hwnd, uMsg, wParam,lParam, handled );
if handled then
exit;
case uMsg of
WM_DESTROY :
PostQuitMessage(0); // Otherwise app will continue to run
// WM_CREATE:
// HTMLayoutSetCallback( hwnd, HtmlCallbackProxy, ProxyWindow );
// else
// Result := DefWindowProc( hwnd, uMsg, wParam, lParam );
end;
Result := DefWindowProc( hwnd, uMsg, wParam, lParam );
end;
{*******************************************************************************
* Create
*******************************************************************************}
constructor TProxyWindow.Create();
begin
Finstance := GetModuleHandle( nil );
FwindowClass.style := CS_HREDRAW or CS_VREDRAW;
FwindowClass.hIcon := LoadIcon( 0, IDI_APPLICATION );
FwindowClass.hCursor := LoadCursor( 0, IDC_ARROW );
FwindowClass.hInstance := Finstance;
FwindowClass.lpfnWndProc := @WindowProc;
FwindowClass.hbrBackground := COLOR_BACKGROUND;
FwindowClass.lpszClassName := 'Example';
// Ðåãèñòðèðóåì êëàññ îêíà
Windows.RegisterClass( FwindowClass );
// Ñîçäà¸ì îêíî
Fhandle := CreateWindow( 'Example', 'Ïðèìåð ñîçäàíèÿ îêíà áåç VCL'
, WS_OVERLAPPEDWINDOW //WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX
, 100, 100 // position
, 320, 200 // size
, 0, 0
, Finstance
, nil
);
// Ïîêàçûâàåì îêíî
//ShowWindow( Fhandle, SW_SHOW );
HTMLayoutSetCallback( Fhandle, HtmlCallbackProxy, self );
// FhScreenDPI := DisplayHorzPixelsPerInch();
// FvScreenDPI := PixelsPerInchVertDisplay( GetDC(0), true );
// UpdateWindow( FwindowClass );
end;
{*******************************************************************************
* TProxyWindow
*******************************************************************************}
class function TProxyWindow.getWindow() : TProxyWindow;
begin
if ( ProxyWindow = nil ) then
begin
// Application.CreateForm( TProxyWindow, ProxyWindow );
ProxyWindow := TProxyWindow.Create();
// ProxyWindow.Height := 100;
// ProxyWindow.Width := 100;
// ProxyWindow.Visible := true;
// ProxyWindow.Show();
Application.ProcessMessages();
end;
Result := ProxyWindow;
end;
{*******************************************************************************
* WndProc
*******************************************************************************}
(*procedure TProxyWindow.WndProc( var aMsg : TMessage );
var
handled : BOOL;
res : LRESULT;
begin
//try
res := HTMLayoutProcND( Handle, aMsg.Msg, aMsg.WParam, aMsg.LParam, handled );
if handled then
begin
aMsg.Result := res;
exit;
end;
case aMsg.Msg of
WM_CREATE:
//SetCallback( HtmlCallbackProxy, self );
end;
inherited;
{except
on e : Exception do
begin
if ( e <> nil ) then if ( e <> nil ) then;
if ( Message.Msg <> 0 ) then if ( Message.Msg <> 0 ) then;
end;
end;}
end;*)
{*******************************************************************************
* SetCallback
*******************************************************************************}
procedure TProxyWindow.SetCallback( aCallback : HTMLayoutNotify; aCallbackParam : Pointer );
begin
HTMLayoutSetCallback( Fhandle, aCallback, aCallbackParam );
end;
{*******************************************************************************
* HtmlCallback
*******************************************************************************}
function TProxyWindow.HtmlCallback( uMsg: UINT; wParam : WPARAM; lParam : LPARAM ) : LRESULT;
begin
Result := 0;
assert( Frenderer <> nil );
case PNMHDR( lParam ).code of
HLN_DOCUMENT_COMPLETE :
Frenderer.doOnDocumentComplete();
end;
{case PNMHDR( lParam ).code of
HLN_CREATE_CONTROL :
Result := doOnCreateControl( PNMHL_CREATE_CONTROL( lParam ) );
HLN_LOAD_DATA:
Result := doOnLoadData( PNMHL_LOAD_DATA( lParam ) );
HLN_CONTROL_CREATED :
doOnControlCreated();
HLN_DATA_LOADED :
Result := doOnDataLoaded( PNMHL_DATA_LOADED( lParam ) );
HLN_DOCUMENT_COMPLETE :
doOnDocumentComplete();
HLN_UPDATE_UI :
doOnUpdateUI();
HLN_DESTROY_CONTROL :
Result := doOnDestroyControl( PNMHL_DESTROY_CONTROL( lParam ) );
HLN_ATTACH_BEHAVIOR :
Result := doOnAttachBehavior( PNMHL_ATTACH_BEHAVIOR( lParam ) );
HLN_BEHAVIOR_CHANGED :
Result := doOnBehaviorChanged( PNMHL_BEHAVIOR_CHANGED( lParam ) );
HLN_DIALOG_CREATED :
Result := doOnDialogCreated();
HLN_DIALOG_CLOSE_RQ :
Result := doOnDialogCloseRequest( PNMHL_DIALOG_CLOSE_RQ( lParam ) );
HLN_DOCUMENT_LOADED :
Result := doOnDocumentLoaded();
end;}
end;
{*******************************************************************************
* setHtml
*******************************************************************************}
procedure TProxyWindow.setHtml( aRenderer : THTMLRenderer; const aHtml : string );
var
res : boolean;
begin
Frenderer := aRenderer;
res := HTMLayoutLoadHtml( Fhandle, LPCBYTE( @aHtml[1] ), Length( aHtml ) );
assert( res );
end;
//-- THTMLRenderer
{*******************************************************************************
* Create
*******************************************************************************}
constructor THTMLRenderer.Create();
begin
Fscreen := nil;
FdcType := dtNone;
FuseDeviceDPI := false;
Fproxy := TProxyWindow.getWindow();
end;
{*******************************************************************************
* Create
*******************************************************************************}
constructor THTMLRenderer.Create( aDc : HDC );
begin
Create();
dc := aDc;
end;
{*******************************************************************************
* Destroy
*******************************************************************************}
destructor THTMLRenderer.Destroy();
begin
FreeAndNil( Fscreen );
inherited;
end;
{*******************************************************************************
* getIsScreen
*******************************************************************************}
function THTMLRenderer.getIsScreen() : boolean;
begin
Result := ( FdcType = dtScreen );
end;
{*******************************************************************************
* getHWin
*******************************************************************************}
function THTMLRenderer.getHWin() : THandle;
begin
Result := Fproxy.Fhandle;
end;
{*******************************************************************************
* setDC
*******************************************************************************}
procedure THTMLRenderer.setDC( aDc : HDC );
var
tech : integer;
begin
if ( Fdc = aDc ) then
exit;
tech := GetDeviceCaps( aDc, TECHNOLOGY );
case tech of
DT_PLOTTER :
FdcType := dtPrinter; // Vector plotter
DT_RASDISPLAY :
FdcType := dtScreen; // Raster display
DT_RASPRINTER :
FdcType := dtPrinter; // Raster printer
DT_RASCAMERA :
FdcType := dtPrinter; // Raster camera
DT_CHARSTREAM :
FdcType := dtPrinter; // Character stream
DT_METAFILE :
FdcType := dtPrinter; //Metafile
DT_DISPFILE :
FdcType := dtPrinter; // Display file
end;
Fdc := aDc;
FhPixelsPerInch := GetDeviceCaps( aDc, LOGPIXELSX );
FvPixelsPerInch := GetDeviceCaps( aDc, LOGPIXELSY );
end;
{*******************************************************************************
* setHtml
*******************************************************************************}
procedure THTMLRenderer.setHtml( const aHtml : string );
begin
if ( Fhtml = aHtml ) then
exit;
Fhtml := aHtml;
Fproxy.setHtml( self, aHtml );
end;
{*******************************************************************************
* doOnDocumentComplete
*******************************************************************************}
procedure THTMLRenderer.doOnDocumentComplete();
begin
measureDocument();
end;
{*******************************************************************************
* measureDocument
*******************************************************************************}
procedure THTMLRenderer.measureDocument();
var
res : HLDOM_RESULT;
shim : THtmlShim;
minW : integer;
begin
shim := THtmlShim.get( hwin );
if ( not HTMLayoutCommitUpdates( hwin ) ) then
begin
assert( false );
exit;
end;
res := HTMLayoutGetElementIntrinsicWidths( shim.handler, minW, Fwidth );
assert( res = HLDOM_OK );
res := HTMLayoutGetElementIntrinsicHeight( shim.handler, Fwidth, Fheight );
assert( res = HLDOM_OK );
end;
{*******************************************************************************
* render
*******************************************************************************}
procedure THTMLRenderer.render( aDC : HDC; const aHtml : string; aX, aY : integer );
begin
dc := aDC;
html := aHtml;
render( aX, aY );
end;
{*******************************************************************************
* render
*******************************************************************************}
procedure THTMLRenderer.render( aDC : HDC; aX, aY : integer );
begin
dc := aDC;
render( aX, aY );
end;
{*******************************************************************************
* render
*******************************************************************************}
procedure THTMLRenderer.render( const aHtml : string; aX, aY : integer );
begin
html := aHtml;
render( aX, aY );
end;
{*******************************************************************************
* render
*******************************************************************************}
procedure THTMLRenderer.render( aX, aY : integer );
begin
renderScaled( aX, aY, 1 );
{ case FdcType of
dtScreen :
renderScreen( aX, aY );
dtPrinter :
renderPrinter( aX, aY );
end;}
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( const aHtml : string; aX, aY : integer; aScaleFactor : double ) : boolean;
begin
html := aHtml;
Result := renderScaled( aX, aY, ceil( Fwidth * aScaleFactor ), ceil( Fheight * aScaleFactor ) );
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( aX, aY : integer; aScaleFactor : double ) : boolean;
begin
Result := renderScaled( aX, aY, Fwidth * aScaleFactor, Fheight * aScaleFactor );
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( const aHtml : string; aX, aY : integer; aScaledWidth, aScaledHeight : double ) : boolean;
begin
html := aHtml;
Result := renderScaled( aX, aY, aScaledWidth, aScaledHeight );
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( aDc : HDC; const aHtml : string; aScaledRect : TRect ) : boolean;
begin
dc := aDc;
html := aHtml;
Result := renderScaled( aScaledRect.Left, aScaledRect.Top, aScaledRect.Right - aScaledRect.Left, aScaledRect.Bottom - aScaledRect.Top );
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( aDc : HDC; aScaledRect : TRect ) : boolean;
begin
dc := aDc;
Result := renderScaled( aScaledRect.Left, aScaledRect.Top, aScaledRect.Right - aScaledRect.Left, aScaledRect.Bottom - aScaledRect.Top );
end;
{***************************************************************************
* deviceX
***************************************************************************}
function THTMLRenderer.deviceX( aValue : double ) : integer;
begin
Result := Round( aValue * FvPixelsPerInch / FhScreenPPI );
end;
{***************************************************************************
* deviceY
***************************************************************************}
function THTMLRenderer.deviceY( aValue : double ) : integer;
begin
Result := Round( aValue * FhPixelsPerInch / FvScreenPPI )
end;
{*******************************************************************************
* renderScaled
*******************************************************************************}
function THTMLRenderer.renderScaled( aX, aY : integer; aScaledWidth, aScaledHeight : double ) : boolean;
var
pt : TPoint;
kx : double;
baseURI : widestring;
printWidth : double;
printHeight : double;
scaledWidth : double;
{***************************************************************************
* adjustViewport
***************************************************************************}
function adjustViewport() : boolean;
begin
Result := GetViewportOrgEx( Fdc, pt );
if ( not Result ) then
exit;
aX := aX + pt.X;
aY := aY + pt.Y;
Result := SetViewportOrgEx( Fdc, aX, aY, nil );
end;
{***************************************************************************
* vr
***************************************************************************}
function vr( aValue : double ) : integer;
begin
if ( FuseDeviceDPI and not isScreen ) then
Result := deviceY( aValue )
else
Result := Round( aValue );
end;
{***************************************************************************
* hr
***************************************************************************}
function hr( aValue : double ) : integer;
begin
if ( FuseDeviceDPI and not isScreen ) then
Result := deviceX( aValue )
else
Result := Round( aValue );
end;
begin
Result := adjustViewport();
if ( not Result ) then
exit;
try
baseURI := 'http://';
Result := printer.load( LPCBYTE( @Fhtml[1] ), Length( Fhtml ), LPCWSTR( baseURI ) );
if ( not Result ) then
exit;
kx := aScaledWidth / Fwidth;
scaledWidth := Fwidth + 100;
printWidth := Fwidth * kx;
printHeight := Fheight * kx;
printer.measure( Fdc, scaledWidth, hr( printWidth ), vr( printHeight ) );
if ( not Result ) then
exit;
Result := printer.render( Fdc, hr(aX), vr(aY), 0 );
if ( not Result ) then
exit;
finally
SetViewportOrgEx( Fdc, pt.x, pt.y, nil );
end;
end;
{*******************************************************************************
* getScreen
*******************************************************************************}
{function THTMLRenderer.getScreen() : THTMLiteBase;
begin
if ( not Assigned( Fscreen ) ) then
begin
Fscreen := THTMLiteBase.Create( 'screen' );
end;
Result := Fscreen;
end;}
{*******************************************************************************
* getPrinter
*******************************************************************************}
function THTMLRenderer.getPrinter() : THTMPrintExBase;
begin
if ( not Assigned( Fprinter ) ) then
begin
Fprinter := THTMPrintExBase.Create( 'print' );
end;
Result := Fprinter;
end;
{*******************************************************************************
* renderScreen
*******************************************************************************}
{function THTMLRenderer.renderScreen( aX, aY : integer ) : boolean;
var
pt : TPoint;
baseURI : widestring;
begin
Result := SetViewportOrgEx( Fdc, aX, aY, @pt );
if ( not Result ) then
exit;
try
baseURI := 'http://';
Result := screen.load( LPCBYTE( @Fhtml[1] ), Length( Fhtml ), LPCWSTR( baseURI ) );
if ( not Result ) then
exit;
// Fwidth and Fheight calculated in measureDocument
Result := screen.measure( Fwidth, Fheight );
if ( not Result ) then
exit;
Result := screen.render( Fdc, aX, aY, aX + Fwidth, aY + Fheight );
if ( not Result ) then
exit;
finally
SetViewportOrgEx( Fdc, pt.x, pt.y, nil );
end;
end;}
{*******************************************************************************
* renderPrinter
*******************************************************************************}
(*function THTMLRenderer.renderPrinter( aX, aY : integer ) : boolean;
var
pt : TPoint;
baseURI : widestring;
printWidth : integer;
printHeight : integer;
scaledWidth : integer;
{***************************************************************************
* vr
***************************************************************************}
function vr( aValue : integer ) : integer;
begin
Result := Round( aValue * FvPixelsPerInch / 96 );
end;
{***************************************************************************
* hr
***************************************************************************}
function hr( aValue : integer ) : integer;
begin
Result := Round( aValue * FhPixelsPerInch / 96 );
end;
begin
Result := SetViewportOrgEx( Fdc, hr( aX ), vr( aY ), @pt );
if ( not Result ) then
exit;
try
baseURI := 'http://';
Result := printer.load( LPCBYTE( @Fhtml[1] ), Length( Fhtml ), LPCWSTR( baseURI ) );
if ( not Result ) then
exit;
scaledWidth := Fwidth + GetSystemMetrics( SM_CXVSCROLL );
printWidth := vr( scaledWidth ) + vr( GetSystemMetrics( SM_CXVSCROLL ) );
printHeight := hr( Fheight ) + hr( GetSystemMetrics( SM_CYHSCROLL ) );
printer.measure( Fdc, scaledWidth, printWidth, printHeight );
if ( not Result ) then
exit;
Result := printer.render( Fdc, hr( aX ), vr( aY ), 0 );
if ( not Result ) then
exit;
finally
SetViewportOrgEx( Fdc, pt.x, pt.y, nil );
end;
end;*)
INITIALIZATION
ProxyWindow := nil;
CalculateDisplayPixelPerInch();
FINALIZATION
FreeAndNil( ProxyWindow );
end.