mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 23:42:16 +00:00
Add PDF output for cairo backend.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@25479 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6455a62a4f
commit
1ce0bd5175
7 changed files with 145 additions and 48 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2007-09-12 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/cairo/CairoGState.h,
|
||||
* Source/cairo/CairoGState.m (-setSize, -DPSgsave, -DPSgrestore):
|
||||
Remove unused methods.
|
||||
* Headers/cairo/CairoPDFSurface.h,
|
||||
* Source/cairo/CairoPDFSurface.m: New files.
|
||||
* Source/cairo/GNUmakefile: Add new source file.
|
||||
* Source/cairo/CairoContext.m (-initWithContextInfo:,
|
||||
-beginPrologueBBox:...title:) Rewrite to support PDF output.
|
||||
|
||||
2007-09-09 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/cairo/CairoGState.m (-DPSeofill, -DPSfill, -DPSstroke):
|
||||
|
|
|
@ -40,10 +40,7 @@
|
|||
|
||||
- (void) GSCurrentSurface: (CairoSurface **)surface: (int *)x : (int *)y;
|
||||
- (void) GSSetSurface: (CairoSurface *)surface : (int)x : (int)y;
|
||||
- (void) DPSgsave;
|
||||
- (void) DPSgrestore;
|
||||
|
||||
- (void) setSize: (NSSize)size;
|
||||
- (void) showPage;
|
||||
@end
|
||||
|
||||
|
|
38
Headers/cairo/CairoPDFSurface.h
Normal file
38
Headers/cairo/CairoPDFSurface.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
This file is part of GNUstep.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef XGCairoPDFSurface_h
|
||||
#define XGCairoPDFSurface_h
|
||||
|
||||
#include "cairo/CairoSurface.h"
|
||||
|
||||
@interface CairoPDFSurface : CairoSurface
|
||||
{
|
||||
NSSize size;
|
||||
}
|
||||
|
||||
- (void)setSize: (NSSize)newSize;
|
||||
- (void)writeComment: (NSString *)comment;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -23,6 +23,7 @@
|
|||
#include "cairo/CairoGState.h"
|
||||
#include "cairo/CairoSurface.h"
|
||||
#include "cairo/CairoPSSurface.h"
|
||||
#include "cairo/CairoPDFSurface.h"
|
||||
#include "cairo/CairoFontInfo.h"
|
||||
#include "cairo/CairoFontEnumerator.h"
|
||||
#include "x11/XGServer.h"
|
||||
|
@ -53,29 +54,16 @@
|
|||
|
||||
- (id) initWithContextInfo: (NSDictionary *)info
|
||||
{
|
||||
NSString *contextType;
|
||||
|
||||
contextType = [info objectForKey:
|
||||
NSGraphicsContextRepresentationFormatAttributeName];
|
||||
// Don't allow super to handle PS case.
|
||||
self = [super initWithContextInfo: nil];
|
||||
if (!self)
|
||||
return self;
|
||||
|
||||
// Now save the info
|
||||
ASSIGN(context_info, info);
|
||||
|
||||
gstate = [[CairoGState allocWithZone: [self zone]] initWithDrawContext: self];
|
||||
|
||||
if (contextType)
|
||||
{
|
||||
CairoSurface *surface;
|
||||
NSSize size;
|
||||
|
||||
surface = [[CairoPSSurface alloc] initWithDevice: info];
|
||||
// This strange setting is needed because of the way GUI handles offset.
|
||||
size = [surface size];
|
||||
[CGSTATE GSSetSurface: surface : 0.0 : size.height];
|
||||
RELEASE(surface);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -141,7 +129,34 @@
|
|||
pages: (int)numPages
|
||||
title: (NSString*)aTitle
|
||||
{
|
||||
[CGSTATE setSize: boundingBox.size];
|
||||
CairoSurface *surface;
|
||||
NSSize size;
|
||||
NSString *contextType;
|
||||
|
||||
contextType = [context_info objectForKey:
|
||||
NSGraphicsContextRepresentationFormatAttributeName];
|
||||
|
||||
if (contextType)
|
||||
{
|
||||
if ([contextType isEqual: NSGraphicsContextPSFormat])
|
||||
{
|
||||
size = boundingBox.size;
|
||||
surface = [[CairoPSSurface alloc] initWithDevice: context_info];
|
||||
[surface setSize: size];
|
||||
// This strange setting is needed because of the way GUI handles offset.
|
||||
[CGSTATE GSSetSurface: surface : 0.0 : size.height];
|
||||
RELEASE(surface);
|
||||
}
|
||||
else if ([contextType isEqual: NSGraphicsContextPDFFormat])
|
||||
{
|
||||
size = boundingBox.size;
|
||||
surface = [[CairoPDFSurface alloc] initWithDevice: context_info];
|
||||
[surface setSize: size];
|
||||
// This strange setting is needed because of the way GUI handles offset.
|
||||
[CGSTATE GSSetSurface: surface : 0.0 : size.height];
|
||||
RELEASE(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) showPage
|
||||
|
|
|
@ -211,26 +211,6 @@
|
|||
[super setOffset: theOffset];
|
||||
}
|
||||
|
||||
- (void) DPSgrestore
|
||||
{
|
||||
if (_ct)
|
||||
{
|
||||
cairo_restore(_ct);
|
||||
if (cairo_status(_ct) == CAIRO_STATUS_INVALID_RESTORE)
|
||||
{
|
||||
// Restore failed because there was no more state on the stack
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) DPSgsave
|
||||
{
|
||||
if (_ct)
|
||||
{
|
||||
cairo_save(_ct);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) showPage
|
||||
{
|
||||
if (_ct)
|
||||
|
@ -239,14 +219,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) setSize: (NSSize)size
|
||||
{
|
||||
if (_surface)
|
||||
{
|
||||
[_surface setSize: size];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Color operations
|
||||
*/
|
||||
|
|
63
Source/cairo/CairoPDFSurface.m
Normal file
63
Source/cairo/CairoPDFSurface.m
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
This file is part of GNUstep.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "cairo/CairoPDFSurface.h"
|
||||
#include <cairo-pdf.h>
|
||||
|
||||
@implementation CairoPDFSurface
|
||||
|
||||
- (id) initWithDevice: (void *)device
|
||||
{
|
||||
NSDictionary *info;
|
||||
NSString *path;
|
||||
|
||||
info = (NSDictionary*)device;
|
||||
path = [info objectForKey: @"NSOutputFile"];
|
||||
|
||||
// FIXME: Hard coded size in points
|
||||
size = NSMakeSize(400, 400);
|
||||
_surface = cairo_pdf_surface_create([path fileSystemRepresentation],
|
||||
size.width, size.height);
|
||||
if (cairo_surface_status(_surface))
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
- (void) setSize: (NSSize)newSize
|
||||
{
|
||||
size = newSize;
|
||||
cairo_pdf_surface_set_size(_surface, size.width, size.height);
|
||||
}
|
||||
|
||||
- (void) writeComment: (NSString *)comment
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
|
@ -36,6 +36,7 @@ cairo_OBJC_FILES = CairoSurface.m \
|
|||
CairoFontEnumerator.m \
|
||||
CairoFaceInfo.m \
|
||||
CairoPSSurface.m \
|
||||
CairoPDFSurface.m \
|
||||
XGCairoSurface.m \
|
||||
XGCairoXImageSurface.m
|
||||
|
||||
|
|
Loading…
Reference in a new issue