mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-01-31 09:02:13 +00:00
- SWRender, added PDF draw test
- PDF drawing related cleanup
This commit is contained in:
parent
524349a088
commit
a570c48944
@ -688,6 +688,7 @@
|
||||
FE6EE2E20DB92B05005503A1 /* KGRasterizer.m in Sources */ = {isa = PBXBuildFile; fileRef = FE6EE2DE0DB92B05005503A1 /* KGRasterizer.m */; };
|
||||
FE6EE2E50DB92B11005503A1 /* VGPath.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6EE2E30DB92B11005503A1 /* VGPath.h */; };
|
||||
FE6EE2E60DB92B11005503A1 /* VGPath.m in Sources */ = {isa = PBXBuildFile; fileRef = FE6EE2E40DB92B11005503A1 /* VGPath.m */; };
|
||||
FE7ABEBE0DC2C9BA0060D15B /* CGPDFDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = FE7ABEBD0DC2C9BA0060D15B /* CGPDFDocument.m */; };
|
||||
FE82867F0D34727900F7489F /* NSApplicationIcon.tiff in Resources */ = {isa = PBXBuildFile; fileRef = FE8286770D34727900F7489F /* NSApplicationIcon.tiff */; };
|
||||
FE8286800D34727900F7489F /* NSSystemInfoPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = FE8286780D34727900F7489F /* NSSystemInfoPanel.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
FE8286810D34727900F7489F /* NSSystemInfoPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = FE8286790D34727900F7489F /* NSSystemInfoPanel.m */; };
|
||||
@ -1437,6 +1438,7 @@
|
||||
FE7247A50C0622F2007CBC51 /* NSTextAttachmentCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSTextAttachmentCell.m; sourceTree = "<group>"; };
|
||||
FE72484F0C0676AA007CBC51 /* NSTypesetter_concrete.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSTypesetter_concrete.h; sourceTree = "<group>"; };
|
||||
FE7248500C0676AA007CBC51 /* NSTypesetter_concrete.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSTypesetter_concrete.m; sourceTree = "<group>"; };
|
||||
FE7ABEBD0DC2C9BA0060D15B /* CGPDFDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CGPDFDocument.m; sourceTree = "<group>"; };
|
||||
FE8286770D34727900F7489F /* NSApplicationIcon.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = NSApplicationIcon.tiff; sourceTree = "<group>"; };
|
||||
FE8286780D34727900F7489F /* NSSystemInfoPanel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = NSSystemInfoPanel.h; sourceTree = "<group>"; };
|
||||
FE8286790D34727900F7489F /* NSSystemInfoPanel.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = NSSystemInfoPanel.m; sourceTree = "<group>"; };
|
||||
@ -1972,6 +1974,7 @@
|
||||
6E2B55B20976075300DA0954 /* CoreGraphics */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FE7ABEBD0DC2C9BA0060D15B /* CGPDFDocument.m */,
|
||||
FE45EDCB0DC2407E00F49290 /* CGImageSource.m */,
|
||||
FE3395570DB930F4009AB3E0 /* KGContext_builtin.h */,
|
||||
FE3395580DB930F4009AB3E0 /* KGContext_builtin.m */,
|
||||
@ -3349,6 +3352,7 @@
|
||||
FE6EE2E60DB92B11005503A1 /* VGPath.m in Sources */,
|
||||
FE33955A0DB930F4009AB3E0 /* KGContext_builtin.m in Sources */,
|
||||
FE45EDCC0DC2407E00F49290 /* CGImageSource.m in Sources */,
|
||||
FE7ABEBE0DC2C9BA0060D15B /* CGPDFDocument.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -7,3 +7,11 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <ApplicationServices/CGPDFPage.h>
|
||||
|
||||
CGPDFPageRef CGPDFPageRetain(CGPDFPageRef self) {
|
||||
return [self retain];
|
||||
}
|
||||
|
||||
void CGPDFPageRelease(CGPDFPageRef self) {
|
||||
[self release];
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ BOOL _isAvailable=NO;
|
||||
case kCGImageAlphaNoneSkipFirst:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
_surface=KGSurfaceInitWithBytes(KGSurfaceAlloc(),_width,_height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorSpace,bitmapInfo,VG_lRGBA_8888_PRE,_bytes);
|
||||
_rasterizer=KGRasterizerInit(KGRasterizerAlloc());
|
||||
_pixelPipe=KGPixelPipeInit(KGPixelPipeAlloc());
|
||||
@ -223,11 +223,13 @@ xform=CGAffineTransformConcat(xform,u2d);
|
||||
}
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs count:(unsigned)count {
|
||||
KGInvalidAbstractInvocation();
|
||||
// KGInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)drawShading:(KGShading *)shading {
|
||||
KGInvalidAbstractInvocation();
|
||||
|
||||
|
||||
//KGInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)drawImage:(KGImage *)image inRect:(CGRect)rect {
|
||||
@ -302,7 +304,7 @@ xform=CGAffineTransformConcat(xform,u2d);
|
||||
}
|
||||
|
||||
-(void)drawLayer:(KGLayer *)layer inRect:(CGRect)rect {
|
||||
KGInvalidAbstractInvocation();
|
||||
//KGInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-initWithData:(NSData *)data;
|
||||
-initWithBytes:(const void *)bytes length:(size_t)length;
|
||||
|
||||
-(NSData *)data;
|
||||
-(const void *)bytes;
|
||||
-(size_t)length;
|
||||
|
||||
|
@ -243,6 +243,7 @@ const char *KGImageNameWithIntent(CGColorRenderingIntent intent);
|
||||
|
||||
size_t KGImageGetWidth(KGImage *self);
|
||||
size_t KGImageGetHeight(KGImage *self);
|
||||
VGColorInternalFormat KGImageColorFormat(KGImage *self);
|
||||
|
||||
KGRGBAffff KGRGBAffffUnpack(unsigned int inputData,KGImage *img);
|
||||
|
||||
|
@ -517,6 +517,10 @@ size_t KGImageGetHeight(KGImage *self) {
|
||||
return self->_height;
|
||||
}
|
||||
|
||||
VGColorInternalFormat KGImageColorFormat(KGImage *self) {
|
||||
return self->_colorFormat;
|
||||
}
|
||||
|
||||
static RIfloat byteToColor(unsigned char i){
|
||||
return (RIfloat)(i) / (RIfloat)0xFF;
|
||||
}
|
||||
|
@ -1019,7 +1019,7 @@ static void stbi_jpeg_load_from_memory(KGImageSource_JPEG *self,const stbi_uc *b
|
||||
KGDataProvider *provider=[[KGDataProvider alloc] initWithData:bitmap];
|
||||
KGColorSpace *colorSpace=[[KGColorSpace alloc] initWithGenericRGB];
|
||||
KGImage *image=[[KGImage alloc] initWithWidth:width height:height bitsPerComponent:8 bitsPerPixel:bitsPerPixel bytesPerRow:bytesPerRow
|
||||
colorSpace:colorSpace bitmapInfo:0/*kCGImageAlphaLast|kCGBitmapByteOrder32Little*/ provider:provider decode:NULL interpolate:NO renderingIntent:kCGRenderingIntentDefault];
|
||||
colorSpace:colorSpace bitmapInfo:kCGBitmapByteOrder32Big provider:provider decode:NULL interpolate:NO renderingIntent:kCGRenderingIntentDefault];
|
||||
|
||||
[colorSpace release];
|
||||
[provider release];
|
||||
|
@ -548,7 +548,7 @@ unsigned char *stbi_png_load_from_memory(const unsigned char *buffer, int len, i
|
||||
KGDataProvider *provider=[[KGDataProvider alloc] initWithData:bitmap];
|
||||
KGColorSpace *colorSpace=[[KGColorSpace alloc] initWithGenericRGB];
|
||||
KGImage *image=[[KGImage alloc] initWithWidth:width height:height bitsPerComponent:8 bitsPerPixel:bitsPerPixel bytesPerRow:bytesPerRow
|
||||
colorSpace:colorSpace bitmapInfo:0/*kCGImageAlphaLast|kCGBitmapByteOrder32Little*/ provider:provider decode:NULL interpolate:NO renderingIntent:kCGRenderingIntentDefault];
|
||||
colorSpace:colorSpace bitmapInfo:kCGBitmapByteOrder32Big provider:provider decode:NULL interpolate:NO renderingIntent:kCGRenderingIntentDefault];
|
||||
|
||||
[colorSpace release];
|
||||
[provider release];
|
||||
|
@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class KGPDFString,KGPDFxref,KGPDFDictionary,KGPDFPage;
|
||||
@class KGPDFString,KGPDFxref,KGPDFDictionary,KGPDFPage,KGDataProvider;
|
||||
|
||||
@interface KGPDFDocument : NSObject {
|
||||
KGPDFString *_version;
|
||||
@ -17,6 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-initWithData:(NSData *)data;
|
||||
-initWithDataProvider:(KGDataProvider *)provider;
|
||||
|
||||
-(KGPDFxref *)xref;
|
||||
|
||||
|
@ -35,6 +35,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithDataProvider:(KGDataProvider *)provider {
|
||||
return [self initWithData:[provider data]];
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
[_xref release];
|
||||
[super dealloc];
|
||||
@ -142,7 +146,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
-(KGPDFPage *)pageAtNumber:(int)pageNumber {
|
||||
KGPDFDictionary *pages=[self pagesRoot];
|
||||
KGPDFPage *page=[self pageAtNumber:pageNumber pages:pages pagesOffset:0];
|
||||
KGPDFPage *page=[self pageAtNumber:pageNumber-1 pages:pages pagesOffset:0];
|
||||
|
||||
return page;
|
||||
}
|
||||
|
@ -12,14 +12,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
@class KGPDFDocument,KGPDFDictionary,KGContext;
|
||||
|
||||
typedef enum {
|
||||
kKGPDFMediaBox,
|
||||
kKGPDFCropBox,
|
||||
kKGPDFBleedBox,
|
||||
kKGPDFTrimBox,
|
||||
kKGPDFArtBox
|
||||
} KGPDFBox;
|
||||
|
||||
@interface KGPDFPage : NSObject {
|
||||
KGPDFDocument *_document;
|
||||
int _pageNumber;
|
||||
@ -35,11 +27,11 @@ typedef enum {
|
||||
|
||||
-(KGPDFDictionary *)dictionary;
|
||||
|
||||
-(BOOL)getRect:(CGRect *)rect forBox:(KGPDFBox)box;
|
||||
-(BOOL)getRect:(CGRect *)rect forBox:(CGPDFBox)box;
|
||||
|
||||
-(int)rotationAngle;
|
||||
|
||||
-(CGAffineTransform)drawingTransformForBox:(KGPDFBox)box inRect:(CGRect)rect rotate:(int)degrees preserveAspectRatio:(BOOL)preserveAspectRatio;
|
||||
-(CGAffineTransform)drawingTransformForBox:(CGPDFBox)box inRect:(CGRect)rect rotate:(int)degrees preserveAspectRatio:(BOOL)preserveAspectRatio;
|
||||
|
||||
-(void)drawInContext:(KGContext *)context;
|
||||
|
||||
|
@ -70,18 +70,18 @@ BOOL KGPDFGetPageArrayForKey(KGPDFPage *page,const char *key,KGPDFArray **arrayp
|
||||
return [check checkForType:kKGPDFObjectTypeArray value:arrayp];
|
||||
}
|
||||
|
||||
-(BOOL)getRect:(CGRect *)rect forBox:(KGPDFBox)box {
|
||||
-(BOOL)getRect:(CGRect *)rect forBox:(CGPDFBox)box {
|
||||
const char *string=NULL;
|
||||
KGPDFArray *array;
|
||||
KGPDFReal *numbers;
|
||||
unsigned count;
|
||||
|
||||
switch(box){
|
||||
case kKGPDFMediaBox: string="MediaBox"; break;
|
||||
case kKGPDFCropBox: string="CropBox"; break;
|
||||
case kKGPDFBleedBox: string="BleedBox"; break;
|
||||
case kKGPDFTrimBox: string="TrimBox"; break;
|
||||
case kKGPDFArtBox: string="ArtBox"; break;
|
||||
case kCGPDFMediaBox: string="MediaBox"; break;
|
||||
case kCGPDFCropBox: string="CropBox"; break;
|
||||
case kCGPDFBleedBox: string="BleedBox"; break;
|
||||
case kCGPDFTrimBox: string="TrimBox"; break;
|
||||
case kCGPDFArtBox: string="ArtBox"; break;
|
||||
}
|
||||
|
||||
if(string==NULL)
|
||||
@ -112,7 +112,7 @@ BOOL KGPDFGetPageArrayForKey(KGPDFPage *page,const char *key,KGPDFArray **arrayp
|
||||
}
|
||||
|
||||
|
||||
-(CGAffineTransform)drawingTransformForBox:(KGPDFBox)box inRect:(CGRect)rect rotate:(int)degrees preserveAspectRatio:(BOOL)preserveAspectRatio {
|
||||
-(CGAffineTransform)drawingTransformForBox:(CGPDFBox)box inRect:(CGRect)rect rotate:(int)degrees preserveAspectRatio:(BOOL)preserveAspectRatio {
|
||||
CGAffineTransform result=CGAffineTransformIdentity;
|
||||
CGRect boxRect;
|
||||
|
||||
|
@ -494,12 +494,12 @@ static void KGPixelPipeReadPremultipliedSourceSpan(KGPixelPipe *self,int x,int y
|
||||
else {
|
||||
KGRGBAffff imageSpan[length];
|
||||
|
||||
KGPixelPipeReadPremultipliedImageNormalSpan(self,x,y,imageSpan,length,self->m_image->_colorFormat|VGColorPREMULTIPLIED);
|
||||
KGPixelPipeReadPremultipliedImageNormalSpan(self,x,y,imageSpan,length,KGImageColorFormat(self->m_image)|VGColorPREMULTIPLIED);
|
||||
|
||||
for(i=0;i<length;i++,x++){
|
||||
//evaluate paint
|
||||
VGColor s=VGColorFromKGRGBA_ffff(span[i],format);
|
||||
VGColor im=VGColorFromKGRGBA_ffff(imageSpan[i],self->m_image->_colorFormat);
|
||||
VGColor im=VGColorFromKGRGBA_ffff(imageSpan[i],KGImageColorFormat(self->m_image));
|
||||
|
||||
//apply image (vgDrawImage only)
|
||||
//1. paint: convert paint to dst space
|
||||
|
@ -35,7 +35,7 @@ typedef enum {
|
||||
VG_NON_ZERO
|
||||
} VGFillRule;
|
||||
|
||||
#define MAX_SAMPLES 32
|
||||
#define MAX_SAMPLES 256
|
||||
|
||||
typedef struct {
|
||||
Vector2 v0;
|
||||
@ -74,7 +74,7 @@ typedef struct {
|
||||
int numSamples;
|
||||
RIfloat sumWeights;
|
||||
RIfloat fradius; //max offset of the sampling points from a pixel center
|
||||
Sample samples[32];
|
||||
Sample samples[MAX_SAMPLES];
|
||||
}
|
||||
|
||||
KGRasterizer *KGRasterizerAlloc();
|
||||
|
@ -129,42 +129,32 @@ void KGRasterizerSetShouldAntialias(KGRasterizer *self,BOOL antialias) {
|
||||
self->_antialias=antialias;
|
||||
//make a sampling pattern
|
||||
self->sumWeights = 0.0f;
|
||||
self->fradius = 0.0f; //max offset of the sampling points from a pixel center
|
||||
|
||||
if(NO && !antialias){
|
||||
self->numSamples = 1;
|
||||
self->samples[0].x = 0.0f;
|
||||
self->samples[0].y = 0.0f;
|
||||
self->samples[0].weight = 1.0f;
|
||||
self->fradius = 0.0f;
|
||||
self->sumWeights = 1.0f;
|
||||
}
|
||||
else {
|
||||
#if 1
|
||||
//box filter of diameter 1.0f, 8-queen sampling pattern
|
||||
self->numSamples = 8;
|
||||
self->samples[0].x = 3;
|
||||
self->samples[1].x = 7;
|
||||
self->samples[2].x = 0;
|
||||
self->samples[3].x = 2;
|
||||
self->samples[4].x = 5;
|
||||
self->samples[5].x = 1;
|
||||
self->samples[6].x = 6;
|
||||
self->samples[7].x = 4;
|
||||
int i;
|
||||
for(i=0;i<self->numSamples;i++)
|
||||
{
|
||||
self->samples[i].x = (self->samples[i].x + 0.5f) / (RIfloat)self->numSamples - 0.5f;
|
||||
self->samples[i].y = ((RIfloat)i + 0.5f) / (RIfloat)self->numSamples - 0.5f;
|
||||
self->samples[i].weight = 1.0f / (RIfloat)self->numSamples;
|
||||
self->sumWeights += self->samples[i].weight;
|
||||
}
|
||||
self->fradius = 0.5f;
|
||||
#else
|
||||
if(NO && !self->_antialias){
|
||||
self->numSamples=1;
|
||||
self->fradius=0.6;
|
||||
self->sumWeights=1;
|
||||
self->samples[0].x = 0;
|
||||
self->samples[0].y = 0;
|
||||
self->samples[0].weight = 1;
|
||||
}
|
||||
else {
|
||||
/*
|
||||
The exact specifications of the Quartz AA filter are unknown. We want something very close in quality.
|
||||
|
||||
Visual comparisons indicate the Quartz filter quality is at least the quality of a 64 sample one.
|
||||
32 samples appears too low regardless of the function. More samples with an inferior weighting function
|
||||
doesn't help and is more expensive.
|
||||
|
||||
Visual comparisons indicate the Quartz filter radius is not large, 0.75 is too big and results
|
||||
in extra pixels being drawn which Quartz does not generate. 0.6 is extremely close if not identical using
|
||||
any reasonable weighting.
|
||||
|
||||
*/
|
||||
// The Quartz AA filter is different than this
|
||||
// 8, 16 also work, but all of them generate misdrawing with the classic test & stroking, this might be a fill bug
|
||||
self->numSamples = 32;
|
||||
self->fradius = .75;
|
||||
self->numSamples = 64;
|
||||
self->fradius = 0.6;
|
||||
int i;
|
||||
|
||||
for(i=0;i<self->numSamples;i++)
|
||||
@ -178,8 +168,8 @@ void KGRasterizerSetShouldAntialias(KGRasterizer *self,BOOL antialias) {
|
||||
RIfloat r = (RIfloat)sqrt(x) * self->fradius;
|
||||
x = r * (RIfloat)sin(y*2.0f*M_PI);
|
||||
y = r * (RIfloat)cos(y*2.0f*M_PI);
|
||||
self->samples[i].weight = (RIfloat)exp(-0.5f * RI_SQR(r/self->fradius));
|
||||
|
||||
self->samples[i].weight = (RIfloat)exp(-0.5*RI_SQR(r));
|
||||
// self->samples[i].weight = (RIfloat)exp(-0.5*RI_SQR(r/self->fradius));
|
||||
RI_ASSERT(x >= -1.5f && x <= 1.5f && y >= -1.5f && y <= 1.5f); //the specification restricts the filter radius to be less than or equal to 1.5
|
||||
|
||||
self->samples[i].x = x;
|
||||
@ -187,9 +177,8 @@ void KGRasterizerSetShouldAntialias(KGRasterizer *self,BOOL antialias) {
|
||||
|
||||
self->sumWeights += self->samples[i].weight;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void scanlineSort(Edge **edges,int count,Edge **B){
|
||||
@ -318,12 +307,6 @@ static void incrementEdgeForAET(Edge *edge,RIfloat cminy,RIfloat cmaxy,RIfloat f
|
||||
}
|
||||
|
||||
/*
|
||||
AA filter
|
||||
|
||||
Apple's AA filter is unknown at this point, so the sampling loop remains unoptimally optimized. The box filter is decent but
|
||||
is not as good. The Gaussian filter is closer, but it has a less uniform appearance than Apple's. The current Gaussian implementation
|
||||
also has big artifacts in some case shown by the Classic test. I'm not sure if the original filter was broken or the fill optimizations
|
||||
created a problem. When we figure out something closer/same as Apple's the sampling loops can be constant for the one filter.
|
||||
|
||||
Aliased Drawing
|
||||
|
||||
@ -483,20 +466,20 @@ void KGRasterizerFill(KGRasterizer *self,VGFillRule fillRule, KGPixelPipe *pixel
|
||||
if(scanx<minx)
|
||||
break;
|
||||
else {
|
||||
int direction=edge->direction;
|
||||
int direction=edge->direction;
|
||||
RIfloat *pre=edge->sidePre;
|
||||
int *windptr=winding;
|
||||
RIfloat pcxnormal=scanx*edge->normal.x;
|
||||
|
||||
s=self->numSamples;
|
||||
while(--s>=0){
|
||||
if(pcxnormal>pre[s])
|
||||
rightOfLastEdge=NO;
|
||||
else {
|
||||
winding[s]+=direction;
|
||||
rightOfLastEdge&=YES;
|
||||
int rightOfThisEdge=0;
|
||||
|
||||
for(s=0;s<self->numSamples;s++,windptr++){
|
||||
if(pcxnormal<=*pre++) {
|
||||
*windptr+=direction;
|
||||
rightOfThisEdge+=direction;
|
||||
}
|
||||
}
|
||||
|
||||
rightOfLastEdge&=(ABS(rightOfThisEdge)==self->numSamples)?YES:NO;
|
||||
if(rightOfLastEdge){
|
||||
rightOfLastEdge=YES;
|
||||
nextEdge=i+1;
|
||||
|
@ -626,7 +626,7 @@ KGSurface *KGSurfaceInit(KGSurface *self,size_t width, size_t height,size_t bits
|
||||
self->_bitmapInfo=bitmapInfo;
|
||||
|
||||
if(!initFunctionsForParameters(self,bitsPerComponent,bitsPerPixel,colorSpace,bitmapInfo))
|
||||
NSLog(@"error, return");
|
||||
NSLog(@"KGSurface error, return");
|
||||
|
||||
self->_imageFormat=imageFormat;
|
||||
size_t checkBPP;
|
||||
|
@ -35,7 +35,7 @@ typedef enum {
|
||||
} NSWindingRule;
|
||||
|
||||
@interface NSBezierPath : NSObject <NSCopying> {
|
||||
KGMutablePath *_path;
|
||||
CGMutablePathRef _path;
|
||||
float _lineWidth;
|
||||
float _miterLimit;
|
||||
float _flatness;
|
||||
|
@ -6,10 +6,10 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
// Original - Christopher Lloyd <cjwl@objc.net>
|
||||
#import <AppKit/NSBezierPath.h>
|
||||
#import <AppKit/KGMutablePath.h>
|
||||
#import <ApplicationServices/CGContext.h>
|
||||
#import <ApplicationServices/CGPath.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <Foundation/NSAffineTransform.h>
|
||||
#import <Foundation/NSRaise.h>
|
||||
@ -24,7 +24,7 @@ static NSLineCapStyle _defaultLineCapStyle=NSButtLineCapStyle;
|
||||
static NSLineJoinStyle _defaultLineJoinStyle=NSMiterLineJoinStyle;
|
||||
|
||||
-init {
|
||||
_path=[[KGMutablePath alloc] init];
|
||||
_path=CGPathCreateMutable();
|
||||
_lineWidth=_defaultLineWidth;
|
||||
_miterLimit=_defaultMiterLimit;
|
||||
_flatness=_defaultFlatness;
|
||||
@ -45,7 +45,7 @@ static NSLineJoinStyle _defaultLineJoinStyle=NSMiterLineJoinStyle;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_path release];
|
||||
CGPathRelease(_path);
|
||||
if(_dashes!=NULL)
|
||||
NSZoneFree(NULL,_dashes);
|
||||
[super dealloc];
|
||||
@ -54,7 +54,7 @@ static NSLineJoinStyle _defaultLineJoinStyle=NSMiterLineJoinStyle;
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
NSBezierPath *copy=NSCopyObject(self,0,zone);
|
||||
|
||||
copy->_path=[_path mutableCopy];
|
||||
copy->_path=CGPathCreateMutableCopy(_path);
|
||||
if(_dashCount>0){
|
||||
int i;
|
||||
|
||||
|
@ -8,6 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <AppKit/NSImageRep.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
@class KGImage;
|
||||
|
||||
@ -49,7 +50,7 @@ typedef enum {
|
||||
unsigned char **_bitmapPlanes;
|
||||
NSMutableDictionary *_properties;
|
||||
|
||||
KGImage *_image;
|
||||
CGImageRef _image;
|
||||
}
|
||||
|
||||
+(void)getTIFFCompressionTypes:(const NSTIFFCompression **)types count:(int *)count;
|
||||
|
@ -9,9 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <AppKit/NSBitmapImageRep.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <AppKit/KGImageSource.h>
|
||||
#import <AppKit/KGImage.h>
|
||||
|
||||
@implementation NSBitmapImageRep
|
||||
|
||||
@ -116,9 +113,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-initWithData:(NSData *)data {
|
||||
KGImageSource *imageSource=[KGImageSource newImageSourceWithData:data options:nil];
|
||||
CGImageSourceRef imageSource=CGImageSourceCreateWithData(data,nil);
|
||||
|
||||
_image=[imageSource imageAtIndex:0 options:nil];
|
||||
_image=CGImageSourceCreateImageAtIndex(imageSource,0,nil);
|
||||
_size.width=CGImageGetWidth(_image);
|
||||
_size.height=CGImageGetHeight(_image);
|
||||
|
||||
|
@ -7,10 +7,9 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <AppKit/NSPDFImageRep.h>
|
||||
#import <AppKit/KGPDFDocument.h>
|
||||
#import <AppKit/KGPDFPage.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <ApplicationServices/CGContext.h>
|
||||
#import <AppKit/KGPDFPage.h>
|
||||
|
||||
@implementation NSPDFImageRep
|
||||
|
||||
@ -36,13 +35,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-initWithData:(NSData *)data {
|
||||
_pdf=[data retain];
|
||||
_currentPage=0;
|
||||
_document=[[KGPDFDocument alloc] initWithData:_pdf];
|
||||
CGDataProviderRef provider=CGDataProviderCreateWithCFData(_pdf);
|
||||
_document=CGPDFDocumentCreateWithProvider(provider);
|
||||
CGDataProviderRelease(provider);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_pdf release];
|
||||
[_document release];
|
||||
CGPDFDocumentRelease(_document);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-(int)pageCount {
|
||||
return [_document pageCount];
|
||||
return CGPDFDocumentGetNumberOfPages(_document);
|
||||
}
|
||||
|
||||
-(int)currentPage {
|
||||
@ -67,10 +68,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-(NSSize)size {
|
||||
KGPDFPage *page=[_document pageAtNumber:_currentPage];
|
||||
CGPDFPageRef page=CGPDFDocumentGetPage(_document,_currentPage);
|
||||
NSRect mediaBox;
|
||||
|
||||
if(![page getRect:&mediaBox forBox:kKGPDFMediaBox])
|
||||
|
||||
if(![page getRect:&mediaBox forBox:kCGPDFMediaBox])
|
||||
return NSMakeSize(0,0);
|
||||
|
||||
return mediaBox.size;
|
||||
@ -78,13 +79,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
-(BOOL)drawInRect:(NSRect)rect {
|
||||
CGContextRef context=[[NSGraphicsContext currentContext] graphicsPort];
|
||||
KGPDFPage *page=[_document pageAtNumber:_currentPage];
|
||||
CGPDFPageRef page=CGPDFDocumentGetPage(_document,_currentPage);
|
||||
|
||||
if(page==nil)
|
||||
return NO;
|
||||
|
||||
CGContextSaveGState(context);
|
||||
CGContextConcatCTM(context,[page drawingTransformForBox:kKGPDFMediaBox inRect:rect rotate:0 preserveAspectRatio:NO]);
|
||||
CGContextConcatCTM(context,[page drawingTransformForBox:kCGPDFMediaBox inRect:rect rotate:0 preserveAspectRatio:NO]);
|
||||
CGContextDrawPDFPage(context,page);
|
||||
CGContextRestoreGState(context);
|
||||
return YES;
|
||||
|
@ -9,6 +9,7 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
FE01AAE60C5D9BF900AEA51A /* ApplicationServices.h in Headers */ = {isa = PBXBuildFile; fileRef = FE32179C0BB41C65004F000A /* ApplicationServices.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
FE45EDC30DC2400F00F49290 /* CGImageSource.h in Headers */ = {isa = PBXBuildFile; fileRef = FE45EDC20DC2400F00F49290 /* CGImageSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
FE7ABE640DC2C0290060D15B /* CGPDFDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = FE7ABE630DC2C0290060D15B /* CGPDFDocument.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
FECAF4E90DB7110900BA2A8E /* CGAffineTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = FECAF4DA0DB7110900BA2A8E /* CGAffineTransform.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
FECAF4EA0DB7110900BA2A8E /* CGBitmapContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FECAF4DB0DB7110900BA2A8E /* CGBitmapContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
FECAF4EB0DB7110900BA2A8E /* CGColor.h in Headers */ = {isa = PBXBuildFile; fileRef = FECAF4DC0DB7110900BA2A8E /* CGColor.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@ -84,6 +85,7 @@
|
||||
FE01AAED0C5D9BF900AEA51A /* ApplicationServices.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ApplicationServices.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
FE32179C0BB41C65004F000A /* ApplicationServices.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ApplicationServices.h; sourceTree = "<group>"; };
|
||||
FE45EDC20DC2400F00F49290 /* CGImageSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGImageSource.h; sourceTree = "<group>"; };
|
||||
FE7ABE630DC2C0290060D15B /* CGPDFDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGPDFDocument.h; sourceTree = "<group>"; };
|
||||
FECAF4DA0DB7110900BA2A8E /* CGAffineTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGAffineTransform.h; sourceTree = "<group>"; };
|
||||
FECAF4DB0DB7110900BA2A8E /* CGBitmapContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGBitmapContext.h; sourceTree = "<group>"; };
|
||||
FECAF4DC0DB7110900BA2A8E /* CGColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGColor.h; sourceTree = "<group>"; };
|
||||
@ -126,10 +128,6 @@
|
||||
0867D691FE84028FC02AAC07 /* ApplicationServices */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FE45EDC20DC2400F00F49290 /* CGImageSource.h */,
|
||||
FECAF52D0DB7134F00BA2A8E /* CGPDFPage.h */,
|
||||
FECAF5150DB711BC00BA2A8E /* CoreGraphicsExport.h */,
|
||||
FECAF5010DB7119B00BA2A8E /* Foundation.xcodeproj */,
|
||||
FECAF4DA0DB7110900BA2A8E /* CGAffineTransform.h */,
|
||||
FECAF4DB0DB7110900BA2A8E /* CGBitmapContext.h */,
|
||||
FECAF4DC0DB7110900BA2A8E /* CGColor.h */,
|
||||
@ -140,16 +138,21 @@
|
||||
FECAF4E10DB7110900BA2A8E /* CGFunction.h */,
|
||||
FECAF4E20DB7110900BA2A8E /* CGGeometry.h */,
|
||||
FECAF4E30DB7110900BA2A8E /* CGImage.h */,
|
||||
FE45EDC20DC2400F00F49290 /* CGImageSource.h */,
|
||||
FECAF4E40DB7110900BA2A8E /* CGLayer.h */,
|
||||
FECAF4E50DB7110900BA2A8E /* CGPath.h */,
|
||||
FECAF4E60DB7110900BA2A8E /* CGPattern.h */,
|
||||
FE7ABE630DC2C0290060D15B /* CGPDFDocument.h */,
|
||||
FECAF52D0DB7134F00BA2A8E /* CGPDFPage.h */,
|
||||
FECAF4E70DB7110900BA2A8E /* CGShading.h */,
|
||||
FECAF4E80DB7110900BA2A8E /* CoreGraphics.h */,
|
||||
08FB77AEFE84172EC02AAC07 /* Classes */,
|
||||
32C88DFF0371C24200C91783 /* Other Sources */,
|
||||
089C1665FE841158C02AAC07 /* Resources */,
|
||||
FECAF4E80DB7110900BA2A8E /* CoreGraphics.h */,
|
||||
FECAF5150DB711BC00BA2A8E /* CoreGraphicsExport.h */,
|
||||
0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */,
|
||||
FECAF5010DB7119B00BA2A8E /* Foundation.xcodeproj */,
|
||||
32C88DFF0371C24200C91783 /* Other Sources */,
|
||||
034768DFFF38A50411DB9C8B /* Products */,
|
||||
089C1665FE841158C02AAC07 /* Resources */,
|
||||
);
|
||||
name = ApplicationServices;
|
||||
sourceTree = "<group>";
|
||||
@ -240,6 +243,7 @@
|
||||
FECAF5160DB711BC00BA2A8E /* CoreGraphicsExport.h in Headers */,
|
||||
FECAF52E0DB7134F00BA2A8E /* CGPDFPage.h in Headers */,
|
||||
FE45EDC30DC2400F00F49290 /* CGImageSource.h in Headers */,
|
||||
FE7ABE640DC2C0290060D15B /* CGPDFDocument.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1,3 +1,11 @@
|
||||
/* Copyright (c) 2008 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import "CoreGraphicsExport.h"
|
||||
|
||||
@class KGImageSource;
|
||||
|
@ -6,8 +6,20 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import "CoreGraphicsExport.h"
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@class KGPDFPage;
|
||||
|
||||
typedef KGPDFPage *CGPDFPageRef;
|
||||
|
||||
typedef enum {
|
||||
kCGPDFMediaBox,
|
||||
kCGPDFCropBox,
|
||||
kCGPDFBleedBox,
|
||||
kCGPDFTrimBox,
|
||||
kCGPDFArtBox,
|
||||
} CGPDFBox;
|
||||
|
||||
COREGRAPHICS_EXPORT CGPDFPageRef CGPDFPageRetain(CGPDFPageRef self);
|
||||
COREGRAPHICS_EXPORT void CGPDFPageRelease(CGPDFPageRef self);
|
||||
|
@ -18,8 +18,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <ApplicationServices/CGFunction.h>
|
||||
#import <ApplicationServices/CGGeometry.h>
|
||||
#import <ApplicationServices/CGImage.h>
|
||||
#import <ApplicationServices/CGImageSource.h>
|
||||
#import <ApplicationServices/CGLayer.h>
|
||||
#import <ApplicationServices/CGPath.h>
|
||||
#import <ApplicationServices/CGPattern.h>
|
||||
#import <ApplicationServices/CGPDFDocument.h>
|
||||
#import <ApplicationServices/CGPDFPage.h>
|
||||
#import <ApplicationServices/CGShading.h>
|
||||
|
@ -6,6 +6,8 @@
|
||||
#import "KGImage.h"
|
||||
#import "KGImageSource.h"
|
||||
#import "KGDataProvider.h"
|
||||
#import "KGPDFDocument.h"
|
||||
#import "KGPDFPage.h"
|
||||
|
||||
#define CGContextRef KGContext *
|
||||
#define CGColorRef KGColor *
|
||||
@ -15,6 +17,8 @@
|
||||
#define CGDataProviderRef KGDataProvider *
|
||||
#define CGImageRef KGImage *
|
||||
#define CGImageSourceRef KGImageSource *
|
||||
#define CGPDFDocumentRef KGPDFDocument *
|
||||
#define CGPDFPageRef KGPDFPage *
|
||||
|
||||
#define CGContextRetain(context) \
|
||||
[context retain]
|
||||
@ -503,6 +507,9 @@
|
||||
|
||||
#define CGDataProviderCreateWithData(info,data,size, releaseCallback) \
|
||||
[[KGDataProvider alloc] initWithBytes:data length:size]
|
||||
|
||||
#define CGDataProviderCreateWithCFData(data) \
|
||||
[[KGDataProvider alloc] initWithData:data]
|
||||
|
||||
// image source
|
||||
|
||||
@ -513,3 +520,28 @@
|
||||
[self imageAtIndex:index options:opts]
|
||||
|
||||
|
||||
// pdf document
|
||||
|
||||
#define CGPDFDocumentRetain(self) \
|
||||
[self retain]
|
||||
|
||||
#define CGPDFDocumentRelease(self) \
|
||||
[self release]
|
||||
|
||||
#define CGPDFDocumentCreateWithProvider(provider) \
|
||||
[[KGPDFDocument alloc] initWithDataProvider:provider]
|
||||
|
||||
#define CGPDFDocumentGetNumberOfPages(self) \
|
||||
[self pageCount]
|
||||
|
||||
#define CGPDFDocumentGetPage(self,pageNumber) \
|
||||
[self pageAtNumber:pageNumber]
|
||||
|
||||
// pdf page
|
||||
|
||||
#define CGPDFPageRetain(self) \
|
||||
[self retain]
|
||||
|
||||
#define CGPDFPageRelease(self) \
|
||||
[self release]
|
||||
|
||||
|
@ -32,9 +32,10 @@
|
||||
-(void)setRotation:(float)value;
|
||||
-(void)setShouldAntialias:(BOOL)value;
|
||||
-(void)setInterpolationQuality:(CGInterpolationQuality)value;
|
||||
-(void)setPDFData:(NSData *)data;
|
||||
|
||||
-(void)drawClassic;
|
||||
-(void)drawBitmapImageRep;
|
||||
|
||||
-(void)drawPDF;
|
||||
|
||||
@end
|
||||
|
@ -34,6 +34,7 @@
|
||||
float _flatness;
|
||||
|
||||
CGImageRef _resamplingImage;
|
||||
CGPDFDocumentRef _pdfDocument;
|
||||
}
|
||||
@end
|
||||
|
||||
@ -60,6 +61,7 @@ static CGColorRef cgColorFromColor(NSColor *color){
|
||||
|
||||
_fillColor=cgColorFromColor([NSColor blueColor]);
|
||||
_strokeColor=cgColorFromColor([NSColor redColor]);
|
||||
_pathDrawingMode=kCGPathStroke;
|
||||
_shouldAntialias=YES;
|
||||
_interpolationQuality=kCGInterpolationDefault;
|
||||
_scalex=1;
|
||||
@ -198,6 +200,16 @@ static CGColorRef cgColorFromColor(NSColor *color){
|
||||
_interpolationQuality=value;
|
||||
}
|
||||
|
||||
-(void)setPDFData:(NSData *)data {
|
||||
if(_pdfDocument!=NULL)
|
||||
CGPDFDocumentRelease(_pdfDocument);
|
||||
|
||||
CGDataProviderRef provider=CGDataProviderCreateWithCFData(data);
|
||||
|
||||
_pdfDocument=CGPDFDocumentCreateWithProvider(provider);
|
||||
CGDataProviderRelease(provider);
|
||||
}
|
||||
|
||||
-(CGAffineTransform)ctm {
|
||||
CGAffineTransform ctm=CGAffineTransformMakeTranslation(400/2,400/2);
|
||||
|
||||
@ -206,6 +218,19 @@ static CGColorRef cgColorFromColor(NSColor *color){
|
||||
return CGAffineTransformRotate(ctm,M_PI*_rotation/180.0);
|
||||
}
|
||||
|
||||
-(void)establishContextState {
|
||||
CGContextSetShouldAntialias(_context,_shouldAntialias);
|
||||
CGContextSetBlendMode(_context,_blendMode);
|
||||
CGContextSetFillColorWithColor(_context,_fillColor);
|
||||
CGContextSetStrokeColorWithColor(_context,_strokeColor);
|
||||
CGContextSetLineWidth(_context,_lineWidth);
|
||||
CGContextSetLineCap(_context,_lineCap);
|
||||
CGContextSetLineJoin(_context,_lineJoin);
|
||||
CGContextSetMiterLimit(_context,_miterLimit);
|
||||
CGContextSetLineDash(_context,_dashPhase,_dashLengths,_dashLengthsCount);
|
||||
CGContextSetFlatness(_context,_flatness);
|
||||
}
|
||||
|
||||
static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRadius,float startAngle,float endAngle){
|
||||
CGPoint point;
|
||||
|
||||
@ -232,16 +257,9 @@ static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRa
|
||||
CGContextSaveGState(_context);
|
||||
CGContextClearRect(_context,CGRectMake(0,0,400,400));
|
||||
CGContextConcatCTM(_context,xform);
|
||||
CGContextSetShouldAntialias(_context,_shouldAntialias);
|
||||
CGContextSetBlendMode(_context,_blendMode);
|
||||
CGContextSetFillColorWithColor(_context,_fillColor);
|
||||
CGContextSetStrokeColorWithColor(_context,_strokeColor);
|
||||
CGContextSetLineWidth(_context,_lineWidth);
|
||||
CGContextSetLineCap(_context,_lineCap);
|
||||
CGContextSetLineJoin(_context,_lineJoin);
|
||||
CGContextSetMiterLimit(_context,_miterLimit);
|
||||
CGContextSetLineDash(_context,_dashPhase,_dashLengths,_dashLengthsCount);
|
||||
CGContextSetFlatness(_context,_flatness);
|
||||
|
||||
[self establishContextState];
|
||||
|
||||
CGContextBeginPath(_context);
|
||||
CGContextAddPath(_context,path);
|
||||
|
||||
@ -260,9 +278,7 @@ static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRa
|
||||
CGContextSaveGState(_context);
|
||||
CGContextClearRect(_context,CGRectMake(0,0,400,400));
|
||||
CGContextConcatCTM(_context,ctm);
|
||||
CGContextSetShouldAntialias(_context,_shouldAntialias);
|
||||
CGContextSetInterpolationQuality(_context,_interpolationQuality);
|
||||
CGContextSetBlendMode(_context,_blendMode);
|
||||
[self establishContextState];
|
||||
|
||||
|
||||
CGContextDrawImage(_context,CGRectMake(0,0,CGImageGetWidth(_resamplingImage),CGImageGetHeight(_resamplingImage)),_resamplingImage);
|
||||
@ -290,16 +306,7 @@ static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRa
|
||||
CGContextSaveGState(_context);
|
||||
CGContextClearRect(_context,CGRectMake(0,0,400,400));
|
||||
CGContextConcatCTM(_context,xform);
|
||||
CGContextSetShouldAntialias(_context,_shouldAntialias);
|
||||
CGContextSetBlendMode(_context,_blendMode);
|
||||
CGContextSetFillColorWithColor(_context,_fillColor);
|
||||
CGContextSetStrokeColorWithColor(_context,_strokeColor);
|
||||
CGContextSetLineWidth(_context,_lineWidth);
|
||||
CGContextSetLineCap(_context,_lineCap);
|
||||
CGContextSetLineJoin(_context,_lineJoin);
|
||||
CGContextSetMiterLimit(_context,_miterLimit);
|
||||
CGContextSetLineDash(_context,_dashPhase,_dashLengths,_dashLengthsCount);
|
||||
CGContextSetFlatness(_context,_flatness);
|
||||
[self establishContextState];
|
||||
CGContextBeginPath(_context);
|
||||
CGContextAddPath(_context,path);
|
||||
|
||||
@ -320,15 +327,7 @@ static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRa
|
||||
CGContextSaveGState(_context);
|
||||
CGContextClearRect(_context,CGRectMake(0,0,400,400));
|
||||
CGContextConcatCTM(_context,ctm);
|
||||
CGContextSetShouldAntialias(_context,_shouldAntialias);
|
||||
CGContextSetFillColorWithColor(_context,_fillColor);
|
||||
CGContextSetStrokeColorWithColor(_context,_strokeColor);
|
||||
CGContextSetLineWidth(_context,_lineWidth);
|
||||
CGContextSetLineCap(_context,_lineCap);
|
||||
CGContextSetLineJoin(_context,_lineJoin);
|
||||
CGContextSetMiterLimit(_context,_miterLimit);
|
||||
CGContextSetLineDash(_context,_dashPhase,_dashLengths,_dashLengthsCount);
|
||||
CGContextSetFlatness(_context,_flatness);
|
||||
[self establishContextState];
|
||||
|
||||
for(i=0;i<limit;i++){
|
||||
CGMutablePathRef path=CGPathCreateMutable();
|
||||
@ -368,6 +367,22 @@ static void addSliceToPath(CGMutablePathRef path,float innerRadius,float outerRa
|
||||
CGContextRestoreGState(_context);
|
||||
}
|
||||
|
||||
-(void)drawPDF {
|
||||
CGAffineTransform ctm=[self ctm];
|
||||
CGContextSaveGState(_context);
|
||||
CGContextClearRect(_context,CGRectMake(0,0,400,400));
|
||||
ctm=CGAffineTransformTranslate(ctm,-200,-200);
|
||||
CGContextConcatCTM(_context,ctm);
|
||||
|
||||
if(_pdfDocument!=NULL){
|
||||
CGPDFPageRef page=CGPDFDocumentGetPage(_pdfDocument,1);
|
||||
|
||||
CGContextDrawPDFPage(_context,page);
|
||||
// CGPDFPageRelease(page);
|
||||
}
|
||||
CGContextRestoreGState(_context);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
-(void)drawSampleInRender:(KGRender *)render {
|
||||
|
@ -39,6 +39,8 @@
|
||||
<string>id</string>
|
||||
<key>selectLineWidth</key>
|
||||
<string>id</string>
|
||||
<key>selectPDFPath</key>
|
||||
<string>id</string>
|
||||
<key>selectPathDrawingMode</key>
|
||||
<string>id</string>
|
||||
<key>selectRotation</key>
|
||||
|
@ -10,8 +10,8 @@
|
||||
<integer>5</integer>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>2</integer>
|
||||
<integer>29</integer>
|
||||
<integer>21</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>9C31</string>
|
||||
|
Binary file not shown.
@ -50,4 +50,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-(void)selectAntialias:sender;
|
||||
-(void)selectInterpolationQuality:sender;
|
||||
|
||||
-(void)selectPDFPath:sender;
|
||||
|
||||
@end
|
||||
|
@ -48,6 +48,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
case 3:
|
||||
[self performTest:@selector(drawBitmapImageRep) withObject:nil];
|
||||
break;
|
||||
|
||||
case 4:
|
||||
[self performTest:@selector(drawPDF) withObject:nil];
|
||||
break;
|
||||
}
|
||||
|
||||
CGDataProviderRef provider;
|
||||
@ -68,7 +72,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
[_kgView setImageRef:image];
|
||||
CGImageRelease(image);
|
||||
}
|
||||
// [_diffView setImageRef:[_kgRender imageRefOfDifferences:_cgRender]];
|
||||
|
||||
if(_cgContext!=nil && _kgContext!=nil){
|
||||
unsigned char *cgData=[_cgContext bytes];
|
||||
unsigned char *kgData=[_kgContext bytes];
|
||||
|
||||
char *diff=NSZoneMalloc([self zone],[_kgContext bytesPerRow]*[_kgContext pixelsHigh]);
|
||||
int i;
|
||||
for(i=0;i<[_kgContext bytesPerRow]*[_kgContext pixelsHigh];i++){
|
||||
int d1=cgData[i];
|
||||
int d2=kgData[i];
|
||||
|
||||
diff[i]=(d1!=d2)?0xFF:00;
|
||||
|
||||
}
|
||||
CGDataProviderRef provider=CGDataProviderCreateWithData(NULL,diff,[_cgContext bytesPerRow]*[_cgContext pixelsHigh],NULL);
|
||||
CGImageRef diffImage=CGImageCreate([_cgContext pixelsWide],[_cgContext pixelsHigh],[_cgContext bitsPerComponent],[_cgContext bitsPerPixel],[_cgContext bytesPerRow],CGColorSpaceCreateDeviceRGB(),
|
||||
[_kgContext bitmapInfo],provider,NULL,NO,kCGRenderingIntentDefault);
|
||||
[_diffView setImageRef:diffImage];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)awakeFromNib {
|
||||
@ -252,4 +277,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
-(void)selectPDFPath:sender {
|
||||
NSOpenPanel *openPanel=[NSOpenPanel openPanel];
|
||||
|
||||
if([openPanel runModalForTypes:[NSArray arrayWithObject:@"pdf"]]){
|
||||
NSData *data=[NSData dataWithContentsOfFile:[openPanel filename]];
|
||||
[_cgContext setPDFData:data];
|
||||
[_kgContext setPDFData:data];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user