// Aprica2
// copyright Pirmin Braun 1997-2007 - pirmin@pirmin.de
// all Rights reserved;
#import "Aprica.h"
#define TEXTPOS_LL 0 /* lower left */
#define TEXTPOS_LM 1 /* lower middle */
#define TEXTPOS_LR 2 /* lower right */
#define PI 3.141592654
#define PBPDF_A4 @"0 0 595 842"
#define PBPDF_B5 @"0 0 499 708"
#define PBPDF_A4quer @"0 0 842 595"
#define PBPDF_A5quer @"0 0 421 298"
#define PBPDF_qm @"0 0 2835 2835"
#define inch 72.0
#define POINTSPERINCH 72.0 /* number of points per inch */
#define POINTSPERCM 28.3464566929 /* number of points per cm */
#define POINTSPERMM 2.83464566929 /* number of points per mm */
#define NSD(s) ([s dataUsingEncoding:(NSWindowsCP1252StringEncoding) allowLossyConversion:YES])
#define CP [pdf currentPage]
#define APC(s) [CP appendToContent:NSD(s)]
@interface PBPDFPage:NSObject
{// parent immer fix das pages-Object
// Resources umfassen Fonts, Images, ProcSet, MediaBox, Contents
// contents ist fix ein stream-Object pro Seite
// mediabox ist die globale
// procset ist ab pdf 1.4 obsolet, kann ein fixes Objekt mit [/PDF /Text /ImageC ] sein
NSMutableArray *imageFilenames; // filenamen f. imagesByFilename
NSMutableArray *fontNames; // wie im cpdf angegeben
NSMutableData *contents; //stream; enthaelt keine binaerdaten
int rotate;
NSString *mediaBox;
int objectIndex;
}
ACCESSh(mediaBox,setMediaBox);
- (int)objectIndex;
- (void)setObjectIndex:(int)i;
- (int)rotate;
- (void)appendToContent:(NSData *)data;
- (void)setRotate:(int)i;
- (NSMutableArray *)imageFilenames;
- (NSMutableArray *)fontNames;
- (NSMutableData *)contents;
@end
@interface PBPDFImage:NSObject
{// type=xobject, subtype=image
NSString *fileName; //darunter wird es in imagesByFilename gehalten
NSString *name; //kurzname des Object fuer Referenzierung
int width,height;
int bitsPerComponent,num_components;
NSData *data;
int objectIndex;
}
ACCESSh(fileName,setFileName);
ACCESSh(name,setName);
ACCESSClassh(data,setData,NSData);
- (int)width;
- (int)height;
- (int)num_components;
- (int)bitsPerComponent;
- (int)objectIndex;
- (void)setObjectIndex:(int)i;
- (BOOL)checkForJpeg;
@end
@interface PBPDFFont:NSObject
{ NSString *name; //kurzname des Font fuer Referenzierung, gleichzeitig eindeutiger Name des font
int objectIndex;
int afmIndex;
NSMutableDictionary *widthDict;
NSString *widthArrayForPDF;
}
ACCESSh(name,setName);
- (NSDictionary *)widthDict;
- (int)objectIndex;
- (void)addToWidthDict:(NSString *)s;
- (void)setObjectIndex:(int)i;
- (int)afmIndex;
- (void)setAfmIndex:(int)i;
- (NSString *)widthArrayForPDF;
@end
@interface PBPDFDoc:NSObject
{ int rotate;
PBPDFFont *currentFont;
NSMutableDictionary *fontInfos; //key=fontName
NSMutableDictionary *imagesByFilename; //key=filename, object=imageInfo
NSMutableArray *pages;
NSString *mediaBox;
PBPDFPage *currentPage;
NSString *currentFontName;
int currentAFMIndex;
int currentEncIndex;
float currentSize;
BOOL wasRendered;
BOOL needsFontEmbedding; // steuert dann postprocessing
}
+ (PBPDFDoc *)newPDF;
- (void)addPage;
- (BOOL)needsFontEmbedding;
- (BOOL)wasRendered;
- (void)setWasRendered:(BOOL)yn;
- (NSString *)stringOfWidth:(int)maxWidth str:(NSString *)s;
- (NSString *)stringOfWidthFullWord:(int)maxWidth str:(NSString *)s;
- (float)stringWidth:(NSString *)s;
- (void)setFont:(NSString *)fontName size:(float)size;
- (NSData *)renderPDF;
- (void)grestore;
- (void)gsave;
- (void)setCTM:(float)a :(float)b :(float)c :(float)d :(float)x :(float)y;
- (void)concatCTM:(float)a :(float)b :(float)c :(float)d :(float)x :(float)y;
- (void)translateCTM:(float)xt :(float)yt;
- (void)text:(NSString *)s x:(float)x y:(float)y rotate:(float)r align:(int)align;
- (void)jpeg:(NSString *)fn x:(float)x y:(float)y w:(float *)imgw h:(float *)imgh;
ACCESSh(currentFontName,setCurrentFontName);
ACCESSClassh(currentFont,setCurrentFont,PBPDFFont);
ACCESSClassh(currentPage,setCurrentPage,PBPDFPage);
@end