mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-21 23:19:29 +02:00
cocoa-printing: Fixes issues which prevented the printing from going through, now an ellipse can be printed with pen and brush
git-svn-id: trunk@48752 -
This commit is contained in:
parent
f7f65c5305
commit
24779bff6c
@ -137,8 +137,13 @@ end;
|
||||
{ TCanvasOperation_Pen_Brush }
|
||||
|
||||
procedure TCanvasOperation_Pen_Brush.DrawTo(const ADest: TCocoaContext);
|
||||
var
|
||||
lCocoaBrush: TCocoaBrush;
|
||||
begin
|
||||
inherited DrawTo(ADest);
|
||||
lCocoaBrush := TCocoaBrush.Create(Brush_Color, Brush_Style, Brush_Pattern);
|
||||
lCocoaBrush.Apply(ADest);
|
||||
lCocoaBrush.Free;
|
||||
end;
|
||||
|
||||
{ TCanvasOperation_Ellipse }
|
||||
@ -431,6 +436,10 @@ begin
|
||||
Changing;
|
||||
RequiredState([csHandleValid, csPenValid, csBrushValid]);
|
||||
lEllipse := TCanvasOperation_Ellipse.Create;
|
||||
lEllipse.X1 := X1;
|
||||
lEllipse.Y1 := Y1;
|
||||
lEllipse.X2 := X2;
|
||||
lEllipse.Y2 := Y2;
|
||||
SetPenAndBrush(lEllipse);
|
||||
FCurRecording.Add(lEllipse);
|
||||
Changed;
|
||||
|
@ -12,8 +12,11 @@ const
|
||||
|
||||
function TCocoaPrinterView.initWithFrame(frameRect: NSRect): id;
|
||||
begin
|
||||
PageMin := 1;
|
||||
PageMax := 1;
|
||||
PageFrom := 1;
|
||||
PageTo := 1;
|
||||
Result:=inherited initWithFrame(frameRect);
|
||||
//Size := NSMakeSize(200, 200);
|
||||
//Image := NSImage.alloc.initWithSize(Size);
|
||||
end;
|
||||
|
||||
@ -26,6 +29,7 @@ end;
|
||||
procedure TCocoaPrinterView.drawRect(dirtyRect: NSRect);
|
||||
var
|
||||
pageHeight: Double;
|
||||
lRect: NSRect;
|
||||
lCurPage: Integer;
|
||||
begin
|
||||
// image page printing alternative
|
||||
@ -34,33 +38,34 @@ begin
|
||||
if Canvas = nil then Exit;
|
||||
|
||||
pageHeight := calculatePrintHeight();
|
||||
Size.height := pageHeight * (PageTo - PageFrom);
|
||||
Size.width := calculatePrintWidth();
|
||||
Self.setFrameSize(Size);
|
||||
lRect := updateSize(False);
|
||||
|
||||
// figure out which page this is
|
||||
lCurPage := Round((Size.height - dirtyRect.origin.y) / pageHeight);
|
||||
lCurPage := Round((lRect.size.height - dirtyRect.origin.y) / pageHeight);
|
||||
|
||||
Canvas.DrawRecording(Self, dirtyRect, lCurPage);
|
||||
Canvas.DrawRecording(Self, dirtyRect, lCurPage - PageFrom);
|
||||
end;
|
||||
|
||||
// Return the number of pages available for printing
|
||||
function TCocoaPrinterView.knowsPageRange(range: NSRangePointer): Boolean;
|
||||
begin
|
||||
updateSize(True);
|
||||
range^.location := PageFrom;
|
||||
range^.length := PageTo;
|
||||
range^.length := PageTo - PageFrom + 1;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaPrinterView.rectForPage(page: NSInteger): NSRect;
|
||||
var
|
||||
lBounds: NSRect;
|
||||
pageHeight: Double;
|
||||
pageHeight, pageWidth: Double;
|
||||
begin
|
||||
lBounds := self.bounds;
|
||||
pageHeight := calculatePrintHeight();
|
||||
Result := NSMakeRect(NSMinX(bounds), NSMaxY(bounds) - page * pageHeight,
|
||||
NSWidth(bounds), pageHeight);
|
||||
pageWidth := calculatePrintWidth();
|
||||
// page Y starting pos is Bottom-Left of page 1 - (pagenr-zero-based) * pageHeight, so:
|
||||
// pageHeight * ((PageTo - PageFrom) - (page - PageFrom)), which simplifies to:
|
||||
Result := NSMakeRect(0, pageHeight * (PageTo - page),
|
||||
pageWidth, pageHeight);
|
||||
end;
|
||||
|
||||
// Calculate the vertical size of the view that fits on a single page
|
||||
@ -100,6 +105,18 @@ begin
|
||||
Result := pageWidth / scale;
|
||||
end;
|
||||
|
||||
function TCocoaPrinterView.updateSize(ADoSetFrame: Boolean): NSRect;
|
||||
var
|
||||
Size: NSSize;
|
||||
begin
|
||||
Size.height := calculatePrintHeight();
|
||||
Size.height := Size.height * (PageTo - PageFrom + 1);
|
||||
Size.width := calculatePrintWidth();
|
||||
if ADoSetFrame then
|
||||
Self.setFrameSize(Size);
|
||||
Result := NSMakeRect(0, 0, Size.width, Size.height);
|
||||
end;
|
||||
|
||||
{ TCocoaPrinter }
|
||||
|
||||
function TCocoaPrinter.CreatePageFormat(APaper: String): PMPageFormat;
|
||||
@ -252,7 +269,7 @@ var
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
FPrintViewRect := GetNSRect(0, 0, 800, 800);
|
||||
FPrintViewRect := GetNSRect(0, 0, 1000, 1000);
|
||||
FPrintView := TCocoaPrinterView.alloc.initWithFrame(FPrintViewRect);
|
||||
FPrintView.Canvas := Canvas as TCocoaPrinterCanvas;
|
||||
|
||||
|
@ -19,7 +19,6 @@ type
|
||||
TCocoaPrinterView = objcclass(NSView)
|
||||
public
|
||||
//Image: NSImage;
|
||||
Size: NSSize;
|
||||
Canvas: TCocoaPrinterCanvas;
|
||||
// TPrintDialog info
|
||||
PageMin, PageMax, PageFrom, PageTo: Integer;
|
||||
@ -32,6 +31,7 @@ type
|
||||
function rectForPage(page: NSInteger): NSRect; override;
|
||||
function calculatePrintHeight: Double; message 'calculatePrintHeight';
|
||||
function calculatePrintWidth: Double; message 'calculatePrintWidth';
|
||||
function updateSize(ADoSetFrame: Boolean): NSRect; message 'updateSize:';
|
||||
end;
|
||||
|
||||
{ TCocoaPrinter }
|
||||
|
Loading…
Reference in New Issue
Block a user