gui/branches/ericwa-opal: copy in opal source/headers

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/ericwa-opal@34156 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2011-11-11 01:03:24 +00:00
parent 5a96e7e794
commit a1e52475a9
148 changed files with 24160 additions and 0 deletions

View file

@ -0,0 +1,224 @@
/** <title>CGAffineTransform</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGAffineTransform_h
#define OPAL_CGAffineTransform_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGGeometry.h>
/* Data Types */
typedef struct CGAffineTransform
{
CGFloat a;
CGFloat b;
CGFloat c;
CGFloat d;
CGFloat tx;
CGFloat ty;
} CGAffineTransform;
/* Constants */
extern const CGAffineTransform CGAffineTransformIdentity;
/* Functions */
/* All but the most complex functions are declared static inline in this
* header file so that they are maximally efficient. In order to provide
* true functions (for code modules that don't have this header) this
* header is included in CGAffineTransform.c where the functions are no longer
* declared inline.
*/
#ifdef IN_CGAFFINETRANSFORM_C
#define GS_AFTR_SCOPE extern
#define GS_AFTR_ATTR
#else
#define GS_AFTR_SCOPE static inline
#define GS_AFTR_ATTR __attribute__((unused))
#endif
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMake(
CGFloat a,
CGFloat b,
CGFloat c,
CGFloat d,
CGFloat tx,
CGFloat ty
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeTranslation(
CGFloat tx,
CGFloat ty
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeScale(
CGFloat sx,
CGFloat sy
) GS_AFTR_ATTR;
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle);
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformConcat(
CGAffineTransform t1,
CGAffineTransform t2
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformTranslate(
CGAffineTransform t,
CGFloat tx,
CGFloat ty
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformScale(
CGAffineTransform t,
CGFloat sx,
CGFloat sy
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformRotate(
CGAffineTransform t,
CGFloat angle
) GS_AFTR_ATTR;
CGAffineTransform CGAffineTransformInvert(CGAffineTransform t);
GS_AFTR_SCOPE CGPoint CGPointApplyAffineTransform(
CGPoint point,
CGAffineTransform t
) GS_AFTR_ATTR;
GS_AFTR_SCOPE CGSize CGSizeApplyAffineTransform(
CGSize size,
CGAffineTransform t
) GS_AFTR_ATTR;
CGRect CGRectApplyAffineTransform(
CGRect rect,
CGAffineTransform t
);
/* Inlined functions */
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMake(
CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty)
{
CGAffineTransform matrix;
matrix.a = a;
matrix.b = b;
matrix.c = c;
matrix.d = d;
matrix.tx = tx;
matrix.ty = ty;
return matrix;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeTranslation(
CGFloat tx, CGFloat ty)
{
CGAffineTransform matrix;
matrix = CGAffineTransformIdentity;
matrix.tx = tx;
matrix.ty = ty;
return matrix;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)
{
CGAffineTransform matrix;
matrix = CGAffineTransformIdentity;
matrix.a = sx;
matrix.d = sy;
return matrix;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformConcat(
CGAffineTransform t1, CGAffineTransform t2)
{
CGAffineTransform t;
t.a = t1.a * t2.a + t1.b * t2.c;
t.b = t1.a * t2.b + t1.b * t2.d;
t.c = t1.c * t2.a + t1.d * t2.c;
t.d = t1.c * t2.b + t1.d * t2.d;
t.tx = t1.tx * t2.a + t1.ty * t2.c + t2.tx;
t.ty = t1.tx * t2.b + t1.ty * t2.d + t2.ty;
return t;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformTranslate(
CGAffineTransform t, CGFloat tx, CGFloat ty)
{
t.tx += tx * t.a + ty * t.c;
t.ty += tx * t.b + ty * t.d;
return t;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformScale(
CGAffineTransform t, CGFloat sx, CGFloat sy)
{
t.a *= sx;
t.b *= sx;
t.c *= sy;
t.d *= sy;
return t;
}
GS_AFTR_SCOPE CGAffineTransform CGAffineTransformRotate(
CGAffineTransform t, CGFloat angle)
{
return CGAffineTransformConcat(CGAffineTransformMakeRotation(angle), t);
}
GS_AFTR_SCOPE CGPoint CGPointApplyAffineTransform(
CGPoint point, CGAffineTransform t)
{
return CGPointMake(t.a * point.x + t.c * point.y + t.tx,
t.b * point.x + t.d * point.y + t.ty);
}
GS_AFTR_SCOPE CGSize CGSizeApplyAffineTransform(
CGSize size, CGAffineTransform t)
{
CGSize r;
r = CGSizeMake(t.a * size.width + t.c * size.height,
t.b * size.width + t.d * size.height);
if (r.width < 0) r.width = -r.width;
if (r.height < 0) r.height = -r.height;
return r;
}
#endif /* OPAL_CGAffineTransform_h */

View file

@ -0,0 +1,160 @@
/** <title>CGBase</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Jan 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGBase_h
#define OPAL_CGBase_h
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
// for off_t
#include <sys/types.h>
// Note: GNUstep Foundation defines CGFloat
#import <Foundation/Foundation.h>
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
/* Typedefs for CoreFoundation types */
typedef signed long CFIndex;
typedef unsigned long CFTypeID;
typedef NSRange CFRange;
typedef NSComparisonResult CFComparisonResult;
#ifdef __OBJC__
@class NSObject;
typedef NSObject *CFTypeRef;
#else
typedef struct NSObject * CFTypeRef;
#endif
#ifdef __OBJC__
@class NSString;
@class NSMutableString;
typedef NSString* CFStringRef;
typedef NSMutableString* CFMutableStringRef;
#else
typedef const struct __CFString * CFStringRef;
typedef struct __CFString * CFMutableStringRef;
#endif
#ifdef __OBJC__
@class NSAttributedString;
@class NSMutableAttributedString;
typedef NSAttributedString* CFAttributedStringRef;
typedef NSMutableAttributedString* CFMutableAttributedStringRef;
#else
typedef struct CFAttributedString * CFAttributedStringRef;
typedef struct CFMutableAttributedString * CFMutableAttributedStringRef;
#endif
#ifdef __OBJC__
@class NSArray;
@class NSMutableArray;
typedef NSArray* CFArrayRef;
typedef NSMutableArray* CFMutableArrayRef;
#else
typedef struct CFArray *CFArrayRef;
typedef struct CFArray *CFMutableArrayRef;
#endif
#ifdef __OBJC__
@class NSCharacterSet;
typedef NSCharacterSet* CFCharacterSetRef;
#else
typedef struct CFCharacterSet * CFCharacterSetRef;
#endif
#ifdef __OBJC__
@class NSData;
@class NSMutableData;
typedef NSData* CFDataRef;
typedef NSMutableData* CFMutableDataRef;
#else
typedef struct CFData *CFDataRef;
typedef struct CFMutableData *CFMutableDataRef;
#endif
#ifdef __OBJC__
@class NSDate;
@class NSTimeZone;
typedef NSDate* CFDateRef;
typedef NSTimeZone* CFTimeZoneRef;
#else
typedef struct CFDate *CFDateRef;
typedef struct CFTimeZone *CFTimeZoneRef;
#endif
#ifdef __OBJC__
@class NSDictionary;
@class NSMutableDictionary;
typedef NSDictionary* CFDictionaryRef;
typedef NSMutableDictionary* CFMutableDictionaryRef;
#else
typedef struct CFDictionary * CFDictionaryRef;
typedef struct CFMutableDictionary * CFMutableDictionaryRef;
#endif
#ifdef __OBJC__
@class NSError;
typedef NSError* CFErrorRef;
#else
typedef struct CFError *CFErrorRef;
#endif
#ifdef __OBJC__
@class NSNumber;
typedef NSNumber* CFNumberRef;
#else
typedef struct NSNumber * CFNumberRef;
#endif
#ifdef __OBJC__
@class NSSet;
@class NSMutableSet;
typedef NSSet* CFSetRef;
typedef NSMutableSet* CFMutableSetRef;
#else
typedef struct CFSet * CFSetRef;
typedef struct CFMutableSet * CFMutableSetRef;
#endif
#ifdef __OBJC__
@class NSURL;
typedef NSURL *CFURLRef;
#else
typedef struct CFURL *CFURLRef;
#endif
#endif /* OPAL_CGBase_h */

View file

@ -0,0 +1,82 @@
/** <title>CGBitmapContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGBitmapContext_h
#define OPAL_CGBitmapContext_h
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGImage.h>
/* Callbacks */
typedef void (*CGBitmapContextReleaseDataCallback)(
void *releaseInfo,
void *data
);
/* Functions */
CGContextRef CGBitmapContextCreate(
void *data,
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bytesPerRow,
CGColorSpaceRef colorspace,
CGBitmapInfo info
);
CGContextRef CGBitmapContextCreateWithData(
void *data,
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bytesPerRow,
CGColorSpaceRef cs,
CGBitmapInfo info,
CGBitmapContextReleaseDataCallback callback,
void *releaseInfo
);
CGImageAlphaInfo CGBitmapContextGetAlphaInfo(CGContextRef ctx);
CGBitmapInfo CGBitmapContextGetBitmapInfo(CGContextRef context);
size_t CGBitmapContextGetBitsPerComponent (CGContextRef ctx);
size_t CGBitmapContextGetBitsPerPixel (CGContextRef ctx);
size_t CGBitmapContextGetBytesPerRow (CGContextRef ctx);
CGColorSpaceRef CGBitmapContextGetColorSpace(CGContextRef ctx);
void *CGBitmapContextGetData(CGContextRef ctx);
size_t CGBitmapContextGetHeight(CGContextRef ctx);
size_t CGBitmapContextGetWidth(CGContextRef ctx);
CGImageRef CGBitmapContextCreateImage(CGContextRef ctx);
#endif /* OPAL_CGBitmapContext_h */

View file

@ -0,0 +1,98 @@
/** <title>CGColor</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGColor_h
#define OPAL_CGColor_h
/* Data Types */
#ifdef __OBJC__
@class CGColor;
typedef CGColor* CGColorRef;
#else
typedef struct CGColor* CGColorRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGColorSpace.h>
#include <CoreGraphics/CGPattern.h>
/* Constants */
const extern CFStringRef kCGColorWhite;
const extern CFStringRef kCGColorBlack;
const extern CFStringRef kCGColorClear;
/* Functions */
CGColorRef CGColorCreate(CGColorSpaceRef colorspace, const CGFloat components[]);
CGColorRef CGColorCreateCopy(CGColorRef clr);
CGColorRef CGColorCreateCopyWithAlpha(CGColorRef clr, CGFloat alpha);
CGColorRef CGColorCreateGenericCMYK(
CGFloat cyan,
CGFloat magenta,
CGFloat yellow,
CGFloat black,
CGFloat alpha
);
CGColorRef CGColorCreateGenericGray(CGFloat gray, CGFloat alpha);
CGColorRef CGColorCreateGenericRGB(
CGFloat red,
CGFloat green,
CGFloat blue,
CGFloat alpha
);
CGColorRef CGColorCreateWithPattern(
CGColorSpaceRef colorspace,
CGPatternRef pattern,
const CGFloat components[]
);
bool CGColorEqualToColor(CGColorRef color1, CGColorRef color2);
CGFloat CGColorGetAlpha(CGColorRef clr);
CGColorSpaceRef CGColorGetColorSpace(CGColorRef clr);
const CGFloat *CGColorGetComponents(CGColorRef clr);
CGColorRef CGColorGetConstantColor(CFStringRef name);
size_t CGColorGetNumberOfComponents(CGColorRef clr);
CGPatternRef CGColorGetPattern(CGColorRef clr);
CFTypeID CGColorGetTypeID();
void CGColorRelease(CGColorRef clr);
CGColorRef CGColorRetain(CGColorRef clr);
#endif /* OPAL_CGColor_h */

View file

@ -0,0 +1,142 @@
/** <title>CGColorSpace</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGColorSpace_h
#define OPAL_CGColorSpace_h
#import <Foundation/NSObject.h>
/* Data Types */
#ifdef __OBJC__
@protocol CGColorSpace;
typedef id <CGColorSpace, NSObject>CGColorSpaceRef;
#else
typedef struct CGColorSpace* CGColorSpaceRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGDataProvider.h>
typedef enum CGColorSpaceModel {
kCGColorSpaceModelUnknown = -1,
kCGColorSpaceModelMonochrome = 0,
kCGColorSpaceModelRGB = 1,
kCGColorSpaceModelCMYK = 2,
kCGColorSpaceModelLab = 3,
kCGColorSpaceModelDeviceN = 4,
kCGColorSpaceModelIndexed = 5,
kCGColorSpaceModelPattern = 6
} CGColorSpaceModel;
/* Constants */
typedef enum CGColorRenderingIntent {
kCGRenderingIntentDefault = 0,
kCGRenderingIntentAbsoluteColorimetric = 1,
kCGRenderingIntentRelativeColorimetric = 2,
kCGRenderingIntentPerceptual = 3,
kCGRenderingIntentSaturation = 4
} CGColorRenderingIntent;
extern const CFStringRef kCGColorSpaceGenericGray;
extern const CFStringRef kCGColorSpaceGenericRGB;
extern const CFStringRef kCGColorSpaceGenericCMYK;
extern const CFStringRef kCGColorSpaceGenericRGBLinear;
extern const CFStringRef kCGColorSpaceAdobeRGB1998;
extern const CFStringRef kCGColorSpaceSRGB;
extern const CFStringRef kCGColorSpaceGenericGrayGamma2_2;
/* Functions */
CFDataRef CGColorSpaceCopyICCProfile(CGColorSpaceRef cs);
CFStringRef CGColorSpaceCopyName(CGColorSpaceRef cs);
CGColorSpaceRef CGColorSpaceCreateCalibratedGray(
const CGFloat whitePoint[3],
const CGFloat blackPoint[3],
CGFloat gamma
);
CGColorSpaceRef CGColorSpaceCreateCalibratedRGB(
const CGFloat whitePoint[3],
const CGFloat blackPoint[3],
const CGFloat gamma[3],
const CGFloat matrix[9]
);
CGColorSpaceRef CGColorSpaceCreateDeviceCMYK();
CGColorSpaceRef CGColorSpaceCreateDeviceGray();
CGColorSpaceRef CGColorSpaceCreateDeviceRGB();
CGColorSpaceRef CGColorSpaceCreateICCBased(
size_t nComponents,
const CGFloat *range,
CGDataProviderRef profile,
CGColorSpaceRef alternateSpace
);
CGColorSpaceRef CGColorSpaceCreateIndexed(
CGColorSpaceRef baseSpace,
size_t lastIndex,
const unsigned char *colorTable
);
CGColorSpaceRef CGColorSpaceCreateLab(
const CGFloat whitePoint[3],
const CGFloat blackPoint[3],
const CGFloat range[4]
);
CGColorSpaceRef CGColorSpaceCreatePattern(CGColorSpaceRef baseSpace);
CGColorSpaceRef CGColorSpaceCreateWithICCProfile(CFDataRef data);
CGColorSpaceRef CGColorSpaceCreateWithName(CFStringRef name);
CGColorSpaceRef CGColorSpaceCreateWithPlatformColorSpace(
void *platformColorSpace
);
CGColorSpaceRef CGColorSpaceGetBaseColorSpace(CGColorSpaceRef cs);
void CGColorSpaceGetColorTable(CGColorSpaceRef cs, unsigned char *table);
size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef cs);
CGColorSpaceModel CGColorSpaceGetModel(CGColorSpaceRef cs);
size_t CGColorSpaceGetNumberOfComponents(CGColorSpaceRef cs);
CFTypeID CGColorSpaceGetTypeID();
CGColorSpaceRef CGColorSpaceRetain(CGColorSpaceRef cs);
void CGColorSpaceRelease(CGColorSpaceRef cs);
#endif /* OPAL_CGColorSpace_h */

View file

@ -0,0 +1,558 @@
/** <title>CGContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGContext_h
#define OPAL_CGContext_h
/* Data Types */
#ifdef __OBJC__
@class CGContext;
typedef CGContext* CGContextRef;
#else
typedef struct CGContext* CGContextRef;
#endif
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGBitmapContext.h>
#include <CoreGraphics/CGColor.h>
#include <CoreGraphics/CGFont.h>
#include <CoreGraphics/CGImage.h>
#include <CoreGraphics/CGPath.h>
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFDocument.h>
#include <CoreGraphics/CGPDFPage.h>
#include <CoreGraphics/CGGradient.h>
#include <CoreGraphics/CGShading.h>
/* Constants */
typedef enum CGBlendMode {
kCGBlendModeNormal = 0,
kCGBlendModeMultiply = 1,
kCGBlendModeScreen = 2,
kCGBlendModeOverlay = 3,
kCGBlendModeDarken = 4,
kCGBlendModeLighten = 5,
kCGBlendModeColorDodge = 6,
kCGBlendModeColorBurn = 7,
kCGBlendModeSoftLight = 8,
kCGBlendModeHardLight = 9,
kCGBlendModeDifference = 10,
kCGBlendModeExclusion = 11,
kCGBlendModeHue = 12,
kCGBlendModeSaturation = 13,
kCGBlendModeColor = 14,
kCGBlendModeLuminosity = 15,
kCGBlendModeClear = 16,
kCGBlendModeCopy = 17,
kCGBlendModeSourceIn = 18,
kCGBlendModeSourceOut = 19,
kCGBlendModeSourceAtop = 20,
kCGBlendModeDestinationOver = 21,
kCGBlendModeDestinationIn = 22,
kCGBlendModeDestinationOut = 23,
kCGBlendModeDestinationAtop = 24,
kCGBlendModeXOR = 25,
kCGBlendModePlusDarker = 26,
kCGBlendModePlusLighter = 27
} CGBlendMode;
typedef enum CGInterpolationQuality {
kCGInterpolationDefault = 0,
kCGInterpolationNone = 1,
kCGInterpolationLow = 2,
kCGInterpolationMedium = 4,
kCGInterpolationHigh = 3
} CGInterpolationQuality;
typedef enum CGLineCap {
kCGLineCapButt = 0,
kCGLineCapRound = 1,
kCGLineCapSquare = 2
} CGLineCap;
typedef enum CGLineJoin {
kCGLineJoinMiter = 0,
kCGLineJoinRound = 1,
kCGLineJoinBevel = 2
} CGLineJoin;
typedef enum CGPathDrawingMode {
kCGPathFill = 0,
kCGPathEOFill = 1,
kCGPathStroke = 2,
kCGPathFillStroke = 3,
kCGPathEOFillStroke = 4
} CGPathDrawingMode;
typedef enum CGTextDrawingMode {
kCGTextFill = 0,
kCGTextStroke = 1,
kCGTextFillStroke = 2,
kCGTextInvisible = 3,
kCGTextFillClip = 4,
kCGTextStrokeClip = 5,
kCGTextFillStrokeClip = 6,
kCGTextClip = 7
} CGTextDrawingMode;
typedef enum CGTextEncoding {
kCGEncodingFontSpecific = 0,
kCGEncodingMacRoman = 1
} CGTextEncoding;
/* Functions */
/* Managing Graphics Contexts */
CFTypeID CGContextGetTypeID();
CGContextRef CGContextRetain(CGContextRef ctx);
void CGContextRelease(CGContextRef ctx);
void CGContextFlush(CGContextRef ctx);
void CGContextSynchronize(CGContextRef ctx);
/* Defining Pages */
void CGContextBeginPage(CGContextRef ctx, const CGRect *mediaBox);
void CGContextEndPage(CGContextRef ctx);
/* Transforming the Coordinate Space of the Page */
void CGContextScaleCTM(CGContextRef ctx, CGFloat sx, CGFloat sy);
void CGContextTranslateCTM(CGContextRef ctx, CGFloat tx, CGFloat ty);
void CGContextRotateCTM(CGContextRef ctx, CGFloat angle);
void CGContextConcatCTM(CGContextRef ctx, CGAffineTransform transform);
CGAffineTransform CGContextGetCTM(CGContextRef ctx);
/* Saving and Restoring the Graphics State */
void CGContextSaveGState(CGContextRef ctx);
void CGContextRestoreGState(CGContextRef ctx);
/* Setting Graphics State Attributes */
void CGContextSetShouldAntialias(CGContextRef ctx, int shouldAntialias);
void CGContextSetLineWidth(CGContextRef ctx, CGFloat width);
void CGContextSetLineJoin(CGContextRef ctx, CGLineJoin join);
void CGContextSetMiterLimit(CGContextRef ctx, CGFloat limit);
void CGContextSetLineCap(CGContextRef ctx, CGLineCap cap);
void CGContextSetLineDash(
CGContextRef ctx,
CGFloat phase,
const CGFloat lengths[],
size_t count
);
void CGContextSetFlatness(CGContextRef ctx, CGFloat flatness);
CGInterpolationQuality CGContextGetInterpolationQuality(CGContextRef ctx);
void CGContextSetInterpolationQuality(
CGContextRef ctx,
CGInterpolationQuality quality
);
void CGContextSetPatternPhase (CGContextRef ctx, CGSize phase);
void CGContextSetFillPattern(
CGContextRef ctx,
CGPatternRef pattern,
const CGFloat components[]
);
void CGContextSetStrokePattern(
CGContextRef ctx,
CGPatternRef pattern,
const CGFloat components[]
);
void CGContextSetShouldSmoothFonts(CGContextRef ctx, int shouldSmoothFonts);
void CGContextSetAllowsFontSmoothing(CGContextRef ctx, bool allowsFontSmoothing);
void CGContextSetBlendMode(CGContextRef ctx, CGBlendMode mode);
void CGContextSetAllowsAntialiasing(CGContextRef ctx, int allowsAntialiasing);
void CGContextSetShouldSubpixelPositionFonts(
CGContextRef ctx,
bool shouldSubpixelPositionFonts
);
void CGContextSetAllowsFontSubpixelPositioning(
CGContextRef ctx,
bool allowsFontSubpixelPositioning
);
void CGContextSetShouldSubpixelQuantizeFonts(
CGContextRef ctx,
bool shouldSubpixelQuantizeFonts
);
void CGContextSetAllowsFontSubpixelQuantization(
CGContextRef ctx,
bool allowsFontSubpixelQuantization
);
void CGContextSetShadow(
CGContextRef ctx,
CGSize offset,
CGFloat radius
);
void CGContextSetShadowWithColor(
CGContextRef ctx,
CGSize offset,
CGFloat radius,
CGColorRef color
);
/* Constructing Paths */
void CGContextBeginPath(CGContextRef ctx);
void CGContextClosePath(CGContextRef ctx);
void CGContextMoveToPoint(CGContextRef ctx, CGFloat x, CGFloat y);
void CGContextAddLineToPoint(CGContextRef ctx, CGFloat x, CGFloat y);
void CGContextAddLines(CGContextRef ctx, const CGPoint points[], size_t count);
void CGContextAddCurveToPoint(
CGContextRef ctx,
CGFloat cp1x,
CGFloat cp1y,
CGFloat cp2x,
CGFloat cp2y,
CGFloat x,
CGFloat y
);
void CGContextAddQuadCurveToPoint(
CGContextRef ctx,
CGFloat cpx,
CGFloat cpy,
CGFloat x,
CGFloat y
);
void CGContextAddRect(CGContextRef ctx, CGRect rect);
void CGContextAddRects(CGContextRef ctx, const CGRect rects[], size_t count);
void CGContextAddArc(
CGContextRef ctx,
CGFloat x,
CGFloat y,
CGFloat radius,
CGFloat startAngle,
CGFloat endAngle,
int clockwise
);
void CGContextAddArcToPoint(
CGContextRef ctx,
CGFloat x1,
CGFloat y1,
CGFloat x2,
CGFloat y2,
CGFloat radius
);
void CGContextAddPath(CGContextRef ctx, CGPathRef path);
void CGContextAddEllipseInRect(CGContextRef ctx, CGRect rect);
/* Creating Stroked Paths */
void CGContextReplacePathWithStrokedPath(CGContextRef ctx);
/* Painting Paths */
void CGContextStrokePath(CGContextRef ctx);
void CGContextFillPath(CGContextRef ctx);
void CGContextEOFillPath(CGContextRef ctx);
void CGContextDrawPath(CGContextRef ctx, CGPathDrawingMode mode);
void CGContextStrokeRect(CGContextRef ctx, CGRect rect);
void CGContextStrokeRectWithWidth(CGContextRef ctx, CGRect rect, CGFloat width);
void CGContextFillRect(CGContextRef ctx, CGRect rect);
void CGContextFillRects(CGContextRef ctx, const CGRect rects[], size_t count);
void CGContextClearRect(CGContextRef ctx, CGRect rect);
void CGContextFillEllipseInRect(CGContextRef ctx, CGRect rect);
void CGContextStrokeEllipseInRect(CGContextRef ctx, CGRect rect);
void CGContextStrokeLineSegments(
CGContextRef ctx,
const CGPoint points[],
size_t count
);
/* Obtaining Path Information */
bool CGContextIsPathEmpty(CGContextRef ctx);
CGPoint CGContextGetPathCurrentPoint(CGContextRef ctx);
CGRect CGContextGetPathBoundingBox(CGContextRef ctx);
CGPathRef CGContextCopyPath(CGContextRef context);
/* Clipping Paths */
void CGContextClip(CGContextRef ctx);
void CGContextEOClip(CGContextRef ctx);
void CGContextClipToRect(CGContextRef ctx, CGRect rect);
void CGContextClipToRects(CGContextRef ctx, const CGRect rects[], size_t count);
void CGContextClipToMask(CGContextRef ctx, CGRect rect, CGImageRef mask);
CGRect CGContextGetClipBoundingBox(CGContextRef ctx);
/* Setting the Color Space and Colors */
void CGContextSetFillColorWithColor(CGContextRef ctx, CGColorRef color);
void CGContextSetStrokeColorWithColor(CGContextRef ctx, CGColorRef color);
void CGContextSetAlpha(CGContextRef ctx, CGFloat alpha);
void CGContextSetFillColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace);
void CGContextSetStrokeColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace);
void CGContextSetFillColor(CGContextRef ctx, const CGFloat components[]);
void CGContextSetStrokeColor(CGContextRef ctx, const CGFloat components[]);
void CGContextSetGrayFillColor(CGContextRef ctx, CGFloat gray, CGFloat alpha);
void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, CGFloat alpha);
void CGContextSetRGBFillColor(
CGContextRef ctx,
CGFloat r,
CGFloat g,
CGFloat b,
CGFloat alpha
);
void CGContextSetRGBStrokeColor(
CGContextRef ctx,
CGFloat r,
CGFloat g,
CGFloat b,
CGFloat alpha
);
void CGContextSetCMYKFillColor(
CGContextRef ctx,
CGFloat c,
CGFloat m,
CGFloat y,
CGFloat k,
CGFloat alpha
);
void CGContextSetCMYKStrokeColor(
CGContextRef ctx,
CGFloat c,
CGFloat m,
CGFloat y,
CGFloat k,
CGFloat alpha
);
void CGContextSetRenderingIntent(CGContextRef ctx, CGColorRenderingIntent intent);
/* Drawing Images */
void CGContextDrawImage(CGContextRef ctx, CGRect rect, CGImageRef image);
void CGContextDrawTiledImage(CGContextRef ctx, CGRect rect, CGImageRef image);
/* Drawing PDF Documents */
void CGContextDrawPDFDocument(
CGContextRef ctx,
CGRect rect,
CGPDFDocumentRef document,
int page
);
void CGContextDrawPDFPage(CGContextRef ctx, CGPDFPageRef page);
/* Drawing Gradients */
void CGContextDrawLinearGradient(
CGContextRef ctx,
CGGradientRef gradient,
CGPoint startPoint,
CGPoint endPoint,
CGGradientDrawingOptions options
);
void CGContextDrawRadialGradient(
CGContextRef ctx,
CGGradientRef gradient,
CGPoint startCenter,
CGFloat startRadius,
CGPoint endCenter,
CGFloat endRadius,
CGGradientDrawingOptions options
);
void CGContextDrawShading(
CGContextRef ctx,
CGShadingRef shading
);
/* Drawing Text */
void CGContextSetFont(CGContextRef ctx, CGFontRef font);
void CGContextSetFontSize(CGContextRef ctx, CGFloat size);
void CGContextSelectFont(
CGContextRef ctx,
const char *name,
CGFloat size,
CGTextEncoding textEncoding
);
void CGContextSetCharacterSpacing(CGContextRef ctx, CGFloat spacing);
void CGContextSetTextDrawingMode(CGContextRef ctx, CGTextDrawingMode mode);
void CGContextSetTextPosition(CGContextRef ctx, CGFloat x, CGFloat y);
CGPoint CGContextGetTextPosition(CGContextRef ctx);
void CGContextSetTextMatrix(CGContextRef ctx, CGAffineTransform transform);
CGAffineTransform CGContextGetTextMatrix(CGContextRef ctx);
void CGContextShowText(CGContextRef ctx, const char *cstring, size_t length);
void CGContextShowTextAtPoint(
CGContextRef ctx,
CGFloat x,
CGFloat y,
const char *cstring,
size_t length
);
void CGContextShowGlyphs(CGContextRef ctx, const CGGlyph *g, size_t count);
void CGContextShowGlyphsAtPoint(
CGContextRef ctx,
CGFloat x,
CGFloat y,
const CGGlyph *g,
size_t count
);
void CGContextShowGlyphsAtPositions(
CGContextRef context,
const CGGlyph glyphs[],
const CGPoint positions[],
size_t count
);
void CGContextShowGlyphsWithAdvances (
CGContextRef c,
const CGGlyph glyphs[],
const CGSize advances[],
size_t count
);
/* Transparency Layers */
void CGContextBeginTransparencyLayer(
CGContextRef ctx,
CFDictionaryRef auxiliaryInfo
);
void CGContextBeginTransparencyLayerWithRect(
CGContextRef ctx,
CGRect rect,
CFDictionaryRef auxiliaryInfo
);
void CGContextEndTransparencyLayer(CGContextRef ctx);
/* User to Device Transformation */
CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef ctx);
CGPoint CGContextConvertPointToDeviceSpace(CGContextRef ctx, CGPoint point);
CGPoint CGContextConvertPointToUserSpace(CGContextRef ctx, CGPoint point);
CGSize CGContextConvertSizeToDeviceSpace(CGContextRef ctx, CGSize size);
CGSize CGContextConvertSizeToUserSpace(CGContextRef ctx, CGSize size);
CGRect CGContextConvertRectToDeviceSpace(CGContextRef ctx, CGRect rect);
CGRect CGContextConvertRectToUserSpace(CGContextRef ctx, CGRect rect);
/* Opal Extensions */
// FIXME: Move extensions to a separate header?
void OpalContextSetScaleFactor(CGContextRef ctx, CGFloat scale);
#endif /* OPAL_CGContext_h */

View file

@ -0,0 +1,72 @@
/** <title>CGDataConsumer</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGDataConsumer_h
#define OPAL_CGDataConsumer_h
/* Data Types */
#ifdef __OBJC__
@class CGDataConsumer;
typedef CGDataConsumer* CGDataConsumerRef;
#else
typedef struct CGDataConsumer* CGDataConsumerRef;
#endif
#include <CoreGraphics/CGBase.h>
/* Callbacks */
typedef size_t (*CGDataConsumerPutBytesCallback)(
void *info,
const void *buffer,
size_t count
);
typedef void (*CGDataConsumerReleaseInfoCallback)(void *info);
typedef struct CGDataConsumerCallbacks
{
CGDataConsumerPutBytesCallback putBytes;
CGDataConsumerReleaseInfoCallback releaseConsumer;
} CGDataConsumerCallbacks;
/* Functions */
CGDataConsumerRef CGDataConsumerCreate(
void *info,
const CGDataConsumerCallbacks *callbacks
);
CGDataConsumerRef CGDataConsumerCreateWithCFData(CFMutableDataRef data);
CGDataConsumerRef CGDataConsumerCreateWithURL(CFURLRef url);
CFTypeID CGDataConsumerGetTypeID();
void CGDataConsumerRelease(CGDataConsumerRef consumer);
CGDataConsumerRef CGDataConsumerRetain(CGDataConsumerRef consumer);
#endif /* OPAL_CGDataConsumer_h */

View file

@ -0,0 +1,197 @@
/** <title>CGDataProvider</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGDataProvider_h
#define OPAL_CGDataProvider_h
/* Data Types */
#ifdef __OBJC__
@class CGDataProvider;
typedef CGDataProvider* CGDataProviderRef;
#else
typedef struct CGDataProvider* CGDataProviderRef;
#endif
#include <CoreGraphics/CGBase.h>
/* Callbacks */
/**
* Sequential data provider callbacks
*/
typedef size_t (*CGDataProviderGetBytesCallback)(
void *info,
void *buffer,
size_t count
);
typedef void (*CGDataProviderSkipBytesCallback)(void *info, size_t count);
typedef off_t (*CGDataProviderSkipForwardCallback)(
void *info,
off_t count
);
typedef void (*CGDataProviderRewindCallback)(void *info);
typedef void (*CGDataProviderReleaseInfoCallback)(void *info);
/**
* Direct access data provider callbacks
*/
typedef const void *(*CGDataProviderGetBytePointerCallback)(void *info);
typedef void (*CGDataProviderReleaseBytePointerCallback)(
void *info,
const void *pointer
);
typedef size_t (*CGDataProviderGetBytesAtOffsetCallback)(
void *info,
void *buffer,
size_t offset,
size_t count
);
typedef size_t (*CGDataProviderGetBytesAtPositionCallback)(
void *info,
void *buffer,
off_t position,
size_t count
);
/**
* Callback for CGDataProviderCreateWithData
*/
typedef void (*CGDataProviderReleaseDataCallback)(
void *info,
const void *data,
size_t size
);
/* Data Types */
/**
* Direct access callbacks structure
*/
typedef struct CGDataProviderDirectCallbacks
{
unsigned int version;
CGDataProviderGetBytePointerCallback getBytePointer;
CGDataProviderReleaseBytePointerCallback releaseBytePointer;
CGDataProviderGetBytesAtPositionCallback getBytesAtPosition;
CGDataProviderReleaseInfoCallback releaseInfo;
} CGDataProviderDirectCallbacks;
/**
* Deprecated direct access callbacks structure
*/
typedef struct CGDataProviderDirectAccessCallbacks
{
CGDataProviderGetBytePointerCallback getBytePointer;
CGDataProviderReleaseBytePointerCallback releaseBytePointer;
CGDataProviderGetBytesAtOffsetCallback getBytes;
CGDataProviderReleaseInfoCallback releaseProvider;
} CGDataProviderDirectAccessCallbacks;
/**
* Sequential callbacks structure
*/
typedef struct CGDataProviderSequentialCallbacks
{
unsigned int version;
CGDataProviderGetBytesCallback getBytes;
CGDataProviderSkipForwardCallback skipForward;
CGDataProviderRewindCallback rewind;
CGDataProviderReleaseInfoCallback releaseInfo;
} CGDataProviderSequentialCallbacks;
/**
* Deprecated sequential callbacks structure
*/
typedef struct CGDataProviderCallbacks
{
CGDataProviderGetBytesCallback getBytes;
CGDataProviderSkipBytesCallback skipBytes;
CGDataProviderRewindCallback rewind;
CGDataProviderReleaseInfoCallback releaseProvider;
} CGDataProviderCallbacks;
/* Functions */
CGDataProviderRef CGDataProviderCreateDirect(
void *info,
off_t size,
const CGDataProviderDirectCallbacks *callbacks
);
CGDataProviderRef CGDataProviderCreateSequential(
void *info,
const CGDataProviderSequentialCallbacks *callbacks
);
/**
* Deprecated
*/
CGDataProviderRef CGDataProviderCreateDirectAccess(
void *info,
size_t size,
const CGDataProviderDirectAccessCallbacks *callbacks
);
/**
* Deprecated
*/
CGDataProviderRef CGDataProviderCreate(
void *info,
const CGDataProviderCallbacks *callbacks
);
CGDataProviderRef CGDataProviderCreateWithData(
void *info,
const void *data,
size_t size,
void (*releaseData)(void *info, const void *data, size_t size)
);
CGDataProviderRef CGDataProviderCreateWithCFData(CFDataRef data);
CGDataProviderRef CGDataProviderCreateWithURL(CFURLRef url);
CGDataProviderRef CGDataProviderCreateWithFilename(const char *filename);
CFDataRef CGDataProviderCopyData(CGDataProviderRef provider);
CGDataProviderRef CGDataProviderRetain(CGDataProviderRef provider);
void CGDataProviderRelease(CGDataProviderRef provider);
CFTypeID CGDataProviderGetTypeID();
#endif /* OPAL_CGDataProvider_h */

View file

@ -0,0 +1,152 @@
/** <title>CGFont</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGFont_h
#define OPAL_CGFont_h
/* Data Types */
#ifdef __OBJC__
@class CGFont;
typedef CGFont* CGFontRef;
#else
typedef struct CGFont* CGFontRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGDataProvider.h>
typedef unsigned short CGGlyph;
typedef unsigned short CGFontIndex;
/* Constants */
enum {
kCGFontIndexMax = ((1 << 16) - 2),
kCGFontIndexInvalid = ((1 << 16) - 1),
kCGGlyphMax = kCGFontIndexMax
};
typedef enum CGFontPostScriptFormat {
kCGFontPostScriptFormatType1 = 1,
kCGFontPostScriptFormatType3 = 3,
kCGFontPostScriptFormatType42 = 42
} CGFontPostScriptFormat;
const extern CFStringRef kCGFontVariationAxisName;
const extern CFStringRef kCGFontVariationAxisMinValue;
const extern CFStringRef kCGFontVariationAxisMaxValue;
const extern CFStringRef kCGFontVariationAxisDefaultValue;
/* Functions */
bool CGFontCanCreatePostScriptSubset(
CGFontRef font,
CGFontPostScriptFormat format
);
CFStringRef CGFontCopyFullName(CGFontRef font);
CFStringRef CGFontCopyGlyphNameForGlyph(CGFontRef font, CGGlyph glyph);
CFStringRef CGFontCopyPostScriptName(CGFontRef font);
CFDataRef CGFontCopyTableForTag(CGFontRef font, uint32_t tag);
CFArrayRef CGFontCopyTableTags(CGFontRef font);
CFArrayRef CGFontCopyVariationAxes(CGFontRef font);
CFDictionaryRef CGFontCopyVariations(CGFontRef font);
CGFontRef CGFontCreateCopyWithVariations(
CGFontRef font,
CFDictionaryRef variations
);
CFDataRef CGFontCreatePostScriptEncoding(
CGFontRef font,
const CGGlyph encoding[256]
);
CFDataRef CGFontCreatePostScriptSubset(
CGFontRef font,
CFStringRef name,
CGFontPostScriptFormat format,
const CGGlyph glyphs[],
size_t count,
const CGGlyph encoding[256]
);
CGFontRef CGFontCreateWithDataProvider(CGDataProviderRef provider);
CGFontRef CGFontCreateWithFontName(CFStringRef name);
CGFontRef CGFontCreateWithPlatformFont(void *platformFontReference);
int CGFontGetAscent(CGFontRef font);
int CGFontGetCapHeight(CGFontRef font);
int CGFontGetDescent(CGFontRef font);
CGRect CGFontGetFontBBox(CGFontRef font);
bool CGFontGetGlyphAdvances(
CGFontRef font,
const CGGlyph glyphs[],
size_t count,
int advances[]
);
bool CGFontGetGlyphBBoxes(
CGFontRef font,
const CGGlyph glyphs[],
size_t count,
CGRect bboxes[]
);
CGGlyph CGFontGetGlyphWithGlyphName(CGFontRef font, CFStringRef glyphName);
CGFloat CGFontGetItalicAngle(CGFontRef font);
int CGFontGetLeading(CGFontRef font);
size_t CGFontGetNumberOfGlyphs(CGFontRef font);
CGFloat CGFontGetStemV(CGFontRef font);
int CGFontGetUnitsPerEm(CGFontRef font);
int CGFontGetXHeight(CGFontRef font);
CFTypeID CGFontGetTypeID();
CGFontRef CGFontRetain(CGFontRef font);
void CGFontRelease(CGFontRef font);
#endif /* OPAL_CGFont_h */

View file

@ -0,0 +1,70 @@
/** <title>CGFunction</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGFunction_h
#define OPAL_CGFunction_h
/* Data Types */
#ifdef __OBJC__
@class CGFunction;
typedef CGFunction* CGFunctionRef;
#else
typedef struct CGFunction* CGFunctionRef;
#endif
#include <CoreGraphics/CGBase.h>
/* Callbacks */
typedef void (*CGFunctionEvaluateCallback)(
void *info,
const CGFloat *inData,
CGFloat *outData
);
typedef void (*CGFunctionReleaseInfoCallback)(void *info);
typedef struct CGFunctionCallbacks {
unsigned int version;
CGFunctionEvaluateCallback evaluate;
CGFunctionReleaseInfoCallback releaseInfo;
} CGFunctionCallbacks;
/* Functions */
CGFunctionRef CGFunctionCreate(
void *info,
size_t domainDimension,
const CGFloat *domain,
size_t rangeDimension,
const CGFloat *range,
const CGFunctionCallbacks *callbacks
);
CGFunctionRef CGFunctionRetain(CGFunctionRef function);
void CGFunctionRelease(CGFunctionRef function);
#endif /* OPAL_CGFunction_h */

View file

@ -0,0 +1,364 @@
/** <title>CGGeometry</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 1995,2002 Free Software Foundation, Inc.
Author: Adam Fedor <fedor@gnu.org>
Author: BALATON Zoltan <balaton@eik.bme.hu>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGGeometry_h
#define OPAL_CGGeometry_h
#include <CoreGraphics/CGBase.h>
/* Data Types */
typedef struct CGPoint
{
CGFloat x;
CGFloat y;
} CGPoint;
typedef struct CGSize
{
CGFloat width;
CGFloat height;
} CGSize;
typedef struct CGRect
{
CGPoint origin;
CGSize size;
} CGRect;
/* Constants */
typedef enum CGRectEdge
{
CGRectMinXEdge = 0,
CGRectMinYEdge = 1,
CGRectMaxXEdge = 2,
CGRectMaxYEdge = 3
} CGRectEdge;
/** Point at 0,0 */
extern const CGPoint CGPointZero;
/** Zero size */
extern const CGSize CGSizeZero;
/** Zero-size rectangle at 0,0 */
extern const CGRect CGRectZero;
/** An invalid rectangle */
extern const CGRect CGRectNull;
/** A rectangle with infinite extent */
extern const CGRect CGRectInfinite;
/* Functions */
/* All but the most complex functions are declared static inline in this
* header file so that they are maximally efficient. In order to provide
* true functions (for code modules that don't have this header) this
* header is included in CGGeometry.c where the functions are no longer
* declared inline.
*/
#ifdef IN_CGGEOMETRY_C
#define OP_GEOM_SCOPE extern
#define OP_GEOM_ATTR
#else
#define OP_GEOM_SCOPE static inline
#define OP_GEOM_ATTR __attribute__((unused))
#endif
/* Creating and modifying Geometric Forms */
/** Returns a CGPoint having x-coordinate x and y-coordinate y. */
OP_GEOM_SCOPE CGPoint CGPointMake(CGFloat x, CGFloat y) OP_GEOM_ATTR;
/** Returns a CGSize having width width and height height. */
OP_GEOM_SCOPE CGSize CGSizeMake(CGFloat width, CGFloat height) OP_GEOM_ATTR;
/** Returns a CGRect having point of origin (x, y) and size (width, height). */
OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) OP_GEOM_ATTR;
/** Returns an equivalent rect which has positive width and heght. */
OP_GEOM_SCOPE CGRect CGRectStandardize(CGRect rect) OP_GEOM_ATTR;
/** Returns the rectangle obtained by translating rect
* horizontally by dx and vertically by dy. */
OP_GEOM_SCOPE CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy) OP_GEOM_ATTR;
/** Returns the rectangle obtained by moving each of rect's
* horizontal sides inward by dy and each of rect's vertical
* sides inward by dx with the center point preserved. A larger
* rectangle can be created by using negative values. */
OP_GEOM_SCOPE CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy) OP_GEOM_ATTR;
/** Returns a rectangle obtained by expanding rect minimally
* so that all four of its defining components are integers. */
CGRect CGRectIntegral(CGRect rect);
/** Returns the smallest rectangle which contains both r1 and r2
* (modulo a set of measure zero). If either of r1 or r2
* is an empty rectangle, then the other rectangle is returned.
* If both are empty, then the empty rectangle is returned. */
CGRect CGRectUnion(CGRect r1, CGRect r2);
/** Returns the largest rectangle which lies in both r1 and r2.
* If r1 and r2 have empty intersection (or, rather, intersection
* of measure zero, since this includes having their intersection
* be only a point or a line), then the empty rectangle is returned. */
CGRect CGRectIntersection(CGRect r1, CGRect r2);
/** Divides rect into two rectangles (namely slice and remainder) by
* "cutting" rect---parallel to, and a distance amount from the given edge
* of rect. You may pass 0 in as either of slice or remainder to avoid
* obtaining either of the created rectangles. */
void CGRectDivide(CGRect rect, CGRect *slice, CGRect *remainder,
CGFloat amount, CGRectEdge edge);
/* Accessing Geometric Attributes */
/** Returns the least x-coordinate value still inside rect. */
OP_GEOM_SCOPE CGFloat CGRectGetMinX(CGRect rect) OP_GEOM_ATTR;
/** Returns the x-coordinate of rect's middle point. */
OP_GEOM_SCOPE CGFloat CGRectGetMidX(CGRect rect) OP_GEOM_ATTR;
/** Returns the greatest x-coordinate value still inside rect. */
OP_GEOM_SCOPE CGFloat CGRectGetMaxX(CGRect rect) OP_GEOM_ATTR;
/** Returns the least y-coordinate value still inside rect. */
OP_GEOM_SCOPE CGFloat CGRectGetMinY(CGRect rect) OP_GEOM_ATTR;
/** Returns the y-coordinate of rect's middle point. */
OP_GEOM_SCOPE CGFloat CGRectGetMidY(CGRect rect) OP_GEOM_ATTR;
/** Returns the greatest y-coordinate value still inside rect. */
OP_GEOM_SCOPE CGFloat CGRectGetMaxY(CGRect rect) OP_GEOM_ATTR;
/** Returns rect's width. */
OP_GEOM_SCOPE CGFloat CGRectGetWidth(CGRect rect) OP_GEOM_ATTR;
/** Returns rect's height. */
OP_GEOM_SCOPE CGFloat CGRectGetHeight(CGRect rect) OP_GEOM_ATTR;
/** Returns 1 iff the rect is invalid. */
int CGRectIsNull(CGRect rect);
/** Returns 1 iff the area of rect is zero (i.e., iff either
* of rect's width or height is zero or is an invalid rectangle). */
OP_GEOM_SCOPE int CGRectIsEmpty(CGRect rect) OP_GEOM_ATTR;
/** Returns 1 iff the rect is infinite. */
int CGRectIsInfinite(CGRect rect);
/** Returns 1 iff rect1 and rect2 are intersecting. */
OP_GEOM_SCOPE int CGRectIntersectsRect(CGRect rect1, CGRect rect2) OP_GEOM_ATTR;
/** Returns 1 iff rect1 contains rect2. */
OP_GEOM_SCOPE int CGRectContainsRect(CGRect rect1, CGRect rect2) OP_GEOM_ATTR;
/** Returns 1 iff point is inside rect. */
OP_GEOM_SCOPE int CGRectContainsPoint(CGRect rect, CGPoint point) OP_GEOM_ATTR;
/** Returns 1 iff rect1's and rect2's origin and size are the same. */
OP_GEOM_SCOPE int CGRectEqualToRect(CGRect rect1, CGRect rect2) OP_GEOM_ATTR;
/** Returns 1 iff size1's and size2's width and height are the same. */
OP_GEOM_SCOPE int CGSizeEqualToSize(CGSize size1, CGSize size2) OP_GEOM_ATTR;
/** Returns 1 iff point1's and point2's x- and y-coordinates are the same. */
OP_GEOM_SCOPE int CGPointEqualToPoint(CGPoint point1, CGPoint point2) OP_GEOM_ATTR;
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point);
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point);
CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size);
bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size);
CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect);
bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect);
/* Inlined functions */
OP_GEOM_SCOPE CGFloat CGRectGetMinX(CGRect rect)
{
if (rect.size.width < 0)
return rect.origin.x + rect.size.width;
else
return rect.origin.x;
}
OP_GEOM_SCOPE CGFloat CGRectGetMidX(CGRect rect)
{
return rect.origin.x + (rect.size.width / 2.0);
}
OP_GEOM_SCOPE CGFloat CGRectGetMaxX(CGRect rect)
{
if (rect.size.width < 0)
return rect.origin.x;
else
return rect.origin.x + rect.size.width;
}
OP_GEOM_SCOPE CGFloat CGRectGetMinY(CGRect rect)
{
if (rect.size.height < 0)
return rect.origin.y + rect.size.height;
else
return rect.origin.y;
}
OP_GEOM_SCOPE CGFloat CGRectGetMidY(CGRect rect)
{
return rect.origin.y + (rect.size.height / 2.0);
}
OP_GEOM_SCOPE CGFloat CGRectGetMaxY(CGRect rect)
{
if (rect.size.height < 0)
return rect.origin.y;
else
return rect.origin.y + rect.size.height;
}
OP_GEOM_SCOPE CGFloat CGRectGetWidth(CGRect rect)
{
return rect.size.width;
}
OP_GEOM_SCOPE CGFloat CGRectGetHeight(CGRect rect)
{
return rect.size.height;
}
OP_GEOM_SCOPE int CGRectIsEmpty(CGRect rect)
{
if (CGRectIsNull(rect))
return 1;
return ((rect.size.width == 0) || (rect.size.height == 0)) ? 1 : 0;
}
OP_GEOM_SCOPE int CGRectIntersectsRect(CGRect rect1, CGRect rect2)
{
return (CGRectIsNull(CGRectIntersection(rect1, rect2)) ? 0 : 1);
}
OP_GEOM_SCOPE int CGRectContainsRect(CGRect rect1, CGRect rect2)
{
return CGRectEqualToRect(rect1, CGRectUnion(rect1, rect2));
}
OP_GEOM_SCOPE int CGRectContainsPoint(CGRect rect, CGPoint point)
{
rect = CGRectStandardize(rect);
return ((point.x >= rect.origin.x) &&
(point.y >= rect.origin.y) &&
(point.x <= rect.origin.x + rect.size.width) &&
(point.y <= rect.origin.y + rect.size.height)) ? 1 : 0;
}
OP_GEOM_SCOPE int CGRectEqualToRect(CGRect rect1, CGRect rect2)
{
/* FIXME: It is not clear from the docs if {{0,0},{1,1}} and {{1,1},{-1,-1}}
are equal or not. (The text seem to imply that they aren't.) */
return ((rect1.origin.x == rect2.origin.x) &&
(rect1.origin.y == rect2.origin.y) &&
(rect1.size.width == rect2.size.width) &&
(rect1.size.height == rect2.size.height)) ? 1 : 0;
}
OP_GEOM_SCOPE int CGSizeEqualToSize(CGSize size1, CGSize size2)
{
return ((size1.width == size2.width) &&
(size1.height == size2.height)) ? 1 : 0;
}
OP_GEOM_SCOPE int CGPointEqualToPoint(CGPoint point1, CGPoint point2)
{
return ((point1.x == point2.x) && (point1.y == point2.y)) ? 1 : 0;
}
OP_GEOM_SCOPE CGPoint CGPointMake(CGFloat x, CGFloat y)
{
CGPoint point;
point.x = x;
point.y = y;
return point;
}
OP_GEOM_SCOPE CGSize CGSizeMake(CGFloat width, CGFloat height)
{
CGSize size;
size.width = width;
size.height = height;
return size;
}
OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
CGRect rect;
rect.origin.x = x;
rect.origin.y = y;
rect.size.width = width;
rect.size.height = height;
return rect;
}
OP_GEOM_SCOPE CGRect CGRectStandardize(CGRect rect)
{
if (rect.size.width < 0) {
rect.origin.x += rect.size.width;
rect.size.width = -rect.size.width;
}
if (rect.size.height < 0) {
rect.origin.y += rect.size.height;
rect.size.height = -rect.size.height;
}
return rect;
}
OP_GEOM_SCOPE CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy)
{
rect.origin.x += dx;
rect.origin.y += dy;
return rect;
}
OP_GEOM_SCOPE CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
{
rect = CGRectStandardize(rect);
rect.origin.x += dx;
rect.origin.y += dy;
rect.size.width -= (2 * dx);
rect.size.height -= (2 * dy);
return rect;
}
#endif /* OPAL_CGGeometry_h */

View file

@ -0,0 +1,67 @@
/** <title>CGGradient</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGGradient_h
#define OPAL_CGGradient_h
/* Data Types */
#ifdef __OBJC__
@class CGGradient;
typedef CGGradient* CGGradientRef;
#else
typedef struct CGGradient* CGGradientRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGColorSpace.h>
/* Constants */
typedef enum {
kCGGradientDrawsBeforeStartLocation = (1 << 0),
kCGGradientDrawsAfterEndLocation = (1 << 1)
} CGGradientDrawingOptions;
/* Functions */
CGGradientRef CGGradientCreateWithColorComponents(
CGColorSpaceRef cs,
const CGFloat components[],
const CGFloat locations[],
size_t count
);
CGGradientRef CGGradientCreateWithColors(
CGColorSpaceRef cs,
CFArrayRef colors,
const CGFloat locations[]
);
CFTypeID CGGradientGetTypeID();
CGGradientRef CGGradientRetain(CGGradientRef grad);
void CGGradientRelease(CGGradientRef grad);
#endif

View file

@ -0,0 +1,171 @@
/** <title>CGImage</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGImage_h
#define OPAL_CGImage_h
/* Data Types */
#ifdef __OBJC__
@class CGImage;
typedef CGImage* CGImageRef;
#else
typedef struct CGImage* CGImageRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGColorSpace.h>
#include <CoreGraphics/CGGeometry.h>
/* Constants */
typedef enum CGImageAlphaInfo
{
kCGImageAlphaNone = 0,
kCGImageAlphaPremultipliedLast = 1,
kCGImageAlphaPremultipliedFirst = 2,
kCGImageAlphaLast = 3,
kCGImageAlphaFirst = 4,
kCGImageAlphaNoneSkipLast = 5,
kCGImageAlphaNoneSkipFirst = 6,
kCGImageAlphaOnly = 7
} CGImageAlphaInfo;
typedef enum CGBitmapInfo {
kCGBitmapAlphaInfoMask = 0x1F,
kCGBitmapFloatComponents = (1 << 8),
kCGBitmapByteOrderMask = 0x7000,
kCGBitmapByteOrderDefault = (0 << 12),
kCGBitmapByteOrder16Little = (1 << 12),
kCGBitmapByteOrder32Little = (2 << 12),
kCGBitmapByteOrder16Big = (3 << 12),
kCGBitmapByteOrder32Big = (4 << 12)
} CGBitmapInfo;
// FIXME: Verify this endianness check works
#if GS_WORDS_BIGENDIAN
#define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Big
#define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Big
#else
#define kCGBitmapByteOrder16Host kCGBitmapByteOrder16Little
#define kCGBitmapByteOrder32Host kCGBitmapByteOrder32Little
#endif
/* Drawing Images */
CGImageRef CGImageCreate(
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bitsPerPixel,
size_t bytesPerRow,
CGColorSpaceRef colorspace,
CGBitmapInfo bitmapInfo,
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent
);
CGImageRef CGImageMaskCreate(
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bitsPerPixel,
size_t bytesPerRow,
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate
);
CGImageRef CGImageCreateCopy(CGImageRef image);
CGImageRef CGImageCreateCopyWithColorSpace(
CGImageRef image,
CGColorSpaceRef colorspace
);
CGImageRef CGImageCreateWithImageInRect(
CGImageRef image,
CGRect rect
);
CGImageRef CGImageCreateWithJPEGDataProvider (
CGDataProviderRef source,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent
);
CGImageRef CGImageCreateWithMask (
CGImageRef image,
CGImageRef mask
);
CGImageRef CGImageCreateWithMaskingColors (
CGImageRef image,
const CGFloat components[]
);
CGImageRef CGImageCreateWithPNGDataProvider (
CGDataProviderRef source,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent
);
CFTypeID CGImageGetTypeID();
CGImageRef CGImageRetain(CGImageRef image);
void CGImageRelease(CGImageRef image);
bool CGImageIsMask(CGImageRef image);
size_t CGImageGetWidth(CGImageRef image);
size_t CGImageGetHeight(CGImageRef image);
size_t CGImageGetBitsPerComponent(CGImageRef image);
size_t CGImageGetBitsPerPixel(CGImageRef image);
size_t CGImageGetBytesPerRow(CGImageRef image);
CGColorSpaceRef CGImageGetColorSpace(CGImageRef image);
CGImageAlphaInfo CGImageGetAlphaInfo(CGImageRef image);
CGBitmapInfo CGImageGetBitmapInfo(CGImageRef image);
CGDataProviderRef CGImageGetDataProvider(CGImageRef image);
const CGFloat *CGImageGetDecode(CGImageRef image);
bool CGImageGetShouldInterpolate(CGImageRef image);
CGColorRenderingIntent CGImageGetRenderingIntent(CGImageRef image);
#endif /* OPAL_CGImage_h */

View file

@ -0,0 +1,101 @@
/** <title>CGImageDestination</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGImageDestination_h
#define OPAL_CGImageDestination_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGDataConsumer.h>
/* Constants */
extern const CFStringRef kCGImageDestinationLossyCompressionQuality;
extern const CFStringRef kCGImageDestinationBackgroundColor;
/* Data Types */
#ifdef __OBJC__
@class CGImageDestination;
typedef CGImageDestination* CGImageDestinationRef;
#else
typedef struct CGImageDestination* CGImageDestinationRef;
#endif
#include <CoreGraphics/CGImage.h>
#include <CoreGraphics/CGImageSource.h>
/* Functions */
/* Creating */
CGImageDestinationRef CGImageDestinationCreateWithData(
CFMutableDataRef data,
CFStringRef type,
size_t count,
CFDictionaryRef opts
);
CGImageDestinationRef CGImageDestinationCreateWithDataConsumer(
CGDataConsumerRef consumer,
CFStringRef type,
size_t count,
CFDictionaryRef opts
);
CGImageDestinationRef CGImageDestinationCreateWithURL(
CFURLRef url,
CFStringRef type,
size_t count,
CFDictionaryRef opts
);
/* Getting Supported Image Types */
CFArrayRef CGImageDestinationCopyTypeIdentifiers();
/* Setting Properties */
void CGImageDestinationSetProperties(
CGImageDestinationRef dest,
CFDictionaryRef properties
);
/* Adding Images */
void CGImageDestinationAddImage(
CGImageDestinationRef dest,
CGImageRef image,
CFDictionaryRef properties
);
void CGImageDestinationAddImageFromSource(
CGImageDestinationRef dest,
CGImageSourceRef source,
size_t index,
CFDictionaryRef properties
);
bool CGImageDestinationFinalize(CGImageDestinationRef dest);
CFTypeID CGImageDestinationGetTypeID();
#endif /* OPAL_CGImageDestination_h */

View file

@ -0,0 +1,137 @@
/** <title>CGImageSource</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGImageSource_h
#define OPAL_CGImageSource_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGDataProvider.h>
/* Constants */
typedef enum CGImageSourceStatus {
kCGImageStatusUnexpectedEOF = -5,
kCGImageStatusInvalidData = -4,
kCGImageStatusUnknownType = -3,
kCGImageStatusReadingHeader = -2,
kCGImageStatusIncomplete = -1,
kCGImageStatusComplete = 0
} CGImageSourceStatus;
const extern CFStringRef kCGImageSourceTypeIdentifierHint;
const extern CFStringRef kCGImageSourceShouldAllowFloat;
const extern CFStringRef kCGImageSourceShouldCache;
const extern CFStringRef kCGImageSourceCreateThumbnailFromImageIfAbsent;
const extern CFStringRef kCGImageSourceCreateThumbnailFromImageAlways;
const extern CFStringRef kCGImageSourceThumbnailMaxPixelSize;
const extern CFStringRef kCGImageSourceCreateThumbnailWithTransform;
/* Data Types */
#ifdef __OBJC__
@class CGImageSource;
typedef CGImageSource* CGImageSourceRef;
#else
typedef struct CGImageSource* CGImageSourceRef;
#endif
#include <CoreGraphics/CGImage.h>
/* Functions */
/* Creating */
CGImageSourceRef CGImageSourceCreateIncremental(CFDictionaryRef opts);
CGImageSourceRef CGImageSourceCreateWithData(
CFDataRef data,
CFDictionaryRef opts
);
CGImageSourceRef CGImageSourceCreateWithDataProvider(
CGDataProviderRef provider,
CFDictionaryRef opts
);
CGImageSourceRef CGImageSourceCreateWithURL(
CFURLRef url,
CFDictionaryRef opts
);
/* Accessing Properties */
CFDictionaryRef CGImageSourceCopyProperties(
CGImageSourceRef source,
CFDictionaryRef opts
);
CFDictionaryRef CGImageSourceCopyPropertiesAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef opts
);
/* Getting Supported Image Types */
CFArrayRef CGImageSourceCopyTypeIdentifiers();
/* Accessing Images */
size_t CGImageSourceGetCount(CGImageSourceRef source);
CGImageRef CGImageSourceCreateImageAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef opts
);
CGImageRef CGImageSourceCreateThumbnailAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef opts
);
CGImageSourceStatus CGImageSourceGetStatus(CGImageSourceRef source);
CGImageSourceStatus CGImageSourceGetStatusAtIndex(
CGImageSourceRef source,
size_t index
);
CFStringRef CGImageSourceGetType(CGImageSourceRef source);
void CGImageSourceUpdateData(
CGImageSourceRef source,
CFDataRef data,
bool finalUpdate
);
void CGImageSourceUpdateDataProvider(
CGImageSourceRef source,
CGDataProviderRef provider,
bool finalUpdate
);
CFTypeID CGImageSourceGetTypeID();
#endif /* OPAL_CGImageSource_h */

View file

@ -0,0 +1,70 @@
/** <title>CGLayer</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2009 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Dec 2009
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGLayer_h
#define OPAL_CGLayer_h
/* Data Types */
#ifdef __OBJC__
@class CGLayer;
typedef CGLayer* CGLayerRef;
#else
typedef struct CGLayer* CGLayerRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
/* Functions */
CGLayerRef CGLayerCreateWithContext(
CGContextRef referenceCtxt,
CGSize size,
CFDictionaryRef auxInfo
);
CGLayerRef CGLayerRetain(CGLayerRef layer);
void CGLayerRelease(CGLayerRef layer);
CGSize CGLayerGetSize(CGLayerRef layer);
CGContextRef CGLayerGetContext(CGLayerRef layer);
void CGContextDrawLayerInRect(
CGContextRef destCtxt,
CGRect rect,
CGLayerRef layer
);
void CGContextDrawLayerAtPoint(
CGContextRef destCtxt,
CGPoint point,
CGLayerRef layer
);
CFTypeID CGLayerGetTypeID();
#endif

View file

@ -0,0 +1,66 @@
/** <title>CGPDFArray</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFArray_h
#define OPAL_CGPDFArray_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFArray;
typedef CGPDFArray* CGPDFArrayRef;
#else
typedef struct CGPDFArray* CGPDFArrayRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFObject.h>
#include <CoreGraphics/CGPDFString.h>
#include <CoreGraphics/CGPDFDictionary.h>
#include <CoreGraphics/CGPDFStream.h>
/* Functions */
bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, CGPDFArrayRef *value);
bool CGPDFArrayGetBoolean(CGPDFArrayRef array, size_t index, CGPDFBoolean *value);
size_t CGPDFArrayGetCount(CGPDFArrayRef array);
bool CGPDFArrayGetDictionary(CGPDFArrayRef array, size_t index, CGPDFDictionaryRef *value);
bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, CGPDFInteger *value);
bool CGPDFArrayGetName(CGPDFArrayRef array, size_t index, const char **value);
bool CGPDFArrayGetNull(CGPDFArrayRef array, size_t index);
bool CGPDFArrayGetNumber(CGPDFArrayRef array, size_t index, CGPDFReal *value);
bool CGPDFArrayGetObject(CGPDFArrayRef array, size_t index, CGPDFObjectRef *value);
bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, CGPDFStreamRef *value);
bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, CGPDFStringRef *value);
#endif /* OPAL_CGPDFArray_h */

View file

@ -0,0 +1,63 @@
/** <title>CGPDFContentStream</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFContentStream_h
#define OPAL_CGPDFContentStream_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFContentStream;
typedef CGPDFContentStream* CGPDFContentStreamRef;
#else
typedef struct CGPDFContentStream* CGPDFContentStreamRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFPage.h>
#include <CoreGraphics/CGPDFStream.h>
#include <CoreGraphics/CGPDFDictionary.h>
/* Functions */
CGPDFContentStreamRef CGPDFContentStreamCreateWithPage(CGPDFPageRef page);
CGPDFContentStreamRef CGPDFContentStreamCreateWithStream(
CGPDFStreamRef stream,
CGPDFDictionaryRef streamResources,
CGPDFContentStreamRef parent
);
CGPDFObjectRef CGPDFContentStreamGetResource(
CGPDFContentStreamRef stream,
const char *category,
const char *name
);
CFArrayRef CGPDFContentStreamGetStreams(CGPDFContentStreamRef stream);
CGPDFContentStreamRef CGPDFContentStreamRetain(CGPDFContentStreamRef stream);
void CGPDFContentStreamRelease(CGPDFContentStreamRef stream);
#endif /* OPAL_CGPDFContentStream_h */

View file

@ -0,0 +1,94 @@
/** <title>CGPDFContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFContext_h
#define OPAL_CGPDFContext_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGDataConsumer.h>
/* Constants */
extern const CFStringRef kCGPDFContextAuthor;
extern const CFStringRef kCGPDFContextCreator;
extern const CFStringRef kCGPDFContextTitle;
extern const CFStringRef kCGPDFContextOwnerPassword;
extern const CFStringRef kCGPDFContextUserPassword;
extern const CFStringRef kCGPDFContextAllowsPrinting;
extern const CFStringRef kCGPDFContextAllowsCopying;
extern const CFStringRef kCGPDFContextOutputIntent;
extern const CFStringRef kCGPDFContextOutputIntents;
extern const CFStringRef kCGPDFContextSubject;
extern const CFStringRef kCGPDFContextKeywords;
extern const CFStringRef kCGPDFContextEncryptionKeyLength;
extern const CFStringRef kCGPDFContextMediaBox;
extern const CFStringRef kCGPDFContextCropBox;
extern const CFStringRef kCGPDFContextBleedBox;
extern const CFStringRef kCGPDFContextTrimBox;
extern const CFStringRef kCGPDFContextArtBox;
extern const CFStringRef kCGPDFXOutputIntentSubtype;
extern const CFStringRef kCGPDFXOutputConditionIdentifier;
extern const CFStringRef kCGPDFXOutputCondition;
extern const CFStringRef kCGPDFXRegistryName;
extern const CFStringRef kCGPDFXInfo;
extern const CFStringRef kCGPDFXDestinationOutputProfile;
/* Functions */
void CGPDFContextAddDestinationAtPoint(
CGContextRef ctx,
CFStringRef name,
CGPoint point
);
void CGPDFContextBeginPage(CGContextRef ctx, CFDictionaryRef pageInfo);
void CGPDFContextClose(CGContextRef ctx);
CGContextRef CGPDFContextCreate(
CGDataConsumerRef consumer,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo
);
CGContextRef CGPDFContextCreateWithURL(
CFURLRef url,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo
);
void CGPDFContextEndPage(CGContextRef ctx);
void CGPDFContextSetDestinationForRect(
CGContextRef ctx,
CFStringRef name,
CGRect rect
);
void CGPDFContextSetURLForRect(CGContextRef ctx, CFURLRef url, CGRect rect);
#endif /* OPAL_CGPDFContext_h */

View file

@ -0,0 +1,73 @@
/** <title>CGPDFDictionary</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFDictionary_h
#define OPAL_CGPDFDictionary_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFDictionary;
typedef CGPDFDictionary* CGPDFDictionaryRef;
#else
typedef struct CGPDFDictionary* CGPDFDictionaryRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFObject.h>
#include <CoreGraphics/CGPDFArray.h>
#include <CoreGraphics/CGPDFStream.h>
/* Callbacks */
typedef void (*CGPDFDictionaryApplierFunction)(
const char *key,
CGPDFObjectRef value,
void *info
);
/* Functions */
void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, CGPDFDictionaryApplierFunction function, void *info);
size_t CGPDFDictionaryGetCount(CGPDFDictionaryRef dict);
bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, CGPDFArrayRef *value);
bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, CGPDFBoolean *value);
bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, CGPDFDictionaryRef *value);
bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, CGPDFInteger *value);
bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, const char **value);
bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, CGPDFReal *value);
bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, CGPDFObjectRef *value);
bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, CGPDFStreamRef *value);
bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, CGPDFStringRef *value);
#endif /* OPAL_CGPDFDictionary_h */

View file

@ -0,0 +1,66 @@
/** <title>CGPDFDocument</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFDocument_h
#define OPAL_CGPDFDocument_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFDocument;
typedef CGPDFDocument* CGPDFDocumentRef;
#else
typedef struct CGPDFDocument* CGPDFDocumentRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGDataConsumer.h>
#include <CoreGraphics/CGDataProvider.h>
/* Functions */
CGPDFDocumentRef CGPDFDocumentCreateWithProvider(CGDataProviderRef provider);
CGPDFDocumentRef CGPDFDocumentCreateWithURL(CFURLRef url);
CGPDFDocumentRef CGPDFDocumentRetain(CGPDFDocumentRef document);
void CGPDFDocumentRelease(CGPDFDocumentRef document);
int CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document);
CGRect CGPDFDocumentGetMediaBox(CGPDFDocumentRef document, int page);
CGRect CGPDFDocumentGetCropBox(CGPDFDocumentRef document, int page);
CGRect CGPDFDocumentGetBleedBox(CGPDFDocumentRef document, int page);
CGRect CGPDFDocumentGetTrimBox(CGPDFDocumentRef document, int page);
CGRect CGPDFDocumentGetArtBox(CGPDFDocumentRef document, int page);
int CGPDFDocumentGetRotationAngle(CGPDFDocumentRef document, int page);
#endif /* OPAL_CGPDFDocument_h */

View file

@ -0,0 +1,64 @@
/** <title>CGPDFObject</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFObject_h
#define OPAL_CGPDFObject_h
#include <CoreGraphics/CGBase.h>
/* Data Types */
typedef unsigned char CGPDFBoolean;
typedef long int CGPDFInteger;
typedef CGFloat CGPDFReal;
#ifdef __OBJC__
@class CGPDFObject;
typedef CGPDFObject* CGPDFObjectRef;
#else
typedef struct CGPDFObject* CGPDFObjectRef;
#endif
/* Constants */
typedef enum CGPDFObjectType {
kCGPDFObjectTypeNull = 1,
kCGPDFObjectTypeBoolean = 2,
kCGPDFObjectTypeInteger = 3,
kCGPDFObjectTypeReal = 4,
kCGPDFObjectTypeName = 5,
kCGPDFObjectTypeString = 6,
kCGPDFObjectTypeArray = 7,
kCGPDFObjectTypeDictionary = 8,
kCGPDFObjectTypeStream = 9
} CGPDFObjectType;
/* Functions */
CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object);
bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, void *value);
#endif /* OPAL_CGPDFDictionary_h */

View file

@ -0,0 +1,57 @@
/** <title>CGPDFOperatorTable</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFOperatorTable_h
#define OPAL_CGPDFOperatorTable_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFOperatorTable;
typedef CGPDFOperatorTable* CGPDFOperatorTableRef;
#else
typedef struct CGPDFOperatorTable* CGPDFOperatorTableRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFScanner.h>
/* Callbacks */
typedef void (*CGPDFOperatorCallback)(CGPDFScannerRef scanner, void *info);
/* Functions */
CGPDFOperatorTableRef CGPDFOperatorTableCreate();
void CGPDFOperatorTableSetCallback(
CGPDFOperatorTableRef table,
const char *name,
CGPDFOperatorCallback callback
);
CGPDFOperatorTableRef CGPDFOperatorTableRetain(CGPDFOperatorTableRef table);
void CGPDFOperatorTableRelease(CGPDFOperatorTableRef table);
#endif /* OPAL_CGPDFOperatorTable_h */

View file

@ -0,0 +1,77 @@
/** <title>CGPDFPage</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFPage_h
#define OPAL_CGPDFPage_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFPage;
typedef CGPDFPage* CGPDFPageRef;
#else
typedef struct CGPDFPage* CGPDFPageRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFDocument.h>
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGPDFDictionary.h>
/* Constants */
typedef enum CGPDFBox {
kCGPDFMediaBox = 0,
kCGPDFCropBox = 1,
kCGPDFBleedBox = 2,
kCGPDFTrimBox = 3,
kCGPDFArtBox = 4
} CGPDFBox;
/* Functions */
CGPDFDocumentRef CGPDFPageGetDocument(CGPDFPageRef page);
size_t CGPDFPageGetPageNumber(CGPDFPageRef page);
CGRect CGPDFPageGetBoxRect(CGPDFPageRef page, CGPDFBox box);
int CGPDFPageGetRotationAngle(CGPDFPageRef page);
CGAffineTransform CGPDFPageGetDrawingTransform(
CGPDFPageRef page,
CGPDFBox box,
CGRect rect,
int rotate,
bool preserveAspectRatio
);
CGPDFDictionaryRef CGPDFPageGetDictionary(CGPDFPageRef page);
CFTypeID CGPDFPageGetTypeID(void);
CGPDFPageRef CGPDFPageRetain(CGPDFPageRef page);
void CGPDFPageRelease(CGPDFPageRef page);
#endif /* OPAL_CGPDFPage_h */

View file

@ -0,0 +1,77 @@
/** <title>CGPDFScanner</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFScanner_h
#define OPAL_CGPDFScanner_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFScanner;
typedef CGPDFScanner* CGPDFScannerRef;
#else
typedef struct CGPDFScanner* CGPDFScannerRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPDFContentStream.h>
#include <CoreGraphics/CGPDFOperatorTable.h>
#include <CoreGraphics/CGPDFArray.h>
#include <CoreGraphics/CGPDFDictionary.h>
#include <CoreGraphics/CGPDFObject.h>
/* Functions */
CGPDFScannerRef CGPDFScannerCreate(
CGPDFContentStreamRef cs,
CGPDFOperatorTableRef table,
void *info
);
bool CGPDFScannerScan(CGPDFScannerRef scanner);
CGPDFContentStreamRef CGPDFScannerGetContentStream(CGPDFScannerRef scanner);
bool CGPDFScannerPopArray(CGPDFScannerRef scanner, CGPDFArrayRef *value);
bool CGPDFScannerPopBoolean(CGPDFScannerRef scanner, CGPDFBoolean *value);
bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, CGPDFDictionaryRef *value);
bool CGPDFScannerPopInteger(CGPDFScannerRef scanner, CGPDFInteger *value);
bool CGPDFScannerPopName(CGPDFScannerRef scanner, const char **value);
bool CGPDFScannerPopNumber(CGPDFScannerRef scanner, CGPDFReal *value);
bool CGPDFScannerPopObject(CGPDFScannerRef scanner, CGPDFObjectRef *value);
bool CGPDFScannerPopStream(CGPDFScannerRef scanner, CGPDFStreamRef *value);
bool CGPDFScannerPopString(CGPDFScannerRef scanner, CGPDFStringRef *value);
CGPDFScannerRef CGPDFScannerRetain(CGPDFScannerRef scanner);
void CGPDFScannerRelease(CGPDFScannerRef scanner);
#endif /* OPAL_CGPDFScanner_h */

View file

@ -0,0 +1,53 @@
/** <title>CGPDFStream</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFStream_h
#define OPAL_CGPDFStream_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFStream;
typedef CGPDFStream* CGPDFStreamRef;
#else
typedef struct CGPDFStream* CGPDFStreamRef;
#endif
#include <CoreGraphics/CGPDFDictionary.h>
#include <CoreGraphics/CGBase.h>
/* Constants */
typedef enum CGPDFDataFormat {
CGPDFDataFormatRaw = 0,
CGPDFDataFormatJPEGEncoded = 1,
CGPDFDataFormatJPEG2000 = 2
} CGPDFDataFormat;
/* Functions */
CGPDFDictionaryRef CGPDFStreamGetDictionary(CGPDFStreamRef stream);
CFDataRef CGPDFStreamCopyData(CGPDFStreamRef stream, CGPDFDataFormat *format);
#endif /* OPAL_CGPDFStream_h */

View file

@ -0,0 +1,48 @@
/** <title>CGPDFString</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPDFString_h
#define OPAL_CGPDFString_h
/* Data Types */
#ifdef __OBJC__
@class CGPDFString;
typedef CGPDFString* CGPDFStringRef;
#else
typedef struct CGPDFString* CGPDFStringRef;
#endif
#include <CoreGraphics/CGBase.h>
/* Functions */
size_t CGPDFStringGetLength(CGPDFStringRef string);
const unsigned char *CGPDFStringGetBytePtr(CGPDFStringRef string);
CFStringRef CGPDFStringCopyTextString(CGPDFStringRef string);
CFDateRef CGPDFStringCopyDate(CGPDFStringRef string);
#endif /* OPAL_CGPDFString_h */

View file

@ -0,0 +1,97 @@
/** <title>CGPSConverter</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPSConverter_h
#define OPAL_CGPSConverter_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGDataProvider.h>
#include <CoreGraphics/CGDataConsumer.h>
/* Callbacks */
typedef void (*CGPSConverterBeginDocumentCallback)(void *info);
typedef void (*CGPSConverterEndDocumentCallback)(void *info, bool success);
typedef void (*CGPSConverterBeginPageCallback)(
void *info,
size_t pageNumber,
CFDictionaryRef pageInfo
);
typedef void (*CGPSConverterEndPageCallback)(
void *info,
size_t pageNumber,
CFDictionaryRef pageInfo
);
typedef void (*CGPSConverterProgressCallback)(void *info);
typedef void (*CGPSConverterMessageCallback)(void *info, CFStringRef msg);
typedef void (*CGPSConverterReleaseInfoCallback)(void *info);
/* Data Types */
typedef struct CGPSConverterCallbacks {
unsigned int version;
CGPSConverterBeginDocumentCallback beginDocument;
CGPSConverterEndDocumentCallback endDocument;
CGPSConverterBeginPageCallback beginPage;
CGPSConverterEndPageCallback endPage;
CGPSConverterProgressCallback noteProgress;
CGPSConverterMessageCallback noteMessage;
CGPSConverterReleaseInfoCallback releaseInfo;
} CGPSConverterCallbacks;
#ifdef __OBJC__
@class CGPSConverter;
typedef CGPSConverter* CGPSConverterRef;
#else
typedef struct CGPSConverter* CGPSConverterRef;
#endif
/* Functions */
CGPSConverterRef CGPSConverterCreate(
void *info,
const CGPSConverterCallbacks *callbacks,
CFDictionaryRef options
);
bool CGPSConverterConvert(
CGPSConverterRef converter,
CGDataProviderRef provider,
CGDataConsumerRef consumer,
CFDictionaryRef options
);
bool CGPSConverterAbort(CGPSConverterRef converter);
bool CGPSConverterIsConverting(CGPSConverterRef converter);
CFTypeID CGPSConverterGetTypeID();
#endif /* OPAL_CGPSConverter_h */

View file

@ -0,0 +1,190 @@
/** <title>CGPath</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPath_h
#define OPAL_CGPath_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGAffineTransform.h>
/* Constants */
typedef enum CGPathElementType {
kCGPathElementMoveToPoint = 0,
kCGPathElementAddLineToPoint = 1,
kCGPathElementAddQuadCurveToPoint = 2,
kCGPathElementAddCurveToPoint = 3,
kCGPathElementCloseSubpath = 4
} CGPathElementType;
/* Data Types */
#ifdef __OBJC__
@class CGPath;
typedef CGPath* CGPathRef;
#else
typedef struct CGPath* CGPathRef;
#endif
#ifdef __OBJC__
@class CGMutablePath;
typedef CGMutablePath* CGMutablePathRef;
#else
typedef struct CGMutablePath* CGMutablePathRef;
#endif
typedef struct CGPathElement {
CGPathElementType type;
CGPoint *points;
} CGPathElement;
/* Callbacks */
typedef void (*CGPathApplierFunction)(void *info, const CGPathElement *element);
/* Functions */
CGPathRef CGPathCreateCopy(CGPathRef path);
CGMutablePathRef CGPathCreateMutable();
CGMutablePathRef CGPathCreateMutableCopy(CGPathRef path);
CGPathRef CGPathRetain(CGPathRef path);
void CGPathRelease(CGPathRef path);
bool CGPathIsEmpty(CGPathRef path);
bool CGPathEqualToPath(CGPathRef path1, CGPathRef path2);
bool CGPathIsRect(CGPathRef path, CGRect *rect);
CGRect CGPathGetBoundingBox(CGPathRef path);
CGPoint CGPathGetCurrentPoint(CGPathRef path);
bool CGPathContainsPoint(
CGPathRef path,
const CGAffineTransform *m,
CGPoint point,
int eoFill
);
void CGPathAddArc(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y,
CGFloat r,
CGFloat startAngle,
CGFloat endAngle,
int clockwise
);
void CGPathAddArcToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x1,
CGFloat y1,
CGFloat x2,
CGFloat y2,
CGFloat r
);
void CGPathAddCurveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cx1,
CGFloat cy1,
CGFloat cx2,
CGFloat cy2,
CGFloat x,
CGFloat y
);
void CGPathAddLines(
CGMutablePathRef path,
const CGAffineTransform *m,
const CGPoint points[],
size_t count
);
void CGPathAddLineToPoint (
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y
);
void CGPathAddPath(
CGMutablePathRef path1,
const CGAffineTransform *m,
CGPathRef path2
);
void CGPathAddQuadCurveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cx,
CGFloat cy,
CGFloat x,
CGFloat y
);
void CGPathAddRect(
CGMutablePathRef path,
const CGAffineTransform *m,
CGRect rect
);
void CGPathAddRects(
CGMutablePathRef path,
const CGAffineTransform *m,
const CGRect rects[],
size_t count
);
void CGPathApply(
CGPathRef path,
void *info,
CGPathApplierFunction function
);
void CGPathMoveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y
);
void CGPathCloseSubpath(CGMutablePathRef path);
void CGPathAddEllipseInRect(
CGMutablePathRef path,
const CGAffineTransform *m,
CGRect rect
);
#endif /* OPAL_CGPath_h */

View file

@ -0,0 +1,82 @@
/** <title>CGPattern</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGPattern_h
#define OPAL_CGPattern_h
/* Data Types */
#ifdef __OBJC__
@class CGPattern;
typedef CGPattern* CGPatternRef;
#else
typedef struct CGPattern* CGPatternRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGAffineTransform.h>
/* Constants */
typedef enum CGPatternTiling
{
kCGPatternTilingNoDistortion = 0,
kCGPatternTilingConstantSpacingMinimalDistortion = 1,
kCGPatternTilingConstantSpacing = 2
} CGPatternTiling;
/* Callbacks */
typedef void(*CGPatternDrawPatternCallback)(void *info, CGContextRef ctx);
typedef void(*CGPatternReleaseInfoCallback)(void *info);
typedef struct CGPatternCallbacks {
unsigned int version;
CGPatternDrawPatternCallback drawPattern;
CGPatternReleaseInfoCallback releaseInfo;
} CGPatternCallbacks;
/* Functions */
CGPatternRef CGPatternCreate(
void *info,
CGRect bounds,
CGAffineTransform matrix,
CGFloat xStep,
CGFloat yStep,
CGPatternTiling tiling,
int isColored,
const CGPatternCallbacks *callbacks
);
CFTypeID CGPatternGetTypeID();
void CGPatternRelease(CGPatternRef pattern);
CGPatternRef CGPatternRetain(CGPatternRef pattern);
#endif /* OPAL_CGPattern_h */

View file

@ -0,0 +1,70 @@
/** <title>CGShading</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGShading_h
#define OPAL_CGShading_h
/* Data Types */
#ifdef __OBJC__
@class CGShading;
typedef CGShading* CGShadingRef;
#else
typedef struct CGShading* CGShadingRef;
#endif
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGFunction.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGColorSpace.h>
/* Functions */
CGShadingRef CGShadingCreateAxial(
CGColorSpaceRef colorspace,
CGPoint start,
CGPoint end,
CGFunctionRef function,
int extendStart,
int extendEnd
);
CGShadingRef CGShadingCreateRadial(
CGColorSpaceRef colorspace,
CGPoint start,
CGFloat startRadius,
CGPoint end,
CGFloat endRadius,
CGFunctionRef function,
int extendStart,
int extendEnd
);
CFTypeID CGShadingGetTypeID();
CGShadingRef CGShadingRetain(CGShadingRef shading);
void CGShadingRelease(CGShadingRef shading);
#endif /* OPAL_CGShading_h */

View file

@ -0,0 +1,58 @@
/** <title>CoreGraphics</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CoreGraphics_h
#define OPAL_CoreGraphics_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGBitmapContext.h>
#include <CoreGraphics/CGColor.h>
#include <CoreGraphics/CGColorSpace.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGDataConsumer.h>
#include <CoreGraphics/CGDataProvider.h>
#include <CoreGraphics/CGFont.h>
#include <CoreGraphics/CGFunction.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGGradient.h>
#include <CoreGraphics/CGImage.h>
#include <CoreGraphics/CGImageSource.h>
#include <CoreGraphics/CGImageDestination.h>
#include <CoreGraphics/CGLayer.h>
#include <CoreGraphics/CGPDFArray.h>
#include <CoreGraphics/CGPDFContentStream.h>
#include <CoreGraphics/CGPDFContext.h>
#include <CoreGraphics/CGPDFDictionary.h>
#include <CoreGraphics/CGPDFDocument.h>
#include <CoreGraphics/CGPDFObject.h>
#include <CoreGraphics/CGPDFOperatorTable.h>
#include <CoreGraphics/CGPDFPage.h>
#include <CoreGraphics/CGPDFScanner.h>
#include <CoreGraphics/CGPDFStream.h>
#include <CoreGraphics/CGPDFString.h>
#include <CoreGraphics/CGPath.h>
#include <CoreGraphics/CGPattern.h>
#include <CoreGraphics/CGShading.h>
#endif /* OPAL_CoreGraphics_h */

View file

@ -0,0 +1,57 @@
/** <title>OPPostScriptContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_OPPostScriptContext_h
#define OPAL_OPPostScriptContext_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGDataConsumer.h>
/* Constants */
extern const CFStringRef kOPPostScriptContextIsEPS;
extern const CFStringRef kOPPostScriptContextLanguageLevel;
/* Functions */
void OPPostScriptContextBeginPage(CGContextRef ctx, CFDictionaryRef pageInfo);
void OPPostScriptContextClose(CGContextRef ctx);
CGContextRef OPPostScriptContextCreate(
CGDataConsumerRef consumer,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo /* ignored */
);
CGContextRef OPPostScriptContextCreateWithURL(
CFURLRef url,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo /* ignored */
);
void OPPostScriptContextEndPage(CGContextRef ctx);
#endif /* OPAL_OPPostScriptContext_h */

View file

@ -0,0 +1,60 @@
/** <title>OPSVGContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_OPSVGContext_h
#define OPAL_OPSVGContext_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGDataConsumer.h>
/* Constants */
/**
* Can used as a key in the auxiliaryInfo dictionary with a value of @"1.2" or
* @"1.1" to restrict to a particular SVG version.
*/
extern const CFStringRef kOPSVGContextSVGVersion;
/* Functions */
void OPSVGContextBeginPage(CGContextRef ctx, CFDictionaryRef pageInfo);
void OPSVGContextClose(CGContextRef ctx);
CGContextRef OPSVGContextCreate(
CGDataConsumerRef consumer,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo
);
CGContextRef OPSVGContextCreateWithURL(
CFURLRef url,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo
);
void OPSVGContextEndPage(CGContextRef ctx);
#endif /* OPAL_OPSVGContext_h */

437
Headers/CoreText/CTFont.h Normal file
View file

@ -0,0 +1,437 @@
/** <title>CTFont</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFont_h
#define OPAL_CTFont_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGPath.h>
#include <CoreGraphics/CGFont.h>
#include <CoreText/CTFontDescriptor.h>
/* Data Types */
#ifdef __OBJC__
@class NSFont;
typedef NSFont* CTFontRef;
#else
typedef struct NSFont* CTFontRef;
#endif
/* Constants */
/**
* The following keys are used to retrieve different names for the font,
* using CTFontCopyName or CTFontCopyLocalizedName.
*/
extern const CFStringRef kCTFontCopyrightNameKey;
extern const CFStringRef kCTFontFamilyNameKey;
extern const CFStringRef kCTFontSubFamilyNameKey;
extern const CFStringRef kCTFontStyleNameKey;
extern const CFStringRef kCTFontUniqueNameKey;
extern const CFStringRef kCTFontFullNameKey;
extern const CFStringRef kCTFontVersionNameKey;
extern const CFStringRef kCTFontPostScriptNameKey;
extern const CFStringRef kCTFontTrademarkNameKey;
extern const CFStringRef kCTFontManufacturerNameKey;
extern const CFStringRef kCTFontDesignerNameKey;
extern const CFStringRef kCTFontDescriptionNameKey;
extern const CFStringRef kCTFontVendorURLNameKey;
extern const CFStringRef kCTFontDesignerURLNameKey;
extern const CFStringRef kCTFontLicenseNameKey;
extern const CFStringRef kCTFontLicenseURLNameKey;
extern const CFStringRef kCTFontSampleTextNameKey;
extern const CFStringRef kCTFontPostScriptCIDNameKey;
/**
* For use with CTFontCopyVariationAxes and CTFontCopyVariation
*/
extern const CFStringRef kCTFontVariationAxisIdentifierKey;
extern const CFStringRef kCTFontVariationAxisMinimumValueKey;
extern const CFStringRef kCTFontVariationAxisMaximumValueKey;
extern const CFStringRef kCTFontVariationAxisDefaultValueKey;
extern const CFStringRef kCTFontVariationAxisNameKey;
/**
* For use with CTFontCopyFeatures and CTFontCopyFeatureSettings.
*
* These are used as keys in the feature dictionaries, which
* are used to query the supported OpenType features of a font,
* or request a feature for a range in an attributed string.
*/
extern const CFStringRef kCTFontFeatureTypeIdentifierKey;
extern const CFStringRef kCTFontFeatureTypeNameKey;
extern const CFStringRef kCTFontFeatureTypeExclusiveKey;
extern const CFStringRef kCTFontFeatureTypeSelectorsKey;
extern const CFStringRef kCTFontFeatureSelectorIdentifierKey;
extern const CFStringRef kCTFontFeatureSelectorNameKey;
extern const CFStringRef kCTFontFeatureSelectorDefaultKey;
extern const CFStringRef kCTFontFeatureSelectorSettingKey;
typedef enum {
kCTFontOptionsDefault = 0,
kCTFontOptionsPreventAutoActivation = 1 << 0,
kCTFontOptionsPreferSystemFont = 1 << 2,
} CTFontOptions;
typedef enum {
kCTFontTableOptionNoOptions = 0,
kCTFontTableOptionExcludeSynthetic = 1 << 0
} CTFontTableOptions;
#if GS_WORDS_BIGENDIAN
#define OP_TABLETAG(a,b,c,d) ((((int)a) << 24) | (((int)b) << 16) | (((int)c) << 8) | ((int)d))
#else
#define OP_TABLETAG(a,b,c,d) ((((int)d) << 24) | (((int)c) << 16) | (((int)b) << 8) | ((int)a))
#endif
typedef enum {
kCTFontTableBASE = OP_TABLETAG('B','A','S','E'),
kCTFontTableCFF = OP_TABLETAG('C','F','F',' '),
kCTFontTableDSIG = OP_TABLETAG('D','S','I','G'),
kCTFontTableEBDT = OP_TABLETAG('E','B','D','T'),
kCTFontTableEBLC = OP_TABLETAG('E','B','L','C'),
kCTFontTableEBSC = OP_TABLETAG('E','B','S','C'),
kCTFontTableGDEF = OP_TABLETAG('G','D','E','F'),
kCTFontTableGPOS = OP_TABLETAG('G','P','O','S'),
kCTFontTableGSUB = OP_TABLETAG('G','S','U','B'),
kCTFontTableJSTF = OP_TABLETAG('J','S','T','F'),
kCTFontTableLTSH = OP_TABLETAG('L','T','S','H'),
kCTFontTableOS2 = OP_TABLETAG('O','S','/','2'),
kCTFontTablePCLT = OP_TABLETAG('P','C','L','T'),
kCTFontTableVDMX = OP_TABLETAG('V','D','M','X'),
kCTFontTableVORG = OP_TABLETAG('V','O','R','G'),
kCTFontTableZapf = OP_TABLETAG('Z','a','p','f'),
kCTFontTableAcnt = OP_TABLETAG('a','c','n','t'),
kCTFontTableAvar = OP_TABLETAG('a','v','a','r'),
kCTFontTableBdat = OP_TABLETAG('b','d','a','t'),
kCTFontTableBhed = OP_TABLETAG('b','h','e','d'),
kCTFontTableBloc = OP_TABLETAG('b','l','o','c'),
kCTFontTableBsln = OP_TABLETAG('b','s','l','n'),
kCTFontTableCmap = OP_TABLETAG('c','m','a','p'),
kCTFontTableCvar = OP_TABLETAG('c','v','a','r'),
kCTFontTableCvt = OP_TABLETAG('c','v','t',' '),
kCTFontTableFdsc = OP_TABLETAG('f','d','s','c'),
kCTFontTableFeat = OP_TABLETAG('f','e','a','t'),
kCTFontTableFmtx = OP_TABLETAG('f','m','t','x'),
kCTFontTableFpgm = OP_TABLETAG('f','p','g','m'),
kCTFontTableFvar = OP_TABLETAG('f','v','a','r'),
kCTFontTableGasp = OP_TABLETAG('g','a','s','p'),
kCTFontTableGlyf = OP_TABLETAG('g','l','y','f'),
kCTFontTableGvar = OP_TABLETAG('g','v','a','r'),
kCTFontTableHdmx = OP_TABLETAG('h','d','m','x'),
kCTFontTableHead = OP_TABLETAG('h','e','a','d'),
kCTFontTableHhea = OP_TABLETAG('h','h','e','a'),
kCTFontTableHmtx = OP_TABLETAG('h','m','t','x'),
kCTFontTableHsty = OP_TABLETAG('h','s','t','y'),
kCTFontTableJust = OP_TABLETAG('j','u','s','t'),
kCTFontTableKern = OP_TABLETAG('k','e','r','n'),
kCTFontTableLcar = OP_TABLETAG('l','c','a','r'),
kCTFontTableLoca = OP_TABLETAG('l','o','c','a'),
kCTFontTableMaxp = OP_TABLETAG('m','a','x','p'),
kCTFontTableMort = OP_TABLETAG('m','o','r','t'),
kCTFontTableMorx = OP_TABLETAG('m','o','r','x'),
kCTFontTableName = OP_TABLETAG('n','a','m','e'),
kCTFontTableOpbd = OP_TABLETAG('o','p','b','d'),
kCTFontTablePost = OP_TABLETAG('p','o','s','t'),
kCTFontTablePrep = OP_TABLETAG('p','r','e','p'),
kCTFontTableProp = OP_TABLETAG('p','r','o','p'),
kCTFontTableTrak = OP_TABLETAG('t','r','a','k'),
kCTFontTableVhea = OP_TABLETAG('v','h','e','a'),
kCTFontTableVmtx = OP_TABLETAG('v','m','t','x')
} CTFontTableTag;
typedef enum {
kCTFontNoFontType = -1,
kCTFontUserFontType = 0,
kCTFontUserFixedPitchFontType = 1,
kCTFontSystemFontType = 2,
kCTFontEmphasizedSystemFontType = 3,
kCTFontSmallSystemFontType = 4,
kCTFontSmallEmphasizedSystemFontType = 5,
kCTFontMiniSystemFontType = 6,
kCTFontMiniEmphasizedSystemFontType = 7,
kCTFontViewsFontType = 8,
kCTFontApplicationFontType = 9,
kCTFontLabelFontType = 10,
kCTFontMenuTitleFontType = 11,
kCTFontMenuItemFontType = 12,
kCTFontMenuItemMarkFontType = 13,
kCTFontMenuItemCmdKeyFontType = 14,
kCTFontWindowTitleFontType = 15,
kCTFontPushButtonFontType = 16,
kCTFontUtilityWindowTitleFontType = 17,
kCTFontAlertHeaderFontType = 18,
kCTFontSystemDetailFontType = 19,
kCTFontEmphasizedSystemDetailFontType = 20,
kCTFontToolbarFontType = 21,
kCTFontSmallToolbarFontType = 22,
kCTFontMessageFontType = 23,
kCTFontPaletteFontType = 24,
kCTFontToolTipFontType = 25,
kCTFontControlContentFontType = 26
} CTFontUIFontType;
/* Functions */
/* Creating */
CTFontRef CTFontCreateForString(
CTFontRef base,
CFStringRef str,
CFRange range
);
/**
* Creates a font with the given matrix and size.
* matrix
*/
CTFontRef CTFontCreateWithFontDescriptor(
CTFontDescriptorRef attribs,
CGFloat size,
const CGAffineTransform *matrixPtr
);
CTFontRef CTFontCreateWithFontDescriptorAndOptions(
CTFontDescriptorRef attribs,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontOptions opts
);
CTFontRef CTFontCreateWithGraphicsFont(
CGFontRef cgFont,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontDescriptorRef attribs
);
CTFontRef CTFontCreateWithName(
CFStringRef name,
CGFloat size,
const CGAffineTransform *matrixPtr
);
CTFontRef CTFontCreateWithNameAndOptions(
CFStringRef name,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontOptions opts
);
CTFontRef CTFontCreateWithPlatformFont(
void *platformFont,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontDescriptorRef attribs
);
CTFontRef CTFontCreateWithQuickdrawInstance(
void *name,
int16_t identifier,
uint8_t style,
CGFloat size
);
CTFontRef CTFontCreateUIFontForLanguage(
CTFontUIFontType type,
CGFloat size,
CFStringRef language
);
/* Copying & Conversion */
CTFontRef CTFontCreateCopyWithAttributes(
CTFontRef font,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontDescriptorRef attribs
);
CTFontRef CTFontCreateCopyWithSymbolicTraits(
CTFontRef font,
CGFloat size,
const CGAffineTransform *matrixPtr,
CTFontSymbolicTraits value,
CTFontSymbolicTraits mask
);
CTFontRef CTFontCreateCopyWithFamily(
CTFontRef font,
CGFloat size,
const CGAffineTransform *matrixPtr,
CFStringRef family
);
void *CTFontGetPlatformFont(
CTFontRef font,
CTFontDescriptorRef *attribs
);
CGFontRef CTFontCopyGraphicsFont(
CTFontRef font,
CTFontDescriptorRef *attribs
);
/* Glyphs */
CFIndex CTFontGetGlyphCount(CTFontRef font);
CGPathRef CTFontCreatePathForGlyph(
CTFontRef font,
CGGlyph glyph,
const CGAffineTransform *transform
);
bool CTFontGetGlyphsForCharacters(
CTFontRef font,
const unichar characters[],
CGGlyph glyphs[],
CFIndex count
);
CGGlyph CTFontGetGlyphWithName(
CTFontRef font,
CFStringRef name
);
double CTFontGetAdvancesForGlyphs(
CTFontRef font,
CTFontOrientation orientation,
const CGGlyph glyphs[],
CGSize advances[],
CFIndex count
);
CGRect CTFontGetBoundingRectsForGlyphs(
CTFontRef font,
CTFontOrientation orientation,
const CGGlyph glyphs[],
CGRect rects[],
CFIndex count
);
void CTFontGetVerticalTranslationsForGlyphs(
CTFontRef font,
const CGGlyph glyphs[],
CGSize translations[],
CFIndex count
);
/* Metrics */
CGFloat CTFontGetAscent(CTFontRef font);
CGFloat CTFontGetDescent(CTFontRef font);
CGFloat CTFontGetCapHeight(CTFontRef font);
CGFloat CTFontGetSize(CTFontRef font);
CGFloat CTFontGetLeading(CTFontRef font);
unsigned CTFontGetUnitsPerEm(CTFontRef font);
CGRect CTFontGetBoundingBox(CTFontRef font);
CGFloat CTFontGetUnderlinePosition(CTFontRef font);
CGFloat CTFontGetUnderlineThickness(CTFontRef font);
CGFloat CTFontGetSlantAngle(CTFontRef font);
CGFloat CTFontGetXHeight(CTFontRef font);
/* Properties */
CGAffineTransform CTFontGetMatrix(CTFontRef font);
CTFontSymbolicTraits CTFontGetSymbolicTraits(CTFontRef font);
CFTypeRef CTFontCopyAttribute(
CTFontRef font,
CFStringRef attrib
);
CFArrayRef CTFontCopyAvailableTables(
CTFontRef font,
CTFontTableOptions opts
);
CFDictionaryRef CTFontCopyTraits(CTFontRef font);
CFArrayRef CTFontCopyFeatures(CTFontRef font);
CFArrayRef CTFontCopyFeatureSettings(CTFontRef font);
CTFontDescriptorRef CTFontCopyFontDescriptor(CTFontRef font);
CFDataRef CTFontCopyTable(
CTFontRef font,
CTFontTableTag table,
CTFontTableOptions opts
);
CFArrayRef CTFontCopyVariationAxes(CTFontRef font);
CFDictionaryRef CTFontCopyVariation(CTFontRef font);
/* Encoding & Character Set */
/**
* Note: Returns NSStringEncoding instead of CFStringEncoding
*/
NSStringEncoding CTFontGetStringEncoding(CTFontRef font);
CFCharacterSetRef CTFontCopyCharacterSet(CTFontRef font);
CFArrayRef CTFontCopySupportedLanguages(CTFontRef font);
/* Name */
CFStringRef CTFontCopyDisplayName(CTFontRef font);
CFStringRef CTFontCopyName(
CTFontRef font,
CFStringRef key
);
CFStringRef CTFontCopyLocalizedName(
CTFontRef font,
CFStringRef key,
CFStringRef *language
);
CFStringRef CTFontCopyPostScriptName(CTFontRef font);
CFStringRef CTFontCopyFamilyName(CTFontRef font);
CFStringRef CTFontCopyFullName(CTFontRef font);
/* CFTypeID */
CFTypeID CTFontGetTypeID();
#endif

View file

@ -0,0 +1,77 @@
/** <title>CTFontCollection</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFontCollection_h
#define OPAL_CTFontCollection_h
#include <CoreGraphics/CGBase.h>
#include <CoreText/CTFontDescriptor.h>
/* Data Types */
#ifdef __OBJC__
@class CTFontCollection;
typedef CTFontCollection* CTFontCollectionRef;
#else
typedef struct CTFontCollection* CTFontCollectionRef;
#endif
/* Callbacks */
typedef CFComparisonResult (*CTFontCollectionSortDescriptorsCallback)(
CTFontDescriptorRef a,
CTFontDescriptorRef b,
void *info
);
/* Constants */
extern const CFStringRef kCTFontCollectionRemoveDuplicatesOption;
/* Functions */
CTFontCollectionRef CTFontCollectionCreateCopyWithFontDescriptors(
CTFontCollectionRef base,
CFArrayRef descriptors,
CFDictionaryRef opts
);
CTFontCollectionRef CTFontCollectionCreateFromAvailableFonts(CFDictionaryRef opts);
CFArrayRef CTFontCollectionCreateMatchingFontDescriptors(CTFontCollectionRef collection);
CFArrayRef CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback(
CTFontCollectionRef collection,
CTFontCollectionSortDescriptorsCallback cb,
void *info
);
CTFontCollectionRef CTFontCollectionCreateWithFontDescriptors(
CFArrayRef descriptors,
CFDictionaryRef opts
);
CFTypeID CTFontCollectionGetTypeID();
#endif

View file

@ -0,0 +1,140 @@
/** <title>CTFontDescriptor</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Jun 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFontDescriptor_h
#define OPAL_CTFontDescriptor_h
#include <CoreGraphics/CGBase.h>
#include <CoreText/CTFontTraits.h>
/* Data Types */
#ifdef __OBJC__
@class NSFontDescriptor;
typedef NSFontDescriptor* CTFontDescriptorRef;
#else
typedef struct NSFontDescriptor* CTFontDescriptorRef;
#endif
/* Constants */
extern const CFStringRef kCTFontURLAttribute;
extern const CFStringRef kCTFontNameAttribute;
extern const CFStringRef kCTFontDisplayNameAttribute;
extern const CFStringRef kCTFontFamilyNameAttribute;
extern const CFStringRef kCTFontStyleNameAttribute;
extern const CFStringRef kCTFontTraitsAttribute;
extern const CFStringRef kCTFontVariationAttribute;
extern const CFStringRef kCTFontSizeAttribute;
extern const CFStringRef kCTFontMatrixAttribute;
extern const CFStringRef kCTFontCascadeListAttribute;
extern const CFStringRef kCTFontCharacterSetAttribute;
extern const CFStringRef kCTFontLanguagesAttribute;
extern const CFStringRef kCTFontBaselineAdjustAttribute;
extern const CFStringRef kCTFontMacintoshEncodingsAttribute;
extern const CFStringRef kCTFontFeaturesAttribute;
extern const CFStringRef kCTFontFeatureSettingsAttribute;
extern const CFStringRef kCTFontFixedAdvanceAttribute;
extern const CFStringRef kCTFontOrientationAttribute;
extern const CFStringRef kCTFontEnabledAttribute;
extern const CFStringRef kCTFontFormatAttribute;
extern const CFStringRef kCTFontRegistrationScopeAttribute;
extern const CFStringRef kCTFontPriorityAttribute;
typedef enum {
kCTFontDefaultOrientation = 0,
kCTFontHorizontalOrientation = 1,
kCTFontVerticalOrientation = 2
} CTFontOrientation;
typedef enum {
kCTFontFormatUnrecognized = 0,
kCTFontFormatOpenTypePostScript = 1,
kCTFontFormatOpenTypeTrueType = 2,
kCTFontFormatTrueType = 3,
kCTFontFormatPostScript = 4,
kCTFontFormatBitmap = 5
} CTFontFormat;
typedef enum {
kCTFontPrioritySystem = 10000,
kCTFontPriorityNetwork = 20000,
kCTFontPriorityComputer = 30000,
kCTFontPriorityUser = 40000,
kCTFontPriorityDynamic = 50000,
kCTFontPriorityProcess = 60000
} CTFontPriority;
/* Functions */
CTFontDescriptorRef CTFontDescriptorCreateWithNameAndSize(
CFStringRef name,
CGFloat size
);
CTFontDescriptorRef CTFontDescriptorCreateWithAttributes(CFDictionaryRef attributes);
CTFontDescriptorRef CTFontDescriptorCreateCopyWithAttributes(
CTFontDescriptorRef original,
CFDictionaryRef attributes
);
CTFontDescriptorRef CTFontDescriptorCreateCopyWithVariation(
CTFontDescriptorRef original,
CFNumberRef variationIdentifier,
CGFloat variationValue
);
CTFontDescriptorRef CTFontDescriptorCreateCopyWithFeature(
CTFontDescriptorRef original,
CFNumberRef featureTypeIdentifier,
CFNumberRef featureSelectorIdentifier
);
CFArrayRef CTFontDescriptorCreateMatchingFontDescriptors(
CTFontDescriptorRef descriptor,
CFSetRef mandatoryAttributes
);
CTFontDescriptorRef CTFontDescriptorCreateMatchingFontDescriptor(
CTFontDescriptorRef descriptor,
CFSetRef mandatoryAttributes
);
CFDictionaryRef CTFontDescriptorCopyAttributes(CTFontDescriptorRef descriptor);
CFTypeRef CTFontDescriptorCopyAttribute(
CTFontDescriptorRef descriptor,
CFStringRef attribute
);
CFTypeRef CTFontDescriptorCopyLocalizedAttribute(
CTFontDescriptorRef descriptor,
CFStringRef attribute,
CFStringRef *language
);
CFTypeID CTFontDescriptorGetTypeID();
#endif

View file

@ -0,0 +1,115 @@
/** <title>CTFontManager</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFontManager_h
#define OPAL_CTFontManager_h
#include <CoreGraphics/CGBase.h>
#include <CoreText/CTFontDescriptor.h>
/* Constants */
extern const CFStringRef kCTFontManagerBundleIdentifier;
extern const CFStringRef kCTFontManagerRegisteredFontsChangedNotification;
typedef enum {
kCTFontManagerScopeNone = 0,
kCTFontManagerScopeProcess = 1,
kCTFontManagerScopeUser = 2,
kCTFontManagerScopeSession = 3
} CTFontManagerScope;
typedef enum {
kCTFontManagerAutoActivationDefault = 0,
kCTFontManagerAutoActivationDisabled = 1,
kCTFontManagerAutoActivationEnabled = 2,
kCTFontManagerAutoActivationPromptUser = 3
} CTFontManagerAutoActivationSetting;
/* Functions */
CFArrayRef CTFontManagerCopyAvailablePostScriptNames();
CFArrayRef CTFontManagerCopyAvailableFontFamilyNames();
CFArrayRef CTFontManagerCopyAvailableFontURLs();
CFComparisonResult CTFontManagerCompareFontFamilyNames(
const void *a,
const void *b,
void *info
);
CFArrayRef CTFontManagerCreateFontDescriptorsFromURL(CFURLRef fileURL);
bool CTFontManagerRegisterFontsForURL(
CFURLRef fontURL,
CTFontManagerScope scope,
CFErrorRef *errors
);
bool CTFontManagerUnregisterFontsForURL(
CFURLRef fontURL,
CTFontManagerScope scope,
CFErrorRef *errors
);
bool CTFontManagerRegisterFontsForURLs(
CFArrayRef fontURLs,
CTFontManagerScope scope,
CFArrayRef *errors
);
bool CTFontManagerUnregisterFontsForURLs(
CFArrayRef fontURLs,
CTFontManagerScope scope,
CFArrayRef *errors
);
void CTFontManagerEnableFontDescriptors(
CFArrayRef descriptors,
bool enable
);
CTFontManagerScope CTFontManagerGetScopeForURL(CFURLRef fontURL);
bool CTFontManagerIsSupportedFont(CFURLRef fontURL);
#if defined(__BLOCKS__)
CFRunLoopSourceRef CTFontManagerCreateFontRequestRunLoopSource(
CFIndex sourceOrder,
CFArrayRef (^createMatchesCallback)(CFDictionaryRef requestAttributes, pid_t requestingProcess)
);
#endif
void CTFontManagerSetAutoActivationSetting(
CFStringRef bundleIdentifier,
CTFontManagerAutoActivationSetting setting
);
CTFontManagerAutoActivationSetting CTFontManagerGetAutoActivationSetting(
CFStringRef bundleIdentifier
);
#endif

View file

@ -0,0 +1,53 @@
/** <title>CTFontManagerErrors</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFontManagerErrors_h
#define OPAL_CTFontManagerErrors_h
#include <CoreGraphics/CGBase.h>
/* Data Types */
typedef CFIndex CTFontManagerError;
/* Constants */
extern const CFStringRef kCTFontManagerErrorDomain;
extern const CFStringRef kCTFontManagerErrorFontURLsKey;
enum {
kCTFontManagerErrorFileNotFound = 101,
kCTFontManagerErrorInsufficientPermissions = 102,
kCTFontManagerErrorUnrecognizedFormat = 103,
kCTFontManagerErrorInvalidFontData = 104,
kCTFontManagerErrorAlreadyRegistered = 105,
};
enum {
kCTFontManagerErrorNotRegistered = 201,
kCTFontManagerErrorInUse = 202,
kCTFontManagerErrorSystemRequired = 202,
};
#endif

View file

@ -0,0 +1,66 @@
/** <title>CTFontTraits</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFontTraits_h
#define OPAL_CTFontTraits_h
#include <CoreGraphics/CGBase.h>
/* Constants */
extern const CFStringRef kCTFontSymbolicTrait;
extern const CFStringRef kCTFontWeightTrait;
extern const CFStringRef kCTFontWidthTrait;
extern const CFStringRef kCTFontSlantTrait;
enum {
kCTFontClassMaskShift = 28
};
typedef enum {
kCTFontItalicTrait = (1 << 0),
kCTFontBoldTrait = (1 << 1),
kCTFontExpandedTrait = (1 << 5),
kCTFontCondensedTrait = (1 << 6),
kCTFontMonoSpaceTrait = (1 << 10),
kCTFontVerticalTrait = (1 << 11),
kCTFontUIOptimizedTrait = (1 << 12),
kCTFontClassMaskTrait = (15 << 28)
} CTFontSymbolicTraits;
typedef enum {
kCTFontUnknownClass = (0 << 28),
kCTFontOldStyleSerifsClass = (1 << 28),
kCTFontTransitionalSerifsClass = (2 << 28),
kCTFontModernSerifsClass = (3 << 28),
kCTFontClarendonSerifsClass = (4 << 28),
kCTFontSlabSerifsClass = (5 << 28),
kCTFontFreeformSerifsClass = (7 << 28),
kCTFontSansSerifClass = (8 << 28),
kCTFontOrnamentalsClass = (9 << 28),
kCTFontScriptsClass = (10 << 28),
kCTFontSymbolicClass = (12 << 28)
} CTFontStylisticClass;
#endif

View file

@ -0,0 +1,76 @@
/** <title>CTFrame</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFrame_h
#define OPAL_CTFrame_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPath.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreText/CTLine.h>
/* Data Types */
#ifdef __OBJC__
@class CTFrame;
typedef CTFrame* CTFrameRef;
#else
typedef struct CTFrame* CTFrameRef;
#endif
/* Constants */
extern const CFStringRef kCTFrameProgressionAttributeName;
typedef enum {
kCTFrameProgressionTopToBottom = 0,
kCTFrameProgressionRightToLeft = 1
} CTFrameProgression;
/* Functions */
CFTypeID CTFrameGetTypeID();
CFRange CTFrameGetStringRange(CTFrameRef frame);
CFRange CTFrameGetVisibleStringRange(CTFrameRef frame);
CGPathRef CTFrameGetPath(CTFrameRef frame);
CFDictionaryRef CTFrameGetFrameAttributes(CTFrameRef frame);
CFArrayRef CTFrameGetLines(CTFrameRef frame);
void CTFrameGetLineOrigins(
CTFrameRef frame,
CFRange range,
CGPoint origins[]
);
void CTFrameDraw(
CTFrameRef frame,
CGContextRef context
);
#endif

View file

@ -0,0 +1,66 @@
/** <title>CTFramesetter</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTFramesetter_h
#define OPAL_CTFramesetter_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGPath.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreText/CTFrame.h>
#include <CoreText/CTTypesetter.h>
/* Data Types */
#ifdef __OBJC__
@class CTFramesetter;
typedef CTFramesetter* CTFramesetterRef;
#else
typedef struct CTFramesetter* CTFramesetterRef;
#endif
/* Functions */
CFTypeID CTFramesetterGetTypeID();
CTFramesetterRef CTFramesetterCreateWithAttributedString(CFAttributedStringRef string);
CTFrameRef CTFramesetterCreateFrame(
CTFramesetterRef framesetter,
CFRange stringRange,
CGPathRef path,
CFDictionaryRef attributes
);
CTTypesetterRef CTFramesetterGetTypesetter(CTFramesetterRef framesetter);
CGSize CTFramesetterSuggestFrameSizeWithConstraints(
CTFramesetterRef framesetter,
CFRange stringRange,
CFDictionaryRef attributes,
CGSize constraints,
CFRange* fitRange
);
#endif

View file

@ -0,0 +1,80 @@
/** <title>CTGlyphInfo</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTGlyphInfo_h
#define OPAL_CTGlyphInfo_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGFont.h>
#include <CoreText/CTFont.h>
/* Data Types */
#ifdef __OBJC__
@class CTGlyphInfo;
typedef CTGlyphInfo* CTGlyphInfoRef;
#else
typedef struct CTGlyphInfo* CTGlyphInfoRef;
#endif
/* Constants */
typedef enum {
kCTIdentityMappingCharacterCollection = 0,
kCTAdobeCNS1CharacterCollection = 1,
kCTAdobeGB1CharacterCollection = 2,
kCTAdobeJapan1CharacterCollection = 3,
kCTAdobeJapan2CharacterCollection = 4,
kCTAdobeKorea1CharacterCollection = 5
} CTCharacterCollection;
/* Functions */
CFTypeID CTGlyphInfoGetTypeID();
CTGlyphInfoRef CTGlyphInfoCreateWithGlyphName(
CFStringRef glyphName,
CTFontRef font,
CFStringRef baseString
);
CTGlyphInfoRef CTGlyphInfoCreateWithGlyph(
CGGlyph glyph,
CTFontRef font,
CFStringRef baseString
);
CTGlyphInfoRef CTGlyphInfoCreateWithCharacterIdentifier(
CGFontIndex cid,
CTCharacterCollection collection,
CFStringRef baseString
);
CFStringRef CTGlyphInfoGetGlyphName(CTGlyphInfoRef glyphInfo);
CGFontIndex CTGlyphInfoGetCharacterIdentifier(CTGlyphInfoRef glyphInfo);
CTCharacterCollection CTGlyphInfoGetCharacterCollection(CTGlyphInfoRef glyphInfo);
#endif

108
Headers/CoreText/CTLine.h Normal file
View file

@ -0,0 +1,108 @@
/** <title>CTLine</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTLine_h
#define OPAL_CTLine_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGContext.h>
#include <CoreGraphics/CGFont.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreText/CTRun.h>
/* Data Types */
#ifdef __OBJC__
@class CTLine;
typedef CTLine* CTLineRef;
#else
typedef struct CTLine* CTLineRef;
#endif
/* Constants */
typedef enum {
kCTLineTruncationStart = 0,
kCTLineTruncationEnd = 1,
kCTLineTruncationMiddle = 2
} CTLineTruncationType;
/* Functions */
CFTypeID CTLineGetTypeID();
CTLineRef CTLineCreateWithAttributedString(CFAttributedStringRef string);
CTLineRef CTLineCreateTruncatedLine(
CTLineRef line,
double width,
CTLineTruncationType truncationType,
CTLineRef truncationToken
);
CTLineRef CTLineCreateJustifiedLine(
CTLineRef line,
CGFloat justificationFactor,
double justificationWidth
);
CFIndex CTLineGetGlyphCount(CTLineRef line);
CFArrayRef CTLineGetGlyphRuns(CTLineRef line);
CFRange CTLineGetStringRange(CTLineRef line);
double CTLineGetPenOffsetForFlush(
CTLineRef line,
CGFloat flushFactor,
double flushWidth
);
void CTLineDraw(CTLineRef line, CGContextRef ctx);
CGRect CTLineGetImageBounds(
CTLineRef line,
CGContextRef ctx
);
double CTLineGetTypographicBounds(
CTLineRef line,
CGFloat* ascent,
CGFloat* descent,
CGFloat* leading
);
double CTLineGetTrailingWhitespaceWidth(CTLineRef line);
CFIndex CTLineGetStringIndexForPosition(
CTLineRef line,
CGPoint position
);
CGFloat CTLineGetOffsetForStringIndex(
CTLineRef line,
CFIndex charIndex,
CGFloat* secondaryOffset
);
#endif

View file

@ -0,0 +1,110 @@
/** <title>CTParagraphStyle</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTParagraphStyle_h
#define OPAL_CTParagraphStyle_h
#include <CoreGraphics/CGBase.h>
/* Data Types */
#ifdef __OBJC__
@class CTParagraphStyle;
typedef CTParagraphStyle* CTParagraphStyleRef;
#else
typedef struct CTParagraphStyle* CTParagraphStyleRef;
#endif
/* Constants */
typedef enum {
kCTLeftTextAlignment = 0,
kCTRightTextAlignment = 1,
kCTCenterTextAlignment = 2,
kCTJustifiedTextAlignment = 3,
kCTNaturalTextAlignment = 4
} CTTextAlignment;
typedef enum {
kCTLineBreakByWordWrapping = 0,
kCTLineBreakByCharWrapping = 1,
kCTLineBreakByClipping = 2,
kCTLineBreakByTruncatingHead = 3,
kCTLineBreakByTruncatingTail = 4,
kCTLineBreakByTruncatingMiddle = 5
} CTLineBreakMode;
typedef enum {
kCTWritingDirectionNatural = -1,
kCTWritingDirectionLeftToRight = 0,
kCTWritingDirectionRightToLeft = 1
} CTWritingDirection;
typedef enum {
kCTParagraphStyleSpecifierAlignment = 0,
kCTParagraphStyleSpecifierFirstLineHeadIndent = 1,
kCTParagraphStyleSpecifierHeadIndent = 2,
kCTParagraphStyleSpecifierTailIndent = 3,
kCTParagraphStyleSpecifierTabStops = 4,
kCTParagraphStyleSpecifierDefaultTabInterval = 5,
kCTParagraphStyleSpecifierLineBreakMode = 6,
kCTParagraphStyleSpecifierLineHeightMultiple = 7,
kCTParagraphStyleSpecifierMaximumLineHeight = 8,
kCTParagraphStyleSpecifierMinimumLineHeight = 9,
kCTParagraphStyleSpecifierLineSpacing = 10,
kCTParagraphStyleSpecifierParagraphSpacing = 11,
kCTParagraphStyleSpecifierParagraphSpacingBefore = 12,
kCTParagraphStyleSpecifierBaseWritingDirection = 13,
kCTParagraphStyleSpecifierCount = 14
} CTParagraphStyleSpecifier;
/* Data Types */
typedef struct CTParagraphStyleSetting {
CTParagraphStyleSpecifier spec;
size_t valueSize;
const void *value;
} CTParagraphStyleSetting;
/* Functions */
CFTypeID CTParagraphStyleGetTypeID();
CTParagraphStyleRef CTParagraphStyleCreate(
const CTParagraphStyleSetting* settings,
CFIndex settingCount
);
CTParagraphStyleRef CTParagraphStyleCreateCopy(CTParagraphStyleRef paragraphStyle);
bool CTParagraphStyleGetValueForSpecifier(
CTParagraphStyleRef paragraphStyle,
CTParagraphStyleSpecifier spec,
size_t valueBufferSize,
void* valueBuffer
);
#endif

117
Headers/CoreText/CTRun.h Normal file
View file

@ -0,0 +1,117 @@
/** <title>CTRun</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTRun_h
#define OPAL_CTRun_h
#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGFont.h>
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGContext.h>
/* Data Types */
#ifdef __OBJC__
@class CTRun;
typedef CTRun* CTRunRef;
#else
typedef struct CTRun* CTRunRef;
#endif
/* Constants */
typedef enum {
kCTRunStatusNoStatus = 0,
kCTRunStatusRightToLeft = (1 << 0),
kCTRunStatusNonMonotonic = (1 << 1),
kCTRunStatusHasNonIdentityMatrix = (1 << 2)
} CTRunStatus;
/* Functions */
CFIndex CTRunGetGlyphCount(CTRunRef run);
CFDictionaryRef CTRunGetAttributes(CTRunRef run);
CTRunStatus CTRunGetStatus(CTRunRef run);
const CGGlyph* CTRunGetGlyphsPtr(CTRunRef run);
void CTRunGetGlyphs(
CTRunRef run,
CFRange range,
CGGlyph buffer[]
);
const CGPoint* CTRunGetPositionsPtr(CTRunRef run);
void CTRunGetPositions(
CTRunRef run,
CFRange range,
CGPoint buffer[]
);
const CGSize* CTRunGetAdvancesPtr(CTRunRef run);
void CTRunGetAdvances(
CTRunRef run,
CFRange range,
CGSize buffer[]
);
const CFIndex *CTRunGetStringIndicesPtr(CTRunRef run);
void CTRunGetStringIndices(
CTRunRef run,
CFRange range,
CFIndex buffer[]
);
CFRange CTRunGetStringRange(CTRunRef run);
double CTRunGetTypographicBounds(
CTRunRef run,
CFRange range,
CGFloat *ascent,
CGFloat *descent,
CGFloat *leading
);
CGRect CTRunGetImageBounds(
CTRunRef run,
CGContextRef ctx,
CFRange range
);
CGAffineTransform CTRunGetTextMatrix(CTRunRef run);
void CTRunDraw(
CTRunRef run,
CGContextRef ctx,
CFRange range
);
CFTypeID CTRunGetTypeID();
#endif

View file

@ -0,0 +1,62 @@
/** <title>CTStringAttribute</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTStringAttributes_h
#define OPAL_CTStringAttributes_h
#include <CoreGraphics/CGBase.h>
/* Constants */
extern const CFStringRef kCTFontAttributeName;
extern const CFStringRef kCTForegroundColorFromContextAttributeName;
extern const CFStringRef kCTKernAttributeName;
extern const CFStringRef kCTLigatureAttributeName;
extern const CFStringRef kCTForegroundColorAttributeName;
extern const CFStringRef kCTParagraphStyleAttributeName;
extern const CFStringRef kCTStrokeWidthAttributeName;
extern const CFStringRef kCTStrokeColorAttributeName;
extern const CFStringRef kCTUnderlineStyleAttributeName;
extern const CFStringRef kCTSuperscriptAttributeName;
extern const CFStringRef kCTUnderlineColorAttributeName;
extern const CFStringRef kCTVerticalFormsAttributeName;
extern const CFStringRef kCTGlyphInfoAttributeName;
extern const CFStringRef kCTCharacterShapeAttributeName;
typedef enum {
kCTUnderlineStyleNone = 0,
kCTUnderlineStyleSingle = 1,
kCTUnderlineStyleThick = 2,
kCTUnderlineStyleDouble = 9
} CTUnderlineStyle;
typedef enum {
kCTUnderlinePatternSolid = 0x0000,
kCTUnderlinePatternDot = 0x0100,
kCTUnderlinePatternDash = 0x0200,
kCTUnderlinePatternDashDot = 0x0300,
kCTUnderlinePatternDashDotDot = 0x0400
} CTUnderlineStyleModifiers;
#endif

View file

@ -0,0 +1,60 @@
/** <title>CTTextTab</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTTextTab_h
#define OPAL_CTTextTab_h
#include <CoreGraphics/CGBase.h>
#include <CoreText/CTParagraphStyle.h>
/* Data Types */
#ifdef __OBJC__
@class CTTextTab;
typedef CTTextTab* CTTextTabRef;
#else
typedef struct CTTextTab* CTTextTabRef;
#endif
/* Constants */
extern const CFStringRef kCTTabColumnTerminatorsAttributeName;
/* Functions */
CFTypeID CTTextTabGetTypeID();
CTTextTabRef CTTextTabCreate(
CTTextAlignment alignment,
double location,
CFDictionaryRef options
);
CTTextAlignment CTTextTabGetAlignment(CTTextTabRef tab);
double CTTextTabGetLocation(CTTextTabRef tab);
CFDictionaryRef CTTextTabGetOptions(CTTextTabRef tab);
#endif

View file

@ -0,0 +1,73 @@
/** <title>CTTypesetter</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CTTypesetter_h
#define OPAL_CTTypesetter_h
#include <CoreGraphics/CGBase.h>
#include <CoreText/CTLine.h>
/* Data Types */
#ifdef __OBJC__
@class CTTypesetter;
typedef CTTypesetter* CTTypesetterRef;
#else
typedef struct CTTypesetter* CTTypesetterRef;
#endif
/* Constants */
extern const CFStringRef kCTTypesetterOptionDisableBidiProcessing;
extern const CFStringRef kCTTypesetterOptionForcedEmbeddingLevel;
/* Functions */
CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef string);
CTTypesetterRef CTTypesetterCreateWithAttributedStringAndOptions(
CFAttributedStringRef string,
CFDictionaryRef opts
);
CTLineRef CTTypesetterCreateLine(
CTTypesetterRef typesetter,
CFRange range
);
CFIndex CTTypesetterSuggestClusterBreak(
CTTypesetterRef typesetter,
CFIndex start,
double width
);
CFIndex CTTypesetterSuggestLineBreak(
CTTypesetterRef typesetter,
CFIndex start,
double width
);
CFTypeID CTTypesetterGetTypeID();
#endif

View file

@ -0,0 +1,44 @@
/** <title>CoreText</title>
<abstract>C Interface to text layout library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Aug 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CoreText_h
#define OPAL_CoreText_h
#include <CoreText/CTFont.h>
#include <CoreText/CTFontCollection.h>
#include <CoreText/CTFontDescriptor.h>
#include <CoreText/CTFontManager.h>
#include <CoreText/CTFontManagerErrors.h>
#include <CoreText/CTFontTraits.h>
#include <CoreText/CTFrame.h>
#include <CoreText/CTFramesetter.h>
#include <CoreText/CTGlyphInfo.h>
#include <CoreText/CTLine.h>
#include <CoreText/CTParagraphStyle.h>
#include <CoreText/CTRun.h>
#include <CoreText/CTStringAttributes.h>
#include <CoreText/CTTextTab.h>
#include <CoreText/CTTypesetter.h>
#endif

View file

@ -0,0 +1,96 @@
/** <title>CGAffineTransform</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define IN_CGAFFINETRANSFORM_C
#include "CoreGraphics/CGAffineTransform.h"
#undef IN_CGAFFINETRANSFORM_C
#import <Foundation/Foundation.h>
#include <math.h>
const CGAffineTransform CGAffineTransformIdentity = {1,0,0,1,0,0};
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle)
{
CGAffineTransform matrix;
CGFloat cosa = cos(angle);
CGFloat sina = sin(angle);
matrix.a = matrix.d = cosa;
matrix.b = sina;
matrix.c = -sina;
matrix.tx = matrix.ty = 0;
return matrix;
}
CGAffineTransform CGAffineTransformInvert(CGAffineTransform t)
{
CGAffineTransform inv;
CGFloat det;
det = t.a * t.d - t.b *t.c;
if (det == 0) {
NSLog(@"Cannot invert matrix, determinant is 0");
return t;
}
inv.a = t.d / det;
inv.b = -t.b / det;
inv.c = -t.c / det;
inv.d = t.a / det;
inv.tx = (t.c * t.ty - t.d * t.tx) / det;
inv.ty = (t.b * t.tx - t.a * t.ty) / det;
return inv;
}
/**
* Returns the smallest rectangle which contains the four supplied points.
*/
static CGRect make_bounding_rect(CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4)
{
CGFloat minX = MIN(p1.x, MIN(p2.x, MIN(p3.x, p4.x)));
CGFloat minY = MIN(p1.y, MIN(p2.y, MIN(p3.y, p4.y)));
CGFloat maxX = MAX(p1.x, MAX(p2.x, MAX(p3.x, p4.x)));
CGFloat maxY = MAX(p1.y, MAX(p2.y, MAX(p3.y, p4.y)));
return CGRectMake(minX, minY, (maxX - minX), (maxY - minY));
}
CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t)
{
CGPoint p1 = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect));
CGPoint p2 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect));
CGPoint p3 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGPoint p4 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
p1 = CGPointApplyAffineTransform(p1, t);
p2 = CGPointApplyAffineTransform(p2, t);
p3 = CGPointApplyAffineTransform(p3, t);
p4 = CGPointApplyAffineTransform(p4, t);
return make_bounding_rect(p1, p2, p3, p4);
}

View file

@ -0,0 +1,320 @@
/** <title>CGBitmapContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2009 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: January 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGBitmapContext.h"
#include "CGContext-private.h"
@interface CGBitmapContext : CGContext
{
@public
CGColorSpaceRef cs;
void *data;
void *releaseInfo;
CGBitmapContextReleaseDataCallback cb;
}
- (id) initWithSurface: (cairo_surface_t *)target
colorspace: (CGColorSpaceRef)colorspace
data: (void*)d
releaseInfo: (void*)i
releaseCallback: (CGBitmapContextReleaseDataCallback)releaseCallback;
@end
@implementation CGBitmapContext
- (id) initWithSurface: (cairo_surface_t *)target
colorspace: (CGColorSpaceRef)colorspace
data: (void*)d
releaseInfo: (void*)i
releaseCallback: (CGBitmapContextReleaseDataCallback)releaseCallback;
{
CGSize size = CGSizeMake(cairo_image_surface_get_width(target),
cairo_image_surface_get_height(target));
if (nil == (self = [super initWithSurface: target size: size]))
{
return nil;
}
cs = CGColorSpaceRetain(colorspace);
data = d;
releaseInfo = i;
cb = releaseCallback;
return self;
}
- (void) dealloc
{
CGColorSpaceRelease(cs);
if (cb)
{
cb(releaseInfo, data);
}
[super dealloc];
}
@end
CGContextRef CGBitmapContextCreate(
void *data,
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bytesPerRow,
CGColorSpaceRef cs,
CGBitmapInfo info)
{
return CGBitmapContextCreateWithData(data, width, height, bitsPerComponent,
bytesPerRow, cs, info, NULL, NULL);
}
static void OPBitmapDataReleaseCallback(void *info, void *data)
{
free(data);
}
CGContextRef CGBitmapContextCreateWithData(
void *data,
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bytesPerRow,
CGColorSpaceRef cs,
CGBitmapInfo info,
CGBitmapContextReleaseDataCallback callback,
void *releaseInfo)
{
cairo_format_t format;
cairo_surface_t *surf;
if (0 != (info & kCGBitmapFloatComponents))
{
NSLog(@"Float components not supported");
return nil;
}
const int order = info & kCGBitmapByteOrderMask;
if (!((NSHostByteOrder() == NS_LittleEndian) && (order == kCGBitmapByteOrder32Little))
&& !((NSHostByteOrder() == NS_BigEndian) && (order == kCGBitmapByteOrder32Big))
&& !(order == kCGBitmapByteOrderDefault))
{
NSLog(@"Bitmap context must be native-endiand");
return nil;
}
const int alpha = info & kCGBitmapAlphaInfoMask;
const CGColorSpaceModel model = CGColorSpaceGetModel(cs);
const size_t numComps = CGColorSpaceGetNumberOfComponents(cs);
if (bitsPerComponent == 8
&& numComps == 3
&& model == kCGColorSpaceModelRGB
&& alpha == kCGImageAlphaPremultipliedFirst)
{
format = CAIRO_FORMAT_ARGB32;
}
else if (bitsPerComponent == 8
&& numComps == 3
&& model == kCGColorSpaceModelRGB
&& alpha == kCGImageAlphaNoneSkipFirst)
{
format = CAIRO_FORMAT_RGB24;
}
else if (bitsPerComponent == 8 && alpha == kCGImageAlphaOnly)
{
format = CAIRO_FORMAT_A8;
}
else if (bitsPerComponent == 1 && alpha == kCGImageAlphaOnly)
{
format = CAIRO_FORMAT_A1;
}
else
{
NSLog(@"Unsupported bitmap format");
return nil;
}
if (data == NULL)
{
data = malloc(height * bytesPerRow); // FIXME: checks
callback = (CGBitmapContextReleaseDataCallback)OPBitmapDataReleaseCallback;
}
surf = cairo_image_surface_create_for_data(data, format, width, height, bytesPerRow);
return [[CGBitmapContext alloc] initWithSurface: surf
colorspace: cs
data: data
releaseInfo: releaseInfo
releaseCallback: callback];
}
CGImageAlphaInfo CGBitmapContextGetAlphaInfo(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
switch (cairo_image_surface_get_format(cairo_get_target(ctx->ct)))
{
case CAIRO_FORMAT_ARGB32:
return kCGImageAlphaPremultipliedFirst;
case CAIRO_FORMAT_RGB24:
return kCGImageAlphaNoneSkipFirst;
case CAIRO_FORMAT_A8:
case CAIRO_FORMAT_A1:
return kCGImageAlphaOnly;
default:
return kCGImageAlphaNone;
}
}
return kCGImageAlphaNone;
}
CGBitmapInfo CGBitmapContextGetBitmapInfo(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return cairo_image_surface_get_stride(cairo_get_target(ctx->ct));
}
return 0;
}
size_t CGBitmapContextGetBitsPerComponent(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
switch (cairo_image_surface_get_format(cairo_get_target(ctx->ct)))
{
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
case CAIRO_FORMAT_A8:
return 8;
case CAIRO_FORMAT_A1:
return 1;
default:
return 0;
}
}
return 0;
}
size_t CGBitmapContextGetBitsPerPixel(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
switch (cairo_image_surface_get_format(cairo_get_target(ctx->ct)))
{
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
return 32;
case CAIRO_FORMAT_A8:
return 8;
case CAIRO_FORMAT_A1:
return 1;
default:
return 0;
}
}
return 0;
}
size_t CGBitmapContextGetBytesPerRow(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return cairo_image_surface_get_stride(cairo_get_target(ctx->ct));
}
return 0;
}
CGColorSpaceRef CGBitmapContextGetColorSpace(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return ((CGBitmapContext*)ctx)->cs;
}
return nil;
}
void *CGBitmapContextGetData(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return cairo_image_surface_get_data(cairo_get_target(ctx->ct));
}
return 0;
}
size_t CGBitmapContextGetHeight(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return cairo_image_surface_get_height(cairo_get_target(ctx->ct));
}
return 0;
}
size_t CGBitmapContextGetWidth(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
return cairo_image_surface_get_width(cairo_get_target(ctx->ct));
}
return 0;
}
static void OpalReleaseContext(void *info, const void *data, size_t size)
{
CGContextRelease(info);
}
CGImageRef CGBitmapContextCreateImage(CGContextRef ctx)
{
if ([ctx isKindOfClass: [CGBitmapContext class]])
{
CGDataProviderRef dp = CGDataProviderCreateWithData(
CGContextRetain(ctx),
CGBitmapContextGetData(ctx),
CGBitmapContextGetBytesPerRow(ctx) * CGBitmapContextGetHeight(ctx),
OpalReleaseContext
);
CGImageRef img = CGImageCreate(
CGBitmapContextGetWidth(ctx),
CGBitmapContextGetHeight(ctx),
CGBitmapContextGetBitsPerComponent(ctx),
CGBitmapContextGetBitsPerPixel(ctx),
CGBitmapContextGetBytesPerRow(ctx),
CGBitmapContextGetColorSpace(ctx),
CGBitmapContextGetBitmapInfo(ctx),
dp,
NULL,
true,
kCGRenderingIntentDefault
);
CGDataProviderRelease(dp);
return img;
}
return nil;
}

View file

@ -0,0 +1,40 @@
/** <title>CGColor</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGColor.h"
@interface CGColor : NSObject
{
@public
CGColorSpaceRef cspace;
CGFloat *comps;
CGPatternRef pattern;
}
- (CGColor*) transformToColorSpace: (CGColorSpaceRef)space withRenderingIntent: (CGColorRenderingIntent)intent;
@end
CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, CGColorRenderingIntent intent);

View file

@ -0,0 +1,286 @@
/** <title>CGColor</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGContext.h"
#include "CoreGraphics/CGColor.h"
#import "CGColor-private.h"
#import "CGColorSpace-private.h"
#import "OPImageConversion.h"
const CFStringRef kCGColorWhite = @"kCGColorWhite";
const CFStringRef kCGColorBlack = @"kCGColorBlack";
const CFStringRef kCGColorClear = @"kCGColorClear";
static CGColorRef _whiteColor;
static CGColorRef _blackColor;
static CGColorRef _clearColor;
@implementation CGColor
- (id) initWithColorSpace: (CGColorSpaceRef)cs components: (const CGFloat*)components
{
self = [super init];
if (nil == self) return nil;
size_t nc, i;
nc = CGColorSpaceGetNumberOfComponents(cs);
NSLog(@"Create color with %d comps", nc);
self->comps = malloc((nc+1)*sizeof(CGFloat));
if (NULL == self->comps) {
NSLog(@"malloc failed");
[self release];
return nil;
}
self->cspace = CGColorSpaceRetain(cs);
self->pattern = nil;
for (i=0; i<=nc; i++)
self->comps[i] = components[i];
return self;
}
- (void) dealloc
{
CGColorSpaceRelease(self->cspace);
CGPatternRelease(self->pattern);
free(self->comps);
[super dealloc];
}
- (BOOL) isEqual: (id)other
{
if (![other isKindOfClass: [CGColor class]]) return NO;
CGColor *otherColor = (CGColor *)other;
int nc = CGColorSpaceGetNumberOfComponents(self->cspace);
if (![self->cspace isEqual: otherColor->cspace]) return NO;
if (![self->pattern isEqual: otherColor->pattern]) return NO;
for (int i = 0; i <= nc; i++) {
if (self->comps[i] != otherColor->comps[i])
return NO;
}
return YES;
}
- (CGColor*) transformToColorSpace: (CGColorSpaceRef)destSpace withRenderingIntent: (CGColorRenderingIntent)intent
{
CGColorSpaceRef sourceSpace = CGColorGetColorSpace(self);
// FIXME: this is ugly because CGColor uses CGFloats, but OPColorTransform only accepts
// 32-bit float components.
float originalComps[CGColorSpaceGetNumberOfComponents(sourceSpace) + 1];
float tranformedComps[CGColorSpaceGetNumberOfComponents(destSpace) + 1];
for (size_t i=0; i < CGColorSpaceGetNumberOfComponents(sourceSpace) + 1; i++)
{
originalComps[i] = comps[i];
}
OPImageFormat sourceFormat;
sourceFormat.compFormat = kOPComponentFormatFloat32bpc;
sourceFormat.colorComponents = CGColorSpaceGetNumberOfComponents(sourceSpace);
sourceFormat.hasAlpha = true;
sourceFormat.isAlphaPremultiplied = false;
sourceFormat.isAlphaLast = true;
OPImageFormat destFormat;
destFormat.compFormat = kOPComponentFormatFloat32bpc;
destFormat.colorComponents = CGColorSpaceGetNumberOfComponents(destSpace);
destFormat.hasAlpha = true;
destFormat.isAlphaPremultiplied = false;
destFormat.isAlphaLast = true;
id<OPColorTransform> xform = [sourceSpace colorTransformTo: destSpace
sourceFormat: sourceFormat
destinationFormat: destFormat
renderingIntent: intent
pixelCount: 1];
[xform transformPixelData: (const unsigned char *)originalComps
output: (unsigned char *)tranformedComps];
CGFloat cgfloatTransformedComps[CGColorSpaceGetNumberOfComponents(destSpace) + 1];
for (size_t i=0; i < CGColorSpaceGetNumberOfComponents(destSpace) + 1; i++)
{
cgfloatTransformedComps[i] = tranformedComps[i];
}
// FIXME: release xform?
return [[[CGColor alloc] initWithColorSpace: destSpace components: cgfloatTransformedComps] autorelease];
}
@end
CGColorRef CGColorCreate(CGColorSpaceRef colorspace, const CGFloat components[])
{
CGColor *clr = [[CGColor alloc] initWithColorSpace: colorspace components: components];
return clr;
}
CFTypeID CGColorGetTypeID()
{
return (CFTypeID)[CGColor class];
}
CGColorRef CGColorRetain(CGColorRef clr)
{
return [clr retain];
}
void CGColorRelease(CGColorRef clr)
{
[clr release];
}
CGColorRef CGColorCreateCopy(CGColorRef clr)
{
return CGColorCreate(clr->cspace, clr->comps);
}
CGColorRef CGColorCreateCopyWithAlpha(CGColorRef clr, CGFloat alpha)
{
CGColorRef newclr;
newclr = CGColorCreate(clr->cspace, clr->comps);
if (!newclr) return nil;
newclr->comps[CGColorSpaceGetNumberOfComponents(newclr->cspace)] = alpha;
return newclr;
}
CGColorRef CGColorCreateGenericCMYK(
CGFloat cyan,
CGFloat magenta,
CGFloat yellow,
CGFloat black,
CGFloat alpha)
{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceCMYK();
const CGFloat components[] = {cyan, magenta, yellow, black, alpha};
CGColorRef clr = CGColorCreate(colorspace, components);
CGColorSpaceRelease(colorspace);
return clr;
}
CGColorRef CGColorCreateGenericGray(CGFloat gray, CGFloat alpha)
{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
const CGFloat components[] = {gray, alpha};
CGColorRef clr = CGColorCreate(colorspace, components);
CGColorSpaceRelease(colorspace);
return clr;
}
CGColorRef CGColorCreateGenericRGB(
CGFloat red,
CGFloat green,
CGFloat blue,
CGFloat alpha)
{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
const CGFloat components[] = {red, green, blue, alpha};
CGColorRef clr = CGColorCreate(colorspace, components);
CGColorSpaceRelease(colorspace);
return clr;
}
CGColorRef CGColorCreateWithPattern(
CGColorSpaceRef colorspace,
CGPatternRef pattern,
const CGFloat components[])
{
CGColorRef clr = CGColorCreate(colorspace, components);
clr->pattern = CGPatternRetain(pattern);
return clr;
}
bool CGColorEqualToColor(CGColorRef color1, CGColorRef color2)
{
return [color1 isEqual: color2];
}
CGFloat CGColorGetAlpha(CGColorRef clr)
{
int alphaIndex = CGColorSpaceGetNumberOfComponents(clr->cspace);
return clr->comps[alphaIndex];
}
CGColorSpaceRef CGColorGetColorSpace(CGColorRef clr)
{
return clr->cspace;
}
const CGFloat *CGColorGetComponents(CGColorRef clr)
{
return clr->comps;
}
CGColorRef CGColorGetConstantColor(CFStringRef name)
{
if ([name isEqual: kCGColorWhite])
{
if (nil == _whiteColor)
{
_whiteColor = CGColorCreateGenericGray(1, 1);
}
return _whiteColor;
}
else if ([name isEqual: kCGColorBlack])
{
if (nil == _blackColor)
{
_blackColor = CGColorCreateGenericGray(0, 1);
}
return _blackColor;
}
else if ([name isEqual: kCGColorClear])
{
if (nil == _clearColor)
{
_clearColor = CGColorCreateGenericGray(0, 0);
}
return _clearColor;
}
return nil;
}
size_t CGColorGetNumberOfComponents(CGColorRef clr)
{
return CGColorSpaceGetNumberOfComponents(clr->cspace);
}
CGPatternRef CGColorGetPattern(CGColorRef clr)
{
return clr->pattern;
}
CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, CGColorRenderingIntent intent)
{
return [clr transformToColorSpace: space withRenderingIntent: intent];
}

View file

@ -0,0 +1,81 @@
/** <title>CGColorSpace</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGColorSpace.h"
#import "OPImageConversion.h"
@protocol OPColorTransform <NSObject>
- (void) transformPixelData: (const unsigned char *)input
output: (unsigned char *)output;
@end
/**
* Abstract superclass for color spaces.
*/
@protocol CGColorSpace <NSObject>
+ (id<CGColorSpace>)colorSpaceGenericGray;
+ (id<CGColorSpace>)colorSpaceGenericRGB;
+ (id<CGColorSpace>)colorSpaceGenericCMYK;
+ (id<CGColorSpace>)colorSpaceGenericRGBLinear;
+ (id<CGColorSpace>)colorSpaceAdobeRGB1998;
+ (id<CGColorSpace>)colorSpaceSRGB;
+ (id<CGColorSpace>)colorSpaceGenericGrayGamma2_2;
- (BOOL)isEqual: (id)other;
- (NSData*)ICCProfile;
- (NSString*)name;
- (id)initWithCalibratedGrayWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
gamma: (CGFloat)gamma;
- (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
gamma: (const CGFloat *)gamma
matrix: (const CGFloat *)matrix;
- (id)initICCBasedWithComponents: (size_t)nComponents
range: (const CGFloat*)range
profile: (CGDataProviderRef)profile
alternateSpace: (CGColorSpaceRef)alternateSpace;
- (CGColorSpaceRef) initLabWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
range: (const CGFloat*)range;
- (CGColorSpaceRef) initWithICCProfile: (CFDataRef)data;
- (CGColorSpaceRef) initWithPlatformColorSpace: (void *)platformColorSpace;
- (CGColorSpaceModel) model;
- (size_t) numberOfComponents;
- (id<OPColorTransform>) colorTransformTo: (id<CGColorSpace>)aColorSpace
sourceFormat: (OPImageFormat)aSourceFormat
destinationFormat: (OPImageFormat)aDestFormat
renderingIntent: (CGColorRenderingIntent)anIntent
pixelCount: (size_t)aPixelCount;
@end

View file

@ -0,0 +1,257 @@
/** <title>CGColorSpace</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSString.h>
#include "CoreGraphics/CGColorSpace.h"
#import "CGColorSpace-private.h"
#import "OPColorSpaceIndexed.h"
const CFStringRef kCGColorSpaceGenericGray = @"kCGColorSpaceGenericGray";
const CFStringRef kCGColorSpaceGenericRGB = @"kCGColorSpaceGenericRGB";
const CFStringRef kCGColorSpaceGenericCMYK = @"kCGColorSpaceGenericCMYK";
const CFStringRef kCGColorSpaceGenericRGBLinear = @"kCGColorSpaceGenericRGBLinear";
const CFStringRef kCGColorSpaceAdobeRGB1998 = @"kCGColorSpaceAdobeRGB1998";
const CFStringRef kCGColorSpaceSRGB = @"kCGColorSpaceSRGB";
const CFStringRef kCGColorSpaceGenericGrayGamma2_2 = @"kCGColorSpaceGenericGrayGamma2_2";
/**
* This is a fallback only used when building Opal without LittleCMS.
* Note that it doesn't do any color management.
*/
#if 0
static void opal_todev_rgb(CGFloat *dest, const CGFloat comps[])
{
dest[0] = comps[0];
dest[1] = comps[1];
dest[2] = comps[2];
dest[3] = comps[3];
}
static void opal_todev_gray(CGFloat *dest, const CGFloat comps[])
{
dest[0] = comps[0];
dest[1] = comps[0];
dest[2] = comps[0];
dest[3] = comps[1];
}
static void opal_todev_cmyk(CGFloat *dest, const CGFloat comps[])
{
// DeviceCMYK to DeviceRGB conversion from PostScript Language Reference
// section 7.2.4
dest[0] = 1 - MIN(1.0, comps[0] + comps[3]);
dest[1] = 1 - MIN(1.0, comps[1] + comps[3]);
dest[2] = 1 - MIN(1.0, comps[2] + comps[3]);
dest[3] = comps[4];
}
#endif
Class OPColorSpaceClass()
{
// FIXME:
return NSClassFromString(@"OPColorSpaceLCMS");
}
CFDataRef CGColorSpaceCopyICCProfile(CGColorSpaceRef cs)
{
return [cs ICCProfile];
}
CFStringRef CGColorSpaceCopyName(CGColorSpaceRef cs)
{
return [cs name];
}
CGColorSpaceRef CGColorSpaceCreateCalibratedGray(
const CGFloat *whitePoint,
const CGFloat *blackPoint,
CGFloat gamma)
{
return [[OPColorSpaceClass() alloc]
initWithCalibratedGrayWithWhitePoint: whitePoint
blackPoint: blackPoint
gamma: gamma];
}
CGColorSpaceRef CGColorSpaceCreateCalibratedRGB(
const CGFloat *whitePoint,
const CGFloat *blackPoint,
const CGFloat *gamma,
const CGFloat *matrix)
{
return [[OPColorSpaceClass() alloc]
initWithCalibratedRGBWithWhitePoint: whitePoint
blackPoint: blackPoint
gamma: gamma
matrix: matrix];
}
CGColorSpaceRef CGColorSpaceCreateDeviceCMYK()
{
return [[OPColorSpaceClass() colorSpaceGenericCMYK] retain];
}
CGColorSpaceRef CGColorSpaceCreateDeviceGray()
{
return [[OPColorSpaceClass() colorSpaceGenericGray] retain];
}
CGColorSpaceRef CGColorSpaceCreateDeviceRGB()
{
return [[OPColorSpaceClass() colorSpaceSRGB] retain];
}
CGColorSpaceRef CGColorSpaceCreateICCBased(
size_t nComponents,
const CGFloat *range,
CGDataProviderRef profile,
CGColorSpaceRef alternateSpace)
{
return [[OPColorSpaceClass() alloc] initICCBasedWithComponents: nComponents
range: range
profile: profile
alternateSpace: alternateSpace];
}
CGColorSpaceRef CGColorSpaceCreateIndexed(
CGColorSpaceRef baseSpace,
size_t lastIndex,
const unsigned char *colorTable)
{
return [[OPColorSpaceIndexed alloc] initWithBaseSpace: baseSpace
lastIndex: lastIndex
colorTable: colorTable];
}
CGColorSpaceRef CGColorSpaceCreateLab(
const CGFloat *whitePoint,
const CGFloat *blackPoint,
const CGFloat *range)
{
return [[OPColorSpaceClass() alloc] initLabWithWhitePoint: whitePoint
blackPoint: blackPoint
range: range];
}
CGColorSpaceRef CGColorSpaceCreatePattern(CGColorSpaceRef baseSpace)
{
// FIXME: implement
return nil;
}
CGColorSpaceRef CGColorSpaceCreateWithICCProfile(CFDataRef data)
{
return [[OPColorSpaceClass() alloc] initWithICCProfile: data];
}
CGColorSpaceRef CGColorSpaceCreateWithName(CFStringRef name)
{
if ([name isEqualToString: kCGColorSpaceGenericGray])
{
return [[OPColorSpaceClass() colorSpaceGenericGray] retain];
}
else if ([name isEqualToString: kCGColorSpaceGenericRGB])
{
return [[OPColorSpaceClass() colorSpaceGenericRGB] retain];
}
else if ([name isEqualToString: kCGColorSpaceGenericCMYK])
{
return [[OPColorSpaceClass() colorSpaceGenericCMYK] retain];
}
else if ([name isEqualToString: kCGColorSpaceGenericRGBLinear])
{
return [[OPColorSpaceClass() colorSpaceGenericRGBLinear] retain];
}
else if ([name isEqualToString: kCGColorSpaceAdobeRGB1998])
{
return [[OPColorSpaceClass() colorSpaceAdobeRGB1998] retain];
}
else if ([name isEqualToString: kCGColorSpaceSRGB])
{
return [[OPColorSpaceClass() colorSpaceSRGB] retain];
}
else if ([name isEqualToString: kCGColorSpaceGenericGrayGamma2_2])
{
return [[OPColorSpaceClass() colorSpaceGenericGrayGamma2_2] retain];
}
return nil;
}
CGColorSpaceRef CGColorSpaceCreateWithPlatformColorSpace(
void *platformColorSpace)
{
return [[OPColorSpaceClass() alloc] initWithPlatformColorSpace: platformColorSpace];
}
CGColorSpaceRef CGColorSpaceGetBaseColorSpace(CGColorSpaceRef cs)
{
// FIXME: fail silently on non-indexed space?
return [(OPColorSpaceIndexed*)cs baseColorSpace];
}
void CGColorSpaceGetColorTable(CGColorSpaceRef cs, unsigned char *table)
{
// FIXME: fail silently on non-indexed space?
[(OPColorSpaceIndexed*)cs getColorTable: table];
}
size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef cs)
{
// FIXME: fail silently on non-indexed space?
return [(OPColorSpaceIndexed*)cs colorTableCount];
}
CGColorSpaceModel CGColorSpaceGetModel(CGColorSpaceRef cs)
{
return [cs model];
}
size_t CGColorSpaceGetNumberOfComponents(CGColorSpaceRef cs)
{
return [cs numberOfComponents];
}
CFTypeID CGColorSpaceGetTypeID()
{
return (CFTypeID)OPColorSpaceClass();
}
CGColorSpaceRef CGColorSpaceRetain(CGColorSpaceRef cs)
{
return [cs retain];
}
void CGColorSpaceRelease(CGColorSpaceRef cs)
{
[cs release];
}

View file

@ -0,0 +1,71 @@
/** <title>CGContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OPAL_CGContext_private_h
#define OPAL_CGContext_private_h
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGContext.h"
#include <cairo.h>
typedef struct ct_additions ct_additions;
struct ct_additions
{
ct_additions *next; /* for Save/Restore */
double alpha;
CGColorRef fill_color;
cairo_pattern_t *fill_cp;
CGColorRef stroke_color;
cairo_pattern_t *stroke_cp;
CGColorRef shadow_color;
cairo_pattern_t *shadow_cp; //FIXME: Don't need this
CGSize shadow_offset;
CGFloat shadow_radius;
CGFontRef font;
CGFloat font_size;
CGFloat char_spacing;
CGTextDrawingMode text_mode;
};
@interface CGContext : NSObject
{
@public
cairo_t *ct; /* A Cairo context -- destination of this CGContext */
ct_additions *add; /* Additional things not in Cairo's gstate */
CGAffineTransform txtmatrix;
CGFloat scale_factor;
CGSize device_size;
}
- (id) initWithSurface: (cairo_surface_t *)target size: (CGSize)size;
@end
CGContextRef opal_new_CGContext(cairo_surface_t *target, CGSize device_size);
void opal_draw_surface_in_rect(CGContextRef ctxt, CGRect dest, cairo_surface_t *src, CGRect srcRect);
void OPContextSetSize(CGContextRef ctxt, CGSize size);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,27 @@
/** <title>CGDataConsumer</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: June, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGDataConsumer.h"
size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, size_t count);

View file

@ -0,0 +1,153 @@
/** <title>CGDataConsumer</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: June, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSData.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSFileHandle.h>
#include "CoreGraphics/CGDataConsumer.h"
@interface CGDataConsumer : NSObject
{
@public
CGDataConsumerCallbacks cb;
void *info;
}
@end
@implementation CGDataConsumer
- (id) initWithCallbacks: (CGDataConsumerCallbacks)callbacks info: (void*)i
{
self = [super init];
cb = callbacks;
info = i;
return self;
}
- (void) dealloc
{
if (cb.releaseConsumer)
{
cb.releaseConsumer(info);
}
[super dealloc];
}
@end
/* Opal-internal access */
size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, size_t count)
{
if (NULL != dc)
{
return dc->cb.putBytes(
dc->info,
buffer,
count);
}
return 0;
}
/* URL consumer */
static size_t opal_URLConsumerPutBytes(
void *info,
const void *buffer,
size_t count)
{
NSData *data = [[NSData alloc] initWithBytesNoCopy: (void*)buffer
length: count
freeWhenDone: NO];
// FIXME: catch exceptions?
[(NSFileHandle*)info writeData: data];
[data release];
return count;
}
static void opal_URLConsumerReleaseInfo(void *info)
{
[(NSFileHandle*)info release];
}
/* CFData consumer */
static size_t opal_CFDataConsumerPutBytes(
void *info,
const void *buffer,
size_t count)
{
[(NSMutableData*)info appendBytes: buffer length: count];
return count;
}
static void opal_CFDataConsumerReleaseInfo(void *info)
{
[(NSMutableData*)info release];
}
/* Functions */
CGDataConsumerRef CGDataConsumerCreate(
void *info,
const CGDataConsumerCallbacks *callbacks)
{
return [[CGDataConsumer alloc] initWithCallbacks: *callbacks info: info];
}
CGDataConsumerRef CGDataConsumerCreateWithCFData(CFMutableDataRef data)
{
CGDataConsumerCallbacks opal_CFDataConsumerCallbacks = {
opal_CFDataConsumerPutBytes, opal_CFDataConsumerReleaseInfo
};
return CGDataConsumerCreate([data retain], &opal_CFDataConsumerCallbacks);
}
CGDataConsumerRef CGDataConsumerCreateWithURL(CFURLRef url)
{
CGDataConsumerCallbacks opal_URLConsumerCallbacks = {
opal_URLConsumerPutBytes, opal_URLConsumerReleaseInfo
};
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath: [(NSURL*)url path]];
return CGDataConsumerCreate([handle retain], &opal_URLConsumerCallbacks);
}
CFTypeID CGDataConsumerGetTypeID()
{
return (CFTypeID)[CGDataConsumer class];
}
void CGDataConsumerRelease(CGDataConsumerRef consumer)
{
[consumer release];
}
CGDataConsumerRef CGDataConsumerRetain(CGDataConsumerRef consumer)
{
return [consumer retain];
}

View file

@ -0,0 +1,60 @@
/** <title>CGDataProvider</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: June, 2010
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGDataProvider.h"
/**
* These functions provide access to the data in a CGDataProvider.
* Sequential or Direct Access functions can be used regardless of the
* internal type of the data provider.
*/
/* Sequential Access */
size_t OPDataProviderGetBytes(CGDataProviderRef dp, void *buffer, size_t count);
off_t OPDataProviderSkipForward(CGDataProviderRef dp, off_t count);
void OPDataProviderRewind(CGDataProviderRef dp);
/* Direct Access */
size_t OPDataProviderGetSize(CGDataProviderRef dp);
const void *OPDataProviderGetBytePointer(CGDataProviderRef dp);
void OPDataProviderReleaseBytePointer(
CGDataProviderRef dp,
const void *pointer
);
size_t OPDataProviderGetBytesAtPosition(
CGDataProviderRef dp,
void *buffer,
off_t position,
size_t count
);

View file

@ -0,0 +1,583 @@
/** <title>CGDataProvider</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: June, 2010
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGDataProvider.h"
#import <Foundation/NSObject.h>
#import <Foundation/NSData.h>
#import <Foundation/NSString.h>
#import <Foundation/NSURL.h>
/**
* CGDataProvider abstract base class
*/
@interface CGDataProvider : NSObject
{
}
/* Opal internal access - Sequential */
- (size_t) getBytes: (void *)buffer count: (size_t)count;
- (off_t) skipForward: (off_t)count;
- (void) rewind;
/* Opal internal access - Direct */
- (size_t) size;
- (const void *)bytePointer;
- (void)releaseBytePointer: (const void *)pointer;
- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count;
- (CFDataRef) copyData;
@end
@implementation CGDataProvider
- (size_t)getBytes: (void *)buffer count: (size_t)count
{
[self doesNotRecognizeSelector: _cmd];
return (size_t)0;
}
- (off_t)skipForward: (off_t)count
{
[self doesNotRecognizeSelector: _cmd];
return (off_t)0;
}
- (void)rewind
{
[self doesNotRecognizeSelector: _cmd];
}
- (size_t)size
{
[self doesNotRecognizeSelector: _cmd];
return (size_t)0;
}
- (const void *)bytePointer
{
[self doesNotRecognizeSelector: _cmd];
return (const void *)NULL;
}
- (void)releaseBytePointer: (const void *)pointer
{
[self doesNotRecognizeSelector: _cmd];
}
- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count
{
[self doesNotRecognizeSelector: _cmd];
return (size_t)0;
}
- (CFDataRef)copyData
{
return [[NSData alloc] initWithBytes: [self bytePointer] length: [self size]];
}
@end
/**
* CGDataProvider subclass for direct data providers
*/
@interface CGDataProviderDirect : CGDataProvider
{
@public
size_t size;
off_t pos;
void *info;
CGDataProviderGetBytePointerCallback getBytePointerCallback;
CGDataProviderReleaseBytePointerCallback releaseBytePointerCallback;
CGDataProviderGetBytesAtOffsetCallback getBytesAtOffsetCallback;
CGDataProviderGetBytesAtPositionCallback getBytesAtPositionCallback;
CGDataProviderReleaseInfoCallback releaseInfoCallback;
}
@end
@implementation CGDataProviderDirect
- (void) dealloc
{
if (releaseInfoCallback)
{
releaseInfoCallback(info);
}
[super dealloc];
}
/* Opal internal access - Sequential */
- (size_t)getBytes: (void *)buffer count: (size_t)count
{
size_t bytesToCopy = MIN(count, (size - pos));
const void *bytePointer = [self bytePointer];
memcpy(buffer, bytePointer + pos, bytesToCopy);
[self releaseBytePointer: bytePointer];
pos += bytesToCopy;
return bytesToCopy;
}
- (off_t)skipForward: (off_t)count
{
pos += count;
return count;
}
- (void)rewind
{
pos = 0;
}
/* Opal internal access - Direct */
- (size_t)size
{
return size;
}
- (const void *)bytePointer
{
if (getBytePointerCallback)
{
return getBytePointerCallback(info);
}
return NULL;
}
- (void)releaseBytePointer: (const void *)pointer
{
if (releaseBytePointerCallback)
{
releaseBytePointerCallback(info, pointer);
}
}
- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count
{
if (getBytesAtOffsetCallback)
{
return getBytesAtOffsetCallback(info, buffer, position, count);
}
else if (getBytesAtPositionCallback)
{
return getBytesAtPositionCallback(info, buffer, (int)position, count);
}
return 0;
}
@end
/**
* CGDataProvider subclass for sequential data providers
*/
@interface CGDataProviderSequential : CGDataProvider
{
@public
void *info;
NSData *directBuffer;
CGDataProviderGetBytesCallback getBytesCallback;
CGDataProviderSkipBytesCallback skipBytesCallback;
CGDataProviderSkipForwardCallback skipForwardCallback;
CGDataProviderRewindCallback rewindCallback;
CGDataProviderReleaseInfoCallback releaseInfoCallback;
}
- (NSData *)directBuffer;
@end
@implementation CGDataProviderSequential
- (void) dealloc
{
if (releaseInfoCallback)
{
releaseInfoCallback(info);
}
[directBuffer release];
[super dealloc];
}
/* Opal internal access - Sequential */
- (size_t)getBytes: (void *)buffer count: (size_t)count
{
if (getBytesCallback)
{
return getBytesCallback(info, buffer, count);
}
return 0;
}
- (off_t)skipForward: (off_t)count
{
if (skipBytesCallback)
{
skipBytesCallback(info, count);
return count;
}
else if (skipForwardCallback)
{
return skipForwardCallback(info, count);
}
return 0;
}
- (void)rewind
{
if (rewindCallback)
{
rewindCallback(info);
}
}
/* Opal internal access - Direct */
- (NSData *)directBuffer
{
if (NULL == directBuffer)
{
NSMutableData *buf = [[NSMutableData alloc] initWithLength: 65536];
[self rewind];
size_t got;
off_t total = 0;
while ((got = [self getBytes: ([buf mutableBytes] + total) count: 65536]) > 0)
{
total += got;
[buf setLength: total + 65536];
}
[buf setLength: total];
directBuffer = buf;
}
return directBuffer;
}
- (size_t)size
{
return [[self directBuffer] length];
}
- (const void *)bytePointer
{
return [[self directBuffer] bytes];
}
- (void)releaseBytePointer: (const void *)pointer
{
;
}
- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count
{
size_t bytesToCopy = MIN(count, ([[self directBuffer] length] - position));
[[self directBuffer] getBytes:buffer range: NSMakeRange(position, bytesToCopy)];
return bytesToCopy;
}
@end
/* Opal internal access - Sequential */
size_t OPDataProviderGetBytes(CGDataProviderRef dp, void *buffer, size_t count)
{
return [dp getBytes: buffer count: count];
}
off_t OPDataProviderSkipForward(CGDataProviderRef dp, off_t count)
{
return [dp skipForward: count];
}
void OPDataProviderRewind(CGDataProviderRef dp)
{
[dp rewind];
}
/* Opal internal access - Direct */
size_t OPDataProviderGetSize(CGDataProviderRef dp)
{
return [dp size];
}
const void *OPDataProviderGetBytePointer(CGDataProviderRef dp)
{
return [dp bytePointer];
}
void OPDataProviderReleaseBytePointer(CGDataProviderRef dp, const void *pointer)
{
[dp releaseBytePointer: pointer];
}
size_t OPDataProviderGetBytesAtPositionCallback(
CGDataProviderRef dp,
void *buffer,
off_t position,
size_t count)
{
return [dp getBytes: buffer atPosition: position count: count];
}
/* Callbacks for ready-made CGDataProviders */
/* Data callbacks */
typedef struct DataInfo {
size_t size;
const void *data;
CGDataProviderReleaseDataCallback releaseData;
} DataInfo;
static const void *opal_DataGetBytePointer(void *info)
{
return ((DataInfo*)info)->data;
}
static void opal_DataReleaseBytePointer(void *info, const void *pointer)
{
;
}
static size_t opal_DataGetBytesAtPosition(
void *info,
void *buffer,
off_t position,
size_t count)
{
size_t bytesToCopy = MIN(count, (((DataInfo*)info)->size - position));
memcpy(buffer, ((DataInfo*)info)->data + position, bytesToCopy);
return bytesToCopy;
}
static void opal_DataReleaseInfo(void *info)
{
free((DataInfo*)info);
}
static const CGDataProviderDirectCallbacks opal_DataCallbacks = {
0,
opal_DataGetBytePointer,
opal_DataReleaseBytePointer,
opal_DataGetBytesAtPosition,
opal_DataReleaseInfo
};
/* CFData callbacks */
static const void *opal_CFDataGetBytePointer(void *info)
{
return [(NSData*)info bytes];
}
static void opal_CFDataReleaseBytePointer(void *info, const void *pointer)
{
;
}
static size_t opal_CFDataGetBytesAtPosition(
void *info,
void *buffer,
off_t position,
size_t count)
{
size_t bytesToCopy = MIN(count, ([(NSData*)info length] - position));
[(NSData*)info getBytes:buffer range: NSMakeRange(position, bytesToCopy)];
return bytesToCopy;
}
static void opal_CFDataReleaseInfo(void *info)
{
[(NSData*)info release];
}
static const CGDataProviderDirectCallbacks opal_CFDataCallbacks = {
0,
opal_CFDataGetBytePointer,
opal_CFDataReleaseBytePointer,
opal_CFDataGetBytesAtPosition,
opal_CFDataReleaseInfo
};
/* File callbacks */
static size_t opal_fileGetBytes(void *info, void *buffer, size_t count)
{
return fread(buffer, 1, count, (FILE*)info);
}
static off_t opal_fileSkipForward(void *info, off_t count)
{
fseek((FILE*)info, count, SEEK_CUR);
return count;
}
static void opal_fileRewind(void *info)
{
rewind((FILE*)info);
}
static void opal_fileReleaseInfo(void *info)
{
fclose((FILE*)info);
}
static const CGDataProviderSequentialCallbacks opal_fileCallbacks = {
0,
opal_fileGetBytes,
opal_fileSkipForward,
opal_fileRewind,
opal_fileReleaseInfo
};
/* Functions */
CFDataRef CGDataProviderCopyData(CGDataProviderRef provider)
{
return [(CGDataProvider*)provider copyData];
}
CGDataProviderRef CGDataProviderCreateDirect(
void *info,
off_t size,
const CGDataProviderDirectCallbacks *callbacks)
{
CGDataProviderDirect *provider = [[CGDataProviderDirect alloc] init];
provider->info = info;
provider->size = size;
provider->getBytePointerCallback = callbacks->getBytePointer;
provider->releaseBytePointerCallback = callbacks->releaseBytePointer;
provider->getBytesAtPositionCallback = callbacks->getBytesAtPosition;
provider->releaseInfoCallback = callbacks->releaseInfo;
return provider;
}
/**
* Deprecated
*/
CGDataProviderRef CGDataProviderCreateDirectAccess(
void *info,
size_t size,
const CGDataProviderDirectAccessCallbacks *callbacks)
{
CGDataProviderDirect *provider = [[CGDataProviderDirect alloc] init];
provider->info = info;
provider->size = size;
provider->getBytePointerCallback = callbacks->getBytePointer;
provider->releaseBytePointerCallback = callbacks->releaseBytePointer;
provider->getBytesAtOffsetCallback = callbacks->getBytes;
provider->releaseInfoCallback = callbacks->releaseProvider;
return provider;
}
CGDataProviderRef CGDataProviderCreateSequential(
void *info,
const CGDataProviderSequentialCallbacks *callbacks)
{
CGDataProviderSequential *provider = [[CGDataProviderSequential alloc] init];
provider->info = info;
provider->getBytesCallback = callbacks->getBytes;
provider->skipForwardCallback = callbacks->skipForward;
provider->rewindCallback = callbacks->rewind;
provider->releaseInfoCallback = callbacks->releaseInfo;
return provider;
}
/**
* Deprecated
*/
CGDataProviderRef CGDataProviderCreate(
void *info,
const CGDataProviderCallbacks *callbacks)
{
CGDataProviderSequential *provider = [[CGDataProviderSequential alloc] init];
provider->info = info;
provider->getBytesCallback = callbacks->getBytes;
provider->skipBytesCallback = callbacks->skipBytes;
provider->rewindCallback = callbacks->rewind;
provider->releaseInfoCallback = callbacks->releaseProvider;
return provider;
}
CGDataProviderRef CGDataProviderCreateWithData(
void *info,
const void *data,
size_t size,
void (*releaseData)(void *info, const void *data, size_t size))
{
DataInfo *i = malloc(sizeof(DataInfo));
i->size = size;
i->data = data;
i->releaseData = releaseData;
return CGDataProviderCreateDirect(i, size, &opal_DataCallbacks);
}
CGDataProviderRef CGDataProviderCreateWithCFData(CFDataRef data)
{
return CGDataProviderCreateDirect([(NSData*)data retain], [(NSData*)data length], &opal_CFDataCallbacks);
}
CGDataProviderRef CGDataProviderCreateWithURL(CFURLRef url)
{
return CGDataProviderCreateWithFilename([[(NSURL*)url path] UTF8String]);
}
CGDataProviderRef CGDataProviderCreateWithFilename(const char *filename)
{
FILE *info = fopen(filename, "rb");
if (NULL == info)
{
return nil;
}
return CGDataProviderCreateSequential(info, &opal_fileCallbacks);
}
CGDataProviderRef CGDataProviderRetain(CGDataProviderRef provider)
{
return [provider retain];
}
void CGDataProviderRelease(CGDataProviderRef provider)
{
[provider release];
}
CFTypeID CGDataProviderGetTypeID()
{
return (CFTypeID)[CGDataProvider class];
}

View file

@ -0,0 +1,322 @@
/** <title>CGFont</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: January, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGBase.h"
#include "CoreGraphics/CGDataProvider.h"
#include "CoreGraphics/CGFont.h"
#import "internal/CGFontInternal.h"
//FIXME: hack
#ifdef __MINGW__
#import "cairo/CairoFontWin32.h"
#else
#import "cairo/CairoFontX11.h"
#endif
@implementation CGFont
+ (Class) fontClass
{
#ifdef __MINGW__
return [CairoFontWin32 class];
#else
return [CairoFontX11 class];
#endif
}
- (bool) canCreatePostScriptSubset: (CGFontPostScriptFormat)format
{
[self doesNotRecognizeSelector: _cmd];
return false;
}
- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFDataRef) copyTableForTag: (uint32_t)tag
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFArrayRef) copyTableTags
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFArrayRef) copyVariationAxes
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFDictionaryRef) copyVariations
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CFDataRef) createPostScriptSubset: (CFStringRef)name
: (CGFontPostScriptFormat)format
: (const CGGlyph[])glyphs
: (size_t)count
: (const CGGlyph[])encoding
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
+ (CGFontRef) createWithDataProvider: (CGDataProviderRef)provider
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
+ (CGFontRef) createWithFontName: (CFStringRef)name
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
+ (CGFontRef) createWithPlatformFont: (void *)platformFontReference
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (bool) getGlyphAdvances: (const CGGlyph[])glyphs
: (size_t)count
: (int[]) advances
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (bool) getGlyphBBoxes: (const CGGlyph[])glyphs
: (size_t)count
: (CGRect[])bboxes
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName
{
[self doesNotRecognizeSelector: _cmd];
return 0;
}
@end
bool CGFontCanCreatePostScriptSubset(
CGFontRef font,
CGFontPostScriptFormat format)
{
return [font canCreatePostScriptSubset: format];
}
CFStringRef CGFontCopyFullName(CGFontRef font)
{
return font->fullName;
}
CFStringRef CGFontCopyGlyphNameForGlyph(CGFontRef font, CGGlyph glyph)
{
return [font copyGlyphNameForGlyph: glyph];
}
CFStringRef CGFontCopyPostScriptName(CGFontRef font)
{
return font->postScriptName;
}
CFDataRef CGFontCopyTableForTag(CGFontRef font, uint32_t tag)
{
return [font copyTableForTag: tag];
}
CFArrayRef CGFontCopyTableTags(CGFontRef font)
{
return [font copyTableTags];
}
CFArrayRef CGFontCopyVariationAxes(CGFontRef font)
{
return [font copyVariationAxes];
}
CFDictionaryRef CGFontCopyVariations(CGFontRef font)
{
return [font copyVariations];
}
CGFontRef CGFontCreateCopyWithVariations(
CGFontRef font,
CFDictionaryRef variations)
{
return [font createCopyWithVariations: variations];
}
CFDataRef CGFontCreatePostScriptEncoding(
CGFontRef font,
const CGGlyph encoding[256])
{
return [font createPostScriptEncoding: encoding];
}
CFDataRef CGFontCreatePostScriptSubset(
CGFontRef font,
CFStringRef name,
CGFontPostScriptFormat format,
const CGGlyph glyphs[],
size_t count,
const CGGlyph encoding[256])
{
return [font createPostScriptSubset: name : format : glyphs : count : encoding];
}
CGFontRef CGFontCreateWithDataProvider(CGDataProviderRef provider)
{
return [[CGFont fontClass] createWithDataProvider: provider];
}
CGFontRef CGFontCreateWithFontName(CFStringRef name)
{
return [[CGFont fontClass] createWithFontName: name];
}
CGFontRef CGFontCreateWithPlatformFont(void *platformFontReference)
{
return [[CGFont fontClass] createWithPlatformFont: platformFontReference];
}
int CGFontGetAscent(CGFontRef font)
{
return font->ascent;
}
int CGFontGetCapHeight(CGFontRef font)
{
return font->capHeight;
}
int CGFontGetDescent(CGFontRef font)
{
return font->descent;
}
CGRect CGFontGetFontBBox(CGFontRef font)
{
return font->fontBBox;
}
bool CGFontGetGlyphAdvances(
CGFontRef font,
const CGGlyph glyphs[],
size_t count,
int advances[])
{
return [font getGlyphAdvances: glyphs : count : advances];
}
bool CGFontGetGlyphBBoxes(
CGFontRef font,
const CGGlyph glyphs[],
size_t count,
CGRect bboxes[])
{
return [font getGlyphBBoxes: glyphs : count : bboxes];
}
CGGlyph CGFontGetGlyphWithGlyphName(CGFontRef font, CFStringRef glyphName)
{
return [font glyphWithGlyphName: glyphName];
}
CGFloat CGFontGetItalicAngle(CGFontRef font)
{
return font->italicAngle;
}
int CGFontGetLeading(CGFontRef font)
{
return font->leading;
}
size_t CGFontGetNumberOfGlyphs(CGFontRef font)
{
return font->numberOfGlyphs;
}
CGFloat CGFontGetStemV(CGFontRef font)
{
return font->stemV;
}
CFTypeID CGFontGetTypeID()
{
// FIXME: correct subclass?
return (CFTypeID)[CGFont fontClass];
}
int CGFontGetUnitsPerEm(CGFontRef font)
{
return font->unitsPerEm;
}
int CGFontGetXHeight(CGFontRef font)
{
return font->xHeight;
}
CGFontRef CGFontRetain(CGFontRef font)
{
return [font retain];
}
void CGFontRelease(CGFontRef font)
{
[font release];
}

View file

@ -0,0 +1,63 @@
/** <title>CGFunction</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGFunction.h"
@interface CGFunction : NSObject
{
@public
}
@end
@implementation CGFunction
@end
CGFunctionRef CGFunctionCreate(
void *info,
size_t domainDimension,
const CGFloat *domain,
size_t rangeDimension,
const CGFloat *range,
const CGFunctionCallbacks *callbacks)
{
CGFunctionRef func = [[CGFunction alloc] init];
//FIXME
return func;
}
CGFunctionRef CGFunctionRetain(CGFunctionRef function)
{
return [function retain];
}
void CGFunctionRelease(CGFunctionRef function)
{
[function release];
}

View file

@ -0,0 +1,222 @@
/** <title>CGGeometry</title>
<abstract>C Interface to graphics drawing library
- geometry routines</abstract>
Copyright (C) 1995,2002 Free Software Foundation, Inc.
Author: Adam Fedor <fedor@gnu.org>
Author: BALATON Zoltan <balaton@eik.bme.hu>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
/* Define IN_CGGEOMETRY_C so that the header can provide non-inline
* versions of the function implementations for us.
*/
#define IN_CGGEOMETRY_C
#include "CoreGraphics/CGGeometry.h"
#undef IN_CGGEOMETRY_C
#define _ISOC99_SOURCE
#include <math.h>
/* Constants */
const CGPoint CGPointZero = {0,0};
const CGSize CGSizeZero = {0,0};
const CGRect CGRectZero = {{0,0},{0,0}};
const CGRect CGRectNull = {{NAN,NAN},{NAN,NAN}};
const CGRect CGRectInfinite = {{INFINITY,INFINITY},{INFINITY,INFINITY}};
/* Functions */
int CGRectIsNull(CGRect rect)
{
return (isnan(rect.origin.x) || isnan(rect.origin.y) ||
isnan(rect.size.width) || isnan(rect.size.height)) ? 1 : 0;
}
int CGRectIsInfinite(CGRect rect)
{
return (isinf(rect.origin.x) || isinf(rect.origin.y) ||
isinf(rect.size.width) || isinf(rect.size.height)) ? 1 : 0;
}
CGRect CGRectIntegral(CGRect rect)
{
rect = CGRectStandardize(rect);
/* The order of the following is relevant: we change values we already used */
rect.size.width = ceil(rect.origin.x + rect.size.width);
rect.size.height = ceil(rect.origin.y + rect.size.height);
rect.origin.x = floor(rect.origin.x);
rect.origin.y = floor(rect.origin.y);
rect.size.width -= rect.origin.x;
rect.size.height -= rect.origin.y;
return rect;
}
CGRect CGRectIntersection(CGRect r1, CGRect r2)
{
CGRect rect;
/* If both of them are empty we can return r2 as an empty rect,
so this covers all cases: */
if (CGRectIsEmpty(r1))
return r2;
else if (CGRectIsEmpty(r2))
return r1;
r1 = CGRectStandardize(r1);
r2 = CGRectStandardize(r2);
if (r1.origin.x + r1.size.width <= r2.origin.x ||
r2.origin.x + r2.size.width <= r1.origin.x ||
r1.origin.y + r1.size.height <= r2.origin.y ||
r2.origin.y + r2.size.height <= r1.origin.y)
return CGRectNull;
rect.origin.x = (r1.origin.x > r2.origin.x ? r1.origin.x : r2.origin.x);
rect.origin.y = (r1.origin.y > r2.origin.y ? r1.origin.y : r2.origin.y);
if (r1.origin.x + r1.size.width < r2.origin.x + r2.size.width)
rect.size.width = r1.origin.x + r1.size.width - rect.origin.x;
else
rect.size.width = r2.origin.x + r2.size.width - rect.origin.x;
if (r1.origin.y + r1.size.height < r2.origin.y + r2.size.height)
rect.size.height = r1.origin.y + r1.size.height - rect.origin.y;
else
rect.size.height = r2.origin.y + r2.size.height - rect.origin.y;
return rect;
}
void CGRectDivide(CGRect rect, CGRect *slice, CGRect *remainder,
CGFloat amount, CGRectEdge edge)
{
static CGRect srect;
static CGRect rrect;
if (!slice)
slice = &srect;
if (!remainder)
remainder = &rrect;
if (amount < 0)
amount = 0;
rect = CGRectStandardize(rect);
*slice = rect;
*remainder = rect;
switch (edge) {
case CGRectMinXEdge:
remainder->origin.x += amount;
if (amount < rect.size.width) {
slice->size.width = amount;
remainder->size.width -= amount;
} else {
remainder->size.width = 0;
}
break;
case CGRectMinYEdge:
remainder->origin.y += amount;
if (amount < rect.size.height) {
slice->size.height = amount;
remainder->size.height -= amount;
} else {
remainder->size.height = 0;
}
break;
case CGRectMaxXEdge:
if (amount < rect.size.width) {
slice->origin.x += rect.size.width - amount;
slice->size.width = amount;
remainder->size.width -= amount;
} else {
remainder->size.width = 0;
}
break;
case CGRectMaxYEdge:
if (amount < rect.size.height) {
slice->origin.y += rect.size.height - amount;
slice->size.height = amount;
remainder->size.height -= amount;
} else {
remainder->size.height = 0;
}
break;
default:
break;
}
}
CGRect CGRectUnion(CGRect r1, CGRect r2)
{
CGRect rect;
/* If both of them are empty we can return r2 as an empty rect,
so this covers all cases: */
if (CGRectIsEmpty(r1))
return r2;
else if (CGRectIsEmpty(r2))
return r1;
r1 = CGRectStandardize(r1);
r2 = CGRectStandardize(r2);
rect.origin.x = MIN(r1.origin.x, r2.origin.x);
rect.origin.y = MIN(r1.origin.y, r2.origin.y);
rect.size.width = MAX(r1.origin.x + r1.size.width, r2.origin.x + r2.size.width);
rect.size.height = MAX(r1.origin.y + r1.size.height, r2.origin.y + r2.size.height);
return rect;
}
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point)
{
// FIXME: implement
return nil;
}
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point)
{
// FIXME: implement
return false;
}
CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size)
{
// FIXME: implement
return nil;
}
bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size)
{
// FIXME: implement
return false;
}
CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect)
{
// FIXME: implement
return nil;
}
bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect)
{
// FIXME: implement
return false;
}

View file

@ -0,0 +1,30 @@
/** <title>CGGradient</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGGradient.h"
CGColorSpaceRef OPGradientGetColorSpace(CGGradientRef g);
const CGFloat *OPGradientGetComponents(CGGradientRef g);
const CGFloat *OPGradientGetLocations(CGGradientRef g);
size_t OPGradientGetCount(CGGradientRef g);

View file

@ -0,0 +1,136 @@
/** <title>CGGradient</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#import <Foundation/NSArray.h>
#include "CoreGraphics/CGGradient.h"
#include "CoreGraphics/CGColor.h"
@interface CGGradient : NSObject
{
@public
CGColorSpaceRef cs;
CGFloat *components;
CGFloat *locations;
size_t count;
}
@end
@implementation CGGradient
- (id) initWithComponents: (const CGFloat[])comps
locations: (const CGFloat[])locs
count: (size_t) cnt
colorspace: (CGColorSpaceRef)cspace
{
self = [super init];
size_t numcomps = cnt * (CGColorSpaceGetNumberOfComponents(cspace) + 1);
components = malloc(numcomps * sizeof(CGFloat));
memcpy(components, comps, numcomps * sizeof(CGFloat));
locations = malloc(cnt * sizeof(CGFloat));
memcpy(locations, locs, cnt * sizeof(CGFloat));
count = cnt;
cs = CGColorSpaceRetain(cspace);
return self;
}
- (void) dealloc
{
free(components);
free(locations);
CGColorSpaceRelease(cs);
[super dealloc];
}
- (id) copyWithZone: (NSZone*)zone
{
return [self retain];
}
@end
/* Private */
CGColorSpaceRef OPGradientGetColorSpace(CGGradientRef g)
{
return g->cs;
}
const CGFloat *OPGradientGetComponents(CGGradientRef g)
{
return g->components;
}
const CGFloat *OPGradientGetLocations(CGGradientRef g)
{
return g->locations;
}
size_t OPGradientGetCount(CGGradientRef g)
{
return g->count;
}
/* Public */
CGGradientRef CGGradientCreateWithColorComponents(
CGColorSpaceRef cs,
const CGFloat components[],
const CGFloat locations[],
size_t count)
{
return [[CGGradient alloc] initWithComponents: components locations: locations count: count colorspace: cs];
}
CGGradientRef CGGradientCreateWithColors(
CGColorSpaceRef cs,
CFArrayRef colors,
const CGFloat locations[])
{
size_t count = [colors count];
size_t cs_numcomps = CGColorSpaceGetNumberOfComponents(cs) + 1;
CGFloat components[count * cs_numcomps];
for (int i=0; i<count; i++)
{
CGColorRef clr = [colors objectAtIndex: i];
memcpy(&components[i*cs_numcomps], CGColorGetComponents(clr), cs_numcomps * sizeof(CGFloat));
}
return CGGradientCreateWithColorComponents(cs, components, locations, count);
}
CFTypeID CGGradientGetTypeID()
{
return (CFTypeID)[CGGradient class];
}
CGGradientRef CGGradientRetain(CGGradientRef grad)
{
return [grad retain];
}
void CGGradientRelease(CGGradientRef grad)
{
[grad release];
}

View file

@ -0,0 +1,544 @@
/** <title>CGImage</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGImage.h"
#include "CoreGraphics/CGImageSource.h"
#include "CGDataProvider-private.h"
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#include <stdlib.h>
#include <cairo.h>
#import "OPImageConversion.h"
void DumpPixel(const void *data, NSString *msg)
{
NSLog(@"%@: (%02x,%02x,%02x,%02x)", msg, (int)(((unsigned char*)data)[0]),
(int)(((unsigned char*)data)[1]),
(int)(((unsigned char*)data)[2]),
(int)(((unsigned char*)data)[3]));
}
@interface CGImage : NSObject
{
@public
bool ismask;
size_t width;
size_t height;
size_t bitsPerComponent;
size_t bitsPerPixel;
size_t bytesPerRow;
CGDataProviderRef dp;
CGFloat *decode;
bool shouldInterpolate;
/* alphaInfo is always AlphaNone for mask */
CGBitmapInfo bitmapInfo;
/* cspace and intent are only set for image */
CGColorSpaceRef cspace;
CGColorRenderingIntent intent;
/* used for CGImageCreateWithImageInRect */
CGRect crop;
cairo_surface_t *surf;
}
@end
@implementation CGImage
- (id) initWithWidth: (size_t)aWidth
height: (size_t)aHeight
bitsPerComponent: (size_t)aBitsPerComponent
bitsPerPixel: (size_t)aBitsPerPixel
bytesPerRow: (size_t)aBytesPerRow
colorSpace: (CGColorSpaceRef)aColorspace
bitmapInfo: (CGBitmapInfo)aBitmapInfo
provider: (CGDataProviderRef)aProvider
decode: (const CGFloat *)aDecode
shouldInterpolate: (bool)anInterpolate
intent: (CGColorRenderingIntent)anIntent
{
self = [super init];
if (nil == self)
{
[super release];
return nil;
}
size_t numComponents;
if ((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaOnly)
{
numComponents = 0;
}
else
{
numComponents = CGColorSpaceGetNumberOfComponents(aColorspace);
}
const bool hasAlpha =
((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedLast) ||
((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) ||
((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaLast) ||
((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaFirst) ||
((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaOnly);
const size_t numComponentsIncludingAlpha = numComponents + (hasAlpha ? 1 : 0);
if (aBitsPerComponent < 1 || aBitsPerComponent > 32)
{
NSLog(@"Unsupported bitsPerComponent: %d", aBitsPerComponent);
[self release];
return nil;
}
if ((aBitmapInfo & kCGBitmapFloatComponents) != 0 && aBitsPerComponent != 32)
{
NSLog(@"Only 32 bitsPerComponents supported for float components");
[self release];
return nil;
}
if (aBitsPerPixel < aBitsPerComponent * numComponentsIncludingAlpha)
{
// Note if an alpha channel is requrested, we require it to be the same size
// as the other components
NSLog(@"Too few bitsPerPixel for bitsPerComponent");
[self release];
return nil;
}
if(aDecode && numComponents) {
size_t i;
self->decode = malloc(2 * numComponents * sizeof(CGFloat));
if (!self->decode)
{
NSLog(@"Malloc failed");
[self release];
return nil;
}
for(i = 0; i < 2 * numComponents; i++)
{
self->decode[i] = aDecode[i];
}
}
self->ismask = false;
self->width = aWidth;
self->height = aHeight;
self->bitsPerComponent = aBitsPerComponent;
self->bitsPerPixel = aBitsPerPixel;
self->bytesPerRow = aBytesPerRow;
self->dp = CGDataProviderRetain(aProvider);
self->shouldInterpolate = anInterpolate;
self->crop = CGRectNull;
self->surf = NULL;
self->bitmapInfo = aBitmapInfo;
self->cspace = CGColorSpaceRetain(aColorspace);
self->intent = intent;
return self;
}
- (id) copyWithZone: (NSZone*)zone
{
return [self retain];
}
- (void) dealloc
{
CGColorSpaceRelease(self->cspace);
CGDataProviderRelease(self->dp);
if (self->decode) free(self->decode);
if (self->surf) cairo_surface_destroy(self->surf);
[super dealloc];
}
- (NSString *)description
{
return [NSString stringWithFormat: @"<CGImage %p width: %d height: %d bits-per-component: %d bpp: %d bytes-per-row: %d provider: %@ shouldInterpolate: %d>", self, (int)width, (int)height, (int)bitsPerComponent, (int)bitsPerPixel, (int)bytesPerRow, dp, (int)shouldInterpolate];
}
@end
CGImageRef CGImageCreate(
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bitsPerPixel,
size_t bytesPerRow,
CGColorSpaceRef colorspace,
CGBitmapInfo bitmapInfo,
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent)
{
return [[CGImage alloc] initWithWidth: width
height: height
bitsPerComponent: bitsPerComponent
bitsPerPixel: bitsPerPixel
bytesPerRow: bytesPerRow
colorSpace: colorspace
bitmapInfo: bitmapInfo
provider: provider
decode: decode
shouldInterpolate: shouldInterpolate
intent: intent];
}
CGImageRef CGImageMaskCreate(
size_t width, size_t height,
size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow,
CGDataProviderRef provider, const CGFloat decode[], bool shouldInterpolate)
{
CGImageRef img = [[CGImage alloc] initWithWidth: width
height: height
bitsPerComponent: bitsPerComponent
bitsPerPixel: bitsPerPixel
bytesPerRow: bytesPerRow
colorSpace: nil // FIXME
bitmapInfo: 0 // FIXME
provider: provider
decode: decode
shouldInterpolate: shouldInterpolate
intent: 0]; // FIXME
if (!img)
{
return nil;
}
img->ismask = true;
return img;
}
CGImageRef CGImageCreateCopy(CGImageRef image)
{
return [image retain];
}
CGImageRef CGImageCreateCopyWithColorSpace(
CGImageRef image,
CGColorSpaceRef colorspace)
{
CGImageRef new;
// FIXME: is this supposed to convert pixel data?
if (image->ismask ||
CGColorSpaceGetNumberOfComponents(image->cspace)
!= CGColorSpaceGetNumberOfComponents(colorspace))
{
return nil;
}
else
{
new = CGImageCreate(image->width, image->height,
image->bitsPerComponent, image->bitsPerPixel, image->bytesPerRow,
colorspace, image->bitmapInfo, image->dp, image->decode,
image->shouldInterpolate, image->intent);
}
if (!new) return NULL;
// Since CGImage is immutable, we can reference the source image's surface
if (image->surf)
{
new->surf = cairo_surface_reference(image->surf);
}
return new;
}
CGImageRef CGImageCreateWithImageInRect(
CGImageRef image,
CGRect rect)
{
CGImageRef new = CGImageCreate(image->width, image->height,
image->bitsPerComponent, image->bitsPerPixel, image->bytesPerRow,
image->cspace, image->bitmapInfo, image->dp, image->decode,
image->shouldInterpolate, image->intent);
if (!new) return NULL;
// Set the crop rect
rect = CGRectIntegral(rect);
rect = CGRectIntersection(rect, CGRectMake(0, 0, image->width, image->height));
new->crop = rect;
return new;
}
CGImageRef CGImageCreateWithMaskingColors (
CGImageRef image,
const CGFloat components[])
{
//FIXME: Implement
return nil;
}
static CGImageRef createWithDataProvider(
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent,
CFStringRef type)
{
NSDictionary *opts = [[NSDictionary alloc] initWithObjectsAndKeys:
type, kCGImageSourceTypeIdentifierHint,
nil];
CGImageSourceRef src = CGImageSourceCreateWithDataProvider(provider, opts);
CGImageRef img = nil;
if ([CGImageSourceGetType(src) isEqual: type])
{
if (CGImageSourceGetCount(src) >= 1)
{
img = CGImageSourceCreateImageAtIndex(src, 0, opts);
}
else
{
NSLog(@"No images found");
}
}
else
{
NSLog(@"Unexpected type of image. expected %@, found %@", type, CGImageSourceGetType(src));
}
[src release];
[opts release];
if (img)
{
img->shouldInterpolate = shouldInterpolate;
img->intent = intent;
// FIXME: decode array???
}
return img;
}
CGImageRef CGImageCreateWithJPEGDataProvider(
CGDataProviderRef source,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent)
{
// FIXME: If cairo 1.9.x or greater, and the image is a PNG or JPEG, attach the
// compressed data to the surface with cairo_surface_set_mime_data (so embedding
// images in to PDF/SVG output works optimally)
return createWithDataProvider(source, decode, shouldInterpolate, intent, @"public.jpeg");
}
CGImageRef CGImageCreateWithPNGDataProvider(
CGDataProviderRef source,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent)
{
return createWithDataProvider(source, decode, shouldInterpolate, intent, @"public.png");
}
CFTypeID CGImageGetTypeID()
{
return (CFTypeID)[CGImage class];
}
CGImageRef CGImageRetain(CGImageRef image)
{
return [image retain];
}
void CGImageRelease(CGImageRef image)
{
[image release];
}
bool CGImageIsMask(CGImageRef image)
{
return image->ismask;
}
size_t CGImageGetWidth(CGImageRef image)
{
return image->width;
}
size_t CGImageGetHeight(CGImageRef image)
{
return image->height;
}
size_t CGImageGetBitsPerComponent(CGImageRef image)
{
return image->bitsPerComponent;
}
size_t CGImageGetBitsPerPixel(CGImageRef image)
{
return image->bitsPerPixel;
}
size_t CGImageGetBytesPerRow(CGImageRef image)
{
return image->bytesPerRow;
}
CGColorSpaceRef CGImageGetColorSpace(CGImageRef image)
{
return image->cspace;
}
CGImageAlphaInfo CGImageGetAlphaInfo(CGImageRef image)
{
return image->bitmapInfo & kCGBitmapAlphaInfoMask;
}
CGBitmapInfo CGImageGetBitmapInfo(CGImageRef image)
{
return image->bitmapInfo;
}
CGDataProviderRef CGImageGetDataProvider(CGImageRef image)
{
return image->dp;
}
const CGFloat *CGImageGetDecode(CGImageRef image)
{
return image->decode;
}
bool CGImageGetShouldInterpolate(CGImageRef image)
{
return image->shouldInterpolate;
}
CGColorRenderingIntent CGImageGetRenderingIntent(CGImageRef image)
{
return image->intent;
}
/**
* Use OPImageConvert to convert whatever image data the CGImage holds
* into Cairo's format (premultiplied ARGB32), and cache this
* surface. Hopefully cairo uploads image surfaces created with
* cairo_image_surface_create to the graphics card.
*
*
*/
cairo_surface_t *opal_CGImageGetSurfaceForImage(CGImageRef img, cairo_surface_t *contextSurface)
{
if (NULL == img)
{
return NULL;
}
if (NULL == img->surf)
{
cairo_surface_t *memSurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
CGImageGetWidth(img),
CGImageGetHeight(img));
if (cairo_surface_status(memSurf) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Cairo error creating image\n");
return NULL;
}
cairo_surface_flush(memSurf); // going to modify the surface outside of cairo
const unsigned char *srcData = OPDataProviderGetBytePointer(img->dp);
const size_t srcWidth = CGImageGetWidth(img);
const size_t srcHeight = CGImageGetHeight(img);
const size_t srcBitsPerComponent = CGImageGetBitsPerComponent(img);
const size_t srcBitsPerPixel = CGImageGetBitsPerPixel(img);
const size_t srcBytesPerRow = CGImageGetBytesPerRow(img);
const CGBitmapInfo srcBitmapInfo = CGImageGetBitmapInfo(img);
const CGColorSpaceRef srcColorSpace = CGImageGetColorSpace(img);
const CGColorRenderingIntent srcIntent = CGImageGetRenderingIntent(img);
unsigned char *dstData = cairo_image_surface_get_data(memSurf);
const size_t dstBitsPerComponent = 8;
const size_t dstBitsPerPixel = 32;
const size_t dstBytesPerRow = cairo_image_surface_get_stride(memSurf);
CGBitmapInfo dstBitmapInfo = kCGImageAlphaPremultipliedFirst;
if (NSHostByteOrder() == NS_LittleEndian)
{
dstBitmapInfo |= kCGBitmapByteOrder32Little;
}
else if (NSHostByteOrder() == NS_BigEndian)
{
dstBitmapInfo |= kCGBitmapByteOrder32Big;
}
const CGColorSpaceRef dstColorSpace = srcColorSpace;
OPImageConvert(
dstData, srcData,
srcWidth, srcHeight,
dstBitsPerComponent, srcBitsPerComponent,
dstBitsPerPixel, srcBitsPerPixel,
dstBytesPerRow, srcBytesPerRow,
dstBitmapInfo, srcBitmapInfo,
dstColorSpace, srcColorSpace,
srcIntent);
DumpPixel(srcData, @"OPImageConvert src (expecting R G B A)");
DumpPixel(dstData, @"OPImageConvert dst (expecting A R G B premult)");
OPDataProviderReleaseBytePointer(img->dp, srcData);
cairo_surface_mark_dirty(memSurf); // done modifying the surface outside of cairo
// Now, draw the image into (hopefully) a surface on the window server
img->surf = cairo_surface_create_similar(contextSurface,
CAIRO_CONTENT_COLOR_ALPHA,
CGImageGetWidth(img),
CGImageGetHeight(img));
cairo_t *ctx = cairo_create(img->surf);
cairo_set_source_surface(ctx, memSurf, 0, 0);
cairo_paint(ctx);
cairo_destroy(ctx);
cairo_surface_destroy(memSurf);
}
return img->surf;
}
CGRect opal_CGImageGetSourceRect(CGImageRef image)
{
if (NULL == image) {
return CGRectMake(0, 0, 0, 0);
}
if (CGRectIsNull(image->crop)) {
return CGRectMake(0, 0, image->width, image->height);
} else {
return image->crop;
}
}

View file

@ -0,0 +1,22 @@
#include "CoreGraphics/CGImageDestination.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
@interface CGImageDestination : NSObject
{
}
+ (void) registerDestinationClass: (Class)cls;
+ (NSArray*) destinationClasses;
+ (Class) destinationClassForType: (NSString*)type;
+ (NSArray *)typeIdentifiers;
- (id) initWithDataConsumer: (CGDataConsumerRef)consumer
type: (CFStringRef)type
count: (size_t)count
options: (CFDictionaryRef)opts;
- (void) setProperties: (CFDictionaryRef)properties;
- (void) addImage: (CGImageRef)img properties: (CFDictionaryRef)properties;
- (bool) finalize;
@end

View file

@ -0,0 +1,205 @@
/** <title>CGImageDestination</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGImageDestination.h"
#import <Foundation/NSException.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
#include "CGImageDestination-private.h"
/* Constants */
const CFStringRef kCGImageDestinationLossyCompressionQuality = @"kCGImageDestinationLossyCompressionQuality";
const CFStringRef kCGImageDestinationBackgroundColor = @"kCGImageDestinationBackgroundColor";
static NSMutableArray *destinationClasses = nil;
@implementation CGImageDestination
+ (void) registerDestinationClass: (Class)cls
{
if (nil == destinationClasses)
{
destinationClasses = [[NSMutableArray alloc] init];
}
if ([cls isSubclassOfClass: [CGImageDestination class]])
{
[destinationClasses addObject: cls];
}
else
{
[NSException raise: NSInvalidArgumentException format: @"+[CGImageDestination registerDestinationClass:] called with invalid class"];
}
}
+ (NSArray*) destinationClasses
{
return destinationClasses;
}
+ (Class) destinationClassForType: (NSString*)type
{
NSUInteger cnt = [destinationClasses count];
for (NSUInteger i=0; i<cnt; i++)
{
Class cls = [destinationClasses objectAtIndex: i];
if ([[cls typeIdentifiers] containsObject: type])
{
return cls;
}
}
return Nil;
}
+ (NSArray *)typeIdentifiers
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (id) initWithDataConsumer: (CGDataConsumerRef)consumer
type: (CFStringRef)type
count: (size_t)count
options: (CFDictionaryRef)opts
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (void) setProperties: (CFDictionaryRef)properties
{
[self doesNotRecognizeSelector: _cmd];
}
- (void) addImage: (CGImageRef)img properties: (CFDictionaryRef)properties
{
[self doesNotRecognizeSelector: _cmd];
}
- (void) addImageFromSource: (CGImageSourceRef)source
index: (size_t)index
properties: (CFDictionaryRef)properties
{
[self doesNotRecognizeSelector: _cmd];
}
- (bool) finalize
{
[self doesNotRecognizeSelector: _cmd];
return false;
}
@end
/* Functions */
/* Creating */
CGImageDestinationRef CGImageDestinationCreateWithData(
CFMutableDataRef data,
CFStringRef type,
size_t count,
CFDictionaryRef opts)
{
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData(data);
CGImageDestinationRef dest;
dest = CGImageDestinationCreateWithDataConsumer(consumer, type, count, opts);
CGDataConsumerRelease(consumer);
return dest;
}
CGImageDestinationRef CGImageDestinationCreateWithDataConsumer(
CGDataConsumerRef consumer,
CFStringRef type,
size_t count,
CFDictionaryRef opts)
{
Class cls = [CGImageDestination destinationClassForType: type];
return [[cls alloc] initWithDataConsumer: consumer type: type count: count options: opts];
}
CGImageDestinationRef CGImageDestinationCreateWithURL(
CFURLRef url,
CFStringRef type,
size_t count,
CFDictionaryRef opts)
{
CGDataConsumerRef consumer = CGDataConsumerCreateWithURL(url);
CGImageDestinationRef dest;
dest = CGImageDestinationCreateWithDataConsumer(consumer, type, count, opts);
CGDataConsumerRelease(consumer);
return dest;
}
/* Getting Supported Image Types */
CFArrayRef CGImageDestinationCopyTypeIdentifiers()
{
NSMutableSet *set = [NSMutableSet set];
NSArray *classes = [CGImageDestination destinationClasses];
NSUInteger cnt = [classes count];
for (NSUInteger i=0; i<cnt; i++)
{
[set addObjectsFromArray: [[classes objectAtIndex: i] typeIdentifiers]];
}
return [[set allObjects] retain];
}
/* Setting Properties */
void CGImageDestinationSetProperties(
CGImageDestinationRef dest,
CFDictionaryRef properties)
{
[dest setProperties: properties];
}
/* Adding Images */
void CGImageDestinationAddImage(
CGImageDestinationRef dest,
CGImageRef image,
CFDictionaryRef properties)
{
[dest addImage: (CGImageRef)image properties: properties];
}
void CGImageDestinationAddImageFromSource(
CGImageDestinationRef dest,
CGImageSourceRef source,
size_t index,
CFDictionaryRef properties)
{
// FIXME: We could support short-circuiting in some cases, but it's probably not worth the complexity
CGImageDestinationAddImage(dest, CGImageSourceCreateImageAtIndex(source, index, nil), properties);
}
bool CGImageDestinationFinalize(CGImageDestinationRef dest)
{
return [dest finalize];
}
CFTypeID CGImageDestinationGetTypeID()
{
return (CFTypeID)[CGImageDestination class];
}

View file

@ -0,0 +1,24 @@
#include "CoreGraphics/CGImageSource.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
@interface CGImageSource : NSObject
{
}
+ (void) registerSourceClass: (Class)cls;
+ (NSArray*) sourceClasses;
+ (NSArray *)typeIdentifiers;
- (id)initWithProvider: (CGDataProviderRef)provider;
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts;
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: (size_t)index;
- (size_t)count;
- (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts;
- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)opts;
- (CGImageSourceStatus)status;
- (CGImageSourceStatus)statusAtIndex: (size_t)index;
- (NSString*)type;
- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate;
@end

View file

@ -0,0 +1,378 @@
/** <title>CGImageSource</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright (C) 2010 Free Software Foundation, Inc.
Author: Eric Wasylishen <ewasylishen@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGImageSource.h"
#import <Foundation/NSException.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
#include "CGImageSource-private.h"
/* Constants */
const CFStringRef kCGImageSourceTypeIdentifierHint = @"kCGImageSourceTypeIdentifierHint";
const CFStringRef kCGImageSourceShouldAllowFloat = @"kCGImageSourceShouldAllowFloat";
const CFStringRef kCGImageSourceShouldCache = @"kCGImageSourceShouldCache";
const CFStringRef kCGImageSourceCreateThumbnailFromImageIfAbsent = @"kCGImageSourceCreateThumbnailFromImageIfAbsent";
const CFStringRef kCGImageSourceCreateThumbnailFromImageAlways = @"kCGImageSourceCreateThumbnailFromImageAlways";
const CFStringRef kCGImageSourceThumbnailMaxPixelSize = @"kCGImageSourceThumbnailMaxPixelSize";
const CFStringRef kCGImageSourceCreateThumbnailWithTransform = @"kCGImageSourceCreateThumbnailWithTransform";
static NSMutableArray *sourceClasses = nil;
@implementation CGImageSource
+ (void) registerSourceClass: (Class)cls
{
if (nil == sourceClasses)
{
sourceClasses = [[NSMutableArray alloc] init];
}
if ([cls isSubclassOfClass: [CGImageSource class]])
{
[sourceClasses addObject: cls];
}
else
{
[NSException raise: NSInvalidArgumentException format: @"+[CGImageSource registerSourceClass:] called with invalid class"];
}
}
+ (NSArray*) sourceClasses
{
return sourceClasses;
}
+ (NSArray *)typeIdentifiers
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
+ (BOOL)canDecodeData: (CGDataProviderRef)provider
{
[self doesNotRecognizeSelector: _cmd];
return NO;
}
- (id)initWithProvider: (CGDataProviderRef)provider
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: (size_t)index
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (size_t)count
{
[self doesNotRecognizeSelector: _cmd];
return 0;
}
- (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)options
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)options
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (CGImageSourceStatus)status
{
[self doesNotRecognizeSelector: _cmd];
return 0;
}
- (CGImageSourceStatus)statusAtIndex: (size_t)index
{
[self doesNotRecognizeSelector: _cmd];
return 0;
}
- (NSString*)type
{
[self doesNotRecognizeSelector: _cmd];
return nil;
}
- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate
{
[self doesNotRecognizeSelector: _cmd];
}
@end
/**
* Proxy class used to implement CGImageSourceCreateIncremental.
* It simply waits for enough data from CGImageSourceUpdateData[Provider] calls
* to create a real CGImageSource, then forwards messages to the real
* image source.
*/
@interface CGImageSourceIncremental : CGImageSource
{
CGImageSource *real;
CFDictionaryRef opts;
}
@end
@implementation CGImageSourceIncremental
- (id)initWithIncrementalOptions: (CFDictionaryRef)o
{
self = [super init];
opts = [o retain];
return self;
}
- (void)dealloc
{
[real release];
[opts release];
[super dealloc];
}
- (CGImageSource*)realSource
{
return real;
}
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options
{
return [[self realSource] propertiesWithOptions: options];
}
- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: (size_t)index
{
return [[self realSource] propertiesWithOptions: options atIndex: index];
}
- (size_t)count
{
return [[self realSource] count];
}
- (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)options
{
return [[self realSource] createImageAtIndex: index options: options];
}
- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)options
{
return [[self realSource] createThumbnailAtIndex: index options: options];
}
- (CGImageSourceStatus)status
{
if (![self realSource])
{
return kCGImageStatusReadingHeader; // FIXME ??
}
return [[self realSource] status];
}
- (CGImageSourceStatus)statusAtIndex: (size_t)index
{
if (![self realSource])
{
return kCGImageStatusReadingHeader; // FIXME ??
}
return [[self realSource] statusAtIndex: index];
}
- (NSString*)type
{
return [[self realSource] type];
}
- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate
{
if (![self realSource])
{
// See if there is enough data to create a real image source
real = CGImageSourceCreateWithDataProvider(provider, opts);
}
else
{
[[self realSource] updateDataProvider: provider finalUpdate: finalUpdate];
}
}
@end
/* Functions */
/* Creating */
CGImageSourceRef CGImageSourceCreateIncremental(CFDictionaryRef options)
{
return [[CGImageSourceIncremental alloc] initWithIncrementalOptions: options];
}
CGImageSourceRef CGImageSourceCreateWithData(
CFDataRef data,
CFDictionaryRef options)
{
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
CGImageSourceRef source;
source = CGImageSourceCreateWithDataProvider(provider, options);
CGDataProviderRelease(provider);
return source;
}
CGImageSourceRef CGImageSourceCreateWithDataProvider(
CGDataProviderRef provider,
CFDictionaryRef options)
{
const NSUInteger cnt = [sourceClasses count];
NSString *possibleType = [options valueForKey:
kCGImageSourceTypeIdentifierHint];
if (possibleType)
{
for (NSUInteger i=0; i<cnt; i++)
{
Class cls = [sourceClasses objectAtIndex: i];
if ([[cls typeIdentifiers] containsObject: possibleType])
{
CGImageSource *src = [[cls alloc] initWithProvider: provider];
if (src)
{
return src;
}
}
}
}
for (NSUInteger i=0; i<cnt; i++)
{
Class cls = [sourceClasses objectAtIndex: i];
CGImageSource *src = [[cls alloc] initWithProvider: provider];
if (src)
{
return src;
}
}
return nil;
}
CGImageSourceRef CGImageSourceCreateWithURL(
CFURLRef url,
CFDictionaryRef options)
{
CGDataProviderRef provider = CGDataProviderCreateWithURL(url);
CGImageSourceRef source;
source = CGImageSourceCreateWithDataProvider(provider, options);
CGDataProviderRelease(provider);
return source;
}
/* Accessing Properties */
CFDictionaryRef CGImageSourceCopyProperties(
CGImageSourceRef source,
CFDictionaryRef options)
{
return [source propertiesWithOptions: options];
}
CFDictionaryRef CGImageSourceCopyPropertiesAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef options)
{
return [source propertiesWithOptions: options atIndex: index];
}
/* Getting Supported Image Types */
CFArrayRef CGImageSourceCopyTypeIdentifiers()
{
NSMutableSet *set = [NSMutableSet set];
NSArray *classes = [CGImageSource sourceClasses];
NSUInteger cnt = [classes count];
for (NSUInteger i=0; i<cnt; i++)
{
[set addObjectsFromArray: [[classes objectAtIndex: i] typeIdentifiers]];
}
return [[set allObjects] retain];
}
/* Accessing Images */
size_t CGImageSourceGetCount(CGImageSourceRef source)
{
return [source count];
}
CGImageRef CGImageSourceCreateImageAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef options)
{
return [source createImageAtIndex: index options: options];
}
CGImageRef CGImageSourceCreateThumbnailAtIndex(
CGImageSourceRef source,
size_t index,
CFDictionaryRef options)
{
return [source createThumbnailAtIndex: index options: options];
}
CGImageSourceStatus CGImageSourceGetStatus(CGImageSourceRef source)
{
return [source status];
}
CGImageSourceStatus CGImageSourceGetStatusAtIndex(
CGImageSourceRef source,
size_t index)
{
return [source statusAtIndex: index];
}
CFStringRef CGImageSourceGetType(CGImageSourceRef source)
{
return [source type];
}
void CGImageSourceUpdateData(
CGImageSourceRef source,
CFDataRef data,
bool finalUpdate)
{
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
CGImageSourceUpdateDataProvider(source, provider, finalUpdate);
CGDataProviderRelease(provider);
}
void CGImageSourceUpdateDataProvider(
CGImageSourceRef source,
CGDataProviderRef provider,
bool finalUpdate)
{
[source updateDataProvider: provider finalUpdate: finalUpdate];
}
CFTypeID CGImageSourceGetTypeID()
{
return (CFTypeID)[CGImageSource class];
}

View file

@ -0,0 +1,116 @@
/** <title>CGLayer</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2009 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: Dec 2009
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include <math.h>
#include "CoreGraphics/CGLayer.h"
#include "CGContext-private.h"
@interface CGLayer : NSObject
{
@public
CGContextRef ctxt;
CGSize size;
}
@end
@implementation CGLayer
- (void) dealloc
{
CGContextRelease(self->ctxt);
[super dealloc];
}
@end
CGLayerRef CGLayerCreateWithContext(
CGContextRef referenceCtxt,
CGSize size,
CFDictionaryRef auxInfo)
{
CGLayer *layer = [[CGLayer alloc] init];
if (!layer) return NULL;
// size is in user-space units of referenceCtxt, so transform it to device
// space.
double w = size.width, h = size.height;
cairo_user_to_device_distance(referenceCtxt->ct, &w, &h);
cairo_surface_t *layerSurface =
cairo_surface_create_similar(cairo_get_target(referenceCtxt->ct),
CAIRO_CONTENT_COLOR_ALPHA,
ceil(fabs(w)),
ceil(fabs(h)));
layer->ctxt = opal_new_CGContext(layerSurface, CGSizeMake(ceil(fabs(w)), ceil(fabs(h))));
layer->size = size;
return layer;
}
CFTypeID CGLayerGetTypeID()
{
return (CFTypeID)[CGLayer class];
}
CGLayerRef CGLayerRetain(CGLayerRef layer)
{
return [layer retain];
}
void CGLayerRelease(CGLayerRef layer)
{
[layer release];
}
CGSize CGLayerGetSize(CGLayerRef layer)
{
return layer->size;
}
CGContextRef CGLayerGetContext(CGLayerRef layer)
{
return layer->ctxt;
}
void CGContextDrawLayerInRect(
CGContextRef destCtxt,
CGRect rect,
CGLayerRef layer)
{
opal_draw_surface_in_rect(destCtxt, rect, cairo_get_target(layer->ctxt->ct),
CGRectMake(0, 0, layer->size.width, layer->size.height));
}
void CGContextDrawLayerAtPoint(
CGContextRef destCtxt,
CGPoint point,
CGLayerRef layer)
{
CGContextDrawLayerInRect(destCtxt,
CGRectMake(point.x, point.y, layer->size.width, layer->size.height),
layer);
}

View file

@ -0,0 +1,81 @@
/** <title>CGPDFArray</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFArray.h"
bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, CGPDFArrayRef *value)
{
return false;
}
bool CGPDFArrayGetBoolean(CGPDFArrayRef array, size_t index, CGPDFBoolean *value)
{
return false;
}
size_t CGPDFArrayGetCount(CGPDFArrayRef array)
{
return 0;
}
bool CGPDFArrayGetDictionary(CGPDFArrayRef array, size_t index, CGPDFDictionaryRef *value)
{
return false;
}
bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, CGPDFInteger *value)
{
return false;
}
bool CGPDFArrayGetName(CGPDFArrayRef array, size_t index, const char **value)
{
return false;
}
bool CGPDFArrayGetNull(CGPDFArrayRef array, size_t index)
{
return false;
}
bool CGPDFArrayGetNumber(CGPDFArrayRef array, size_t index, CGPDFReal *value)
{
return false;
}
bool CGPDFArrayGetObject(CGPDFArrayRef array, size_t index, CGPDFObjectRef *value)
{
return false;
}
bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, CGPDFStreamRef *value)
{
return false;
}
bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, CGPDFStringRef *value)
{
return false;
}

View file

@ -0,0 +1,62 @@
/** <title>CGPDFContentStream</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFContentStream.h"
CGPDFContentStreamRef CGPDFContentStreamCreateWithPage(CGPDFPageRef page)
{
return nil;
}
CGPDFContentStreamRef CGPDFContentStreamCreateWithStream(
CGPDFStreamRef stream,
CGPDFDictionaryRef streamResources,
CGPDFContentStreamRef parent)
{
return nil;
}
CGPDFObjectRef CGPDFContentStreamGetResource(
CGPDFContentStreamRef stream,
const char *category,
const char *name)
{
return nil;
}
CFArrayRef CGPDFContentStreamGetStreams(CGPDFContentStreamRef stream)
{
return nil;
}
CGPDFContentStreamRef CGPDFContentStreamRetain(CGPDFContentStreamRef stream)
{
return nil;
}
void CGPDFContentStreamRelease(CGPDFContentStreamRef stream)
{
}

View file

@ -0,0 +1,167 @@
/** <title>CGPDFContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: January, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSString.h>
#import <Foundation/NSURL.h>
#include "CoreGraphics/CGPDFContext.h"
#include "CoreGraphics/CGDataConsumer.h"
#include "CGContext-private.h"
#include "CGDataConsumer-private.h"
#include <cairo.h>
#include <cairo-pdf.h>
/* Constants */
const CFStringRef kCGPDFContextAuthor = @"kCGPDFContextAuthor";
const CFStringRef kCGPDFContextCreator = @"kCGPDFContextCreator";
const CFStringRef kCGPDFContextTitle = @"kCGPDFContextTitle";
const CFStringRef kCGPDFContextOwnerPassword = @"kCGPDFContextOwnerPassword";
const CFStringRef kCGPDFContextUserPassword = @"kCGPDFContextUserPassword";
const CFStringRef kCGPDFContextAllowsPrinting = @"kCGPDFContextAllowsPrinting";
const CFStringRef kCGPDFContextAllowsCopying = @"kCGPDFContextAllowsCopying";
const CFStringRef kCGPDFContextOutputIntent = @"kCGPDFContextOutputIntent";
const CFStringRef kCGPDFContextOutputIntents = @"kCGPDFContextOutputIntents";
const CFStringRef kCGPDFContextSubject = @"kCGPDFContextSubject";
const CFStringRef kCGPDFContextKeywords = @"kCGPDFContextKeywords";
const CFStringRef kCGPDFContextEncryptionKeyLength = @"kCGPDFContextEncryptionKeyLength";
const CFStringRef kCGPDFContextMediaBox = @"kCGPDFContextMediaBox";
const CFStringRef kCGPDFContextCropBox = @"kCGPDFContextCropBox";
const CFStringRef kCGPDFContextBleedBox = @"kCGPDFContextBleedBox";
const CFStringRef kCGPDFContextTrimBox = @"kCGPDFContextTrimBox";
const CFStringRef kCGPDFContextArtBox = @"kCGPDFContextArtBox";
const CFStringRef kCGPDFXOutputIntentSubtype = @"kCGPDFXOutputIntentSubtype";
const CFStringRef kCGPDFXOutputConditionIdentifier = @"kCGPDFXOutputConditionIdentifier";
const CFStringRef kCGPDFXOutputCondition = @"kCGPDFXOutputCondition";
const CFStringRef kCGPDFXRegistryName = @"kCGPDFXRegistryName";
const CFStringRef kCGPDFXInfo = @"kCGPDFXInfo";
const CFStringRef kCGPDFXDestinationOutputProfile = @"kCGPDFXDestinationOutputProfile";
/* Functions */
void CGPDFContextAddDestinationAtPoint(
CGContextRef ctx,
CFStringRef name,
CGPoint point)
{
NSLog(@"CGPDFContextAddDestinationAtPoint not supported.");
}
void CGPDFContextBeginPage(CGContextRef ctx, CFDictionaryRef pageInfo)
{
// FIXME: Not sure what this should do. Nothing?
}
void CGPDFContextClose(CGContextRef ctx)
{
cairo_status_t cret;
cairo_surface_finish(cairo_get_target(ctx->ct));
cret = cairo_status(ctx->ct);
if (cret) {
NSLog(@"CGPDFContextClose status: %s", cairo_status_to_string(cret));
return;
}
}
static cairo_status_t opal_CGPDFContextWriteFunction(
void *closure,
const unsigned char *data,
unsigned int length)
{
OPDataConsumerPutBytes((CGDataConsumerRef)closure, data, length);
return CAIRO_STATUS_SUCCESS;
}
static cairo_user_data_key_t OpalDataConsumerKey;
static void opal_SurfaceDestoryFunc(void *data)
{
CGDataConsumerRelease((CGDataConsumerRef)data);
}
CGContextRef CGPDFContextCreate(
CGDataConsumerRef consumer,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo)
{
CGRect box;
if (mediaBox == NULL) {
box = CGRectMake(0, 0, 8.5 * 72, 11 * 72);
} else {
box = *mediaBox;
}
//FIXME: We ignore the origin of mediaBox.. is that correct?
cairo_surface_t *surf = cairo_pdf_surface_create_for_stream(
opal_CGPDFContextWriteFunction,
CGDataConsumerRetain(consumer),
box.size.width,
box.size.height);
cairo_surface_set_user_data(surf, &OpalDataConsumerKey, consumer, opal_SurfaceDestoryFunc);
CGContextRef ctx = opal_new_CGContext(surf, box.size);
return ctx;
}
CGContextRef CGPDFContextCreateWithURL(
CFURLRef url,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo)
{
CGDataConsumerRef dc = CGDataConsumerCreateWithURL(url);
CGContextRef ctx = CGPDFContextCreate(dc, mediaBox, auxiliaryInfo);
CGDataConsumerRelease(dc);
return ctx;
}
void CGPDFContextEndPage(CGContextRef ctx)
{
cairo_status_t cret;
cairo_show_page(ctx->ct);
cret = cairo_status(ctx->ct);
if (cret) {
NSLog(@"CGPDFContextEndPage status: %s", cairo_status_to_string(cret));
return;
}
}
void CGPDFContextSetDestinationForRect(
CGContextRef ctx,
CFStringRef name,
CGRect rect)
{
NSLog(@"CGPDFContextSetDestinationForRect not supported.");
}
void CGPDFContextSetURLForRect(CGContextRef ctx, CFURLRef url, CGRect rect)
{
NSLog(@"CGPDFContextSetURLForRect not supported.");
}

View file

@ -0,0 +1,82 @@
/** <title>CGPDFDictionary</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFDictionary.h"
void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, CGPDFDictionaryApplierFunction function, void *info)
{
}
size_t CGPDFDictionaryGetCount(CGPDFDictionaryRef dict)
{
return 0;
}
bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, CGPDFArrayRef *value)
{
return false;
}
bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, CGPDFBoolean *value)
{
return false;
}
bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, CGPDFDictionaryRef *value)
{
return false;
}
bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, CGPDFInteger *value)
{
return false;
}
bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, const char **value)
{
return false;
}
bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, CGPDFReal *value)
{
return false;
}
bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, CGPDFObjectRef *value)
{
return false;
}
bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, CGPDFStreamRef *value)
{
return false;
}
bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, CGPDFStringRef *value)
{
return false;
}

View file

@ -0,0 +1,81 @@
/** <title>CGPDFDocument</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFDocument.h"
CGPDFDocumentRef CGPDFDocumentCreateWithProvider(CGDataProviderRef provider)
{
return nil;
}
CGPDFDocumentRef CGPDFDocumentCreateWithURL(CFURLRef url)
{
return nil;
}
CGPDFDocumentRef CGPDFDocumentRetain(CGPDFDocumentRef document)
{
return nil;
}
void CGPDFDocumentRelease(CGPDFDocumentRef document)
{
}
int CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document)
{
return 0;
}
CGRect CGPDFDocumentGetMediaBox(CGPDFDocumentRef document, int page)
{
return CGRectNull;
}
CGRect CGPDFDocumentGetCropBox(CGPDFDocumentRef document, int page)
{
return CGRectNull;
}
CGRect CGPDFDocumentGetBleedBox(CGPDFDocumentRef document, int page)
{
return CGRectNull;
}
CGRect CGPDFDocumentGetTrimBox(CGPDFDocumentRef document, int page)
{
return CGRectNull;
}
CGRect CGPDFDocumentGetArtBox(CGPDFDocumentRef document, int page)
{
return CGRectNull;
}
int CGPDFDocumentGetRotationAngle(CGPDFDocumentRef document, int page)
{
return 0;
}

View file

@ -0,0 +1,36 @@
/** <title>CGPDFObject</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFObject.h"
CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object)
{
return kCGPDFObjectTypeNull;
}
bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, void *value)
{
return false;
}

View file

@ -0,0 +1,49 @@
/** <title>CGPDFOperatorTable</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFOperatorTable.h"
CGPDFOperatorTableRef CGPDFOperatorTableCreate()
{
return nil;
}
void CGPDFOperatorTableSetCallback(
CGPDFOperatorTableRef table,
const char *name,
CGPDFOperatorCallback callback)
{
}
CGPDFOperatorTableRef CGPDFOperatorTableRetain(CGPDFOperatorTableRef table)
{
return nil;
}
void CGPDFOperatorTableRelease(CGPDFOperatorTableRef table)
{
}

View file

@ -0,0 +1,76 @@
/** <title>CGPDFPage</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFPage.h"
CGPDFDocumentRef CGPDFPageGetDocument(CGPDFPageRef page)
{
return nil;
}
size_t CGPDFPageGetPageNumber(CGPDFPageRef page)
{
return 0;
}
CGRect CGPDFPageGetBoxRect(CGPDFPageRef page, CGPDFBox box)
{
return CGRectNull;
}
int CGPDFPageGetRotationAngle(CGPDFPageRef page)
{
return 0;
}
CGAffineTransform CGPDFPageGetDrawingTransform(
CGPDFPageRef page,
CGPDFBox box,
CGRect rect,
int rotate,
bool preserveAspectRatio)
{
return CGAffineTransformIdentity;
}
CGPDFDictionaryRef CGPDFPageGetDictionary(CGPDFPageRef page)
{
return nil;
}
CFTypeID CGPDFPageGetTypeID(void)
{
return (CFTypeID)nil;
}
CGPDFPageRef CGPDFPageRetain(CGPDFPageRef page)
{
return nil;
}
void CGPDFPageRelease(CGPDFPageRef page)
{
}

View file

@ -0,0 +1,99 @@
/** <title>CGPDFScanner</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFScanner.h"
CGPDFScannerRef CGPDFScannerCreate(
CGPDFContentStreamRef cs,
CGPDFOperatorTableRef table,
void *info)
{
return nil;
}
bool CGPDFScannerScan(CGPDFScannerRef scanner)
{
return false;
}
CGPDFContentStreamRef CGPDFScannerGetContentStream(CGPDFScannerRef scanner)
{
return nil;
}
bool CGPDFScannerPopArray(CGPDFScannerRef scanner, CGPDFArrayRef *value)
{
return false;
}
bool CGPDFScannerPopBoolean(CGPDFScannerRef scanner, CGPDFBoolean *value)
{
return false;
}
bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, CGPDFDictionaryRef *value)
{
return false;
}
bool CGPDFScannerPopInteger(CGPDFScannerRef scanner, CGPDFInteger *value)
{
return false;
}
bool CGPDFScannerPopName(CGPDFScannerRef scanner, const char **value)
{
return false;
}
bool CGPDFScannerPopNumber(CGPDFScannerRef scanner, CGPDFReal *value)
{
return false;
}
bool CGPDFScannerPopObject(CGPDFScannerRef scanner, CGPDFObjectRef *value)
{
return false;
}
bool CGPDFScannerPopStream(CGPDFScannerRef scanner, CGPDFStreamRef *value)
{
return false;
}
bool CGPDFScannerPopString(CGPDFScannerRef scanner, CGPDFStringRef *value)
{
return false;
}
CGPDFScannerRef CGPDFScannerRetain(CGPDFScannerRef scanner)
{
return nil;
}
void CGPDFScannerRelease(CGPDFScannerRef scanner)
{
}

View file

@ -0,0 +1,36 @@
/** <title>CGPDFStream</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFStream.h"
CGPDFDictionaryRef CGPDFStreamGetDictionary(CGPDFStreamRef stream)
{
return nil;
}
CFDataRef CGPDFStreamCopyData(CGPDFStreamRef stream, CGPDFDataFormat *format)
{
return nil;
}

View file

@ -0,0 +1,46 @@
/** <title>CGPDFString</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPDFString.h"
size_t CGPDFStringGetLength(CGPDFStringRef string)
{
return 0;
}
const unsigned char *CGPDFStringGetBytePtr(CGPDFStringRef string)
{
return NULL;
}
CFStringRef CGPDFStringCopyTextString(CGPDFStringRef string)
{
return nil;
}
CFDateRef CGPDFStringCopyDate(CGPDFStringRef string)
{
return nil;
}

View file

@ -0,0 +1,62 @@
/** <title>CGPSConverter</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGPSConverter.h"
#include "CoreGraphics/CGPDFContext.h"
CGPSConverterRef CGPSConverterCreate(
void *info,
const CGPSConverterCallbacks *callbacks,
CFDictionaryRef options)
{
return nil;
}
bool CGPSConverterConvert(
CGPSConverterRef converter,
CGDataProviderRef provider,
CGDataConsumerRef consumer,
CFDictionaryRef options)
{
//CGContextRef ctx = CGPDFContextCreate(consumer, NULL, NULL);
// Read postscript from the data provider, and draw on ctx
return true;
}
bool CGPSConverterAbort(CGPSConverterRef converter)
{
return false;
}
bool CGPSConverterIsConverting(CGPSConverterRef converter)
{
return false;
}
CFTypeID CGPSConverterGetTypeID()
{
return (CFTypeID)nil;
}

View file

@ -0,0 +1,482 @@
/** <title>CGPath</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPath.h"
#import "OPPath.h"
CGPathRef CGPathCreateCopy(CGPathRef path)
{
return [path copy];
}
CGMutablePathRef CGPathCreateMutable()
{
return [[CGMutablePath alloc] init];
}
CGMutablePathRef CGPathCreateMutableCopy(CGPathRef path)
{
return [[CGMutablePath alloc] initWithCGPath: path];
}
CGPathRef CGPathRetain(CGPathRef path)
{
return [path retain];
}
void CGPathRelease(CGPathRef path)
{
[path release];
}
bool CGPathIsEmpty(CGPathRef path)
{
return [path count] == 0;
}
bool CGPathEqualToPath(CGPathRef path1, CGPathRef path2)
{
return [path1 isEqual: path2];
}
bool CGPathIsRect(CGPathRef path, CGRect *rect)
{
return [path isRect: rect];
}
CGRect CGPathGetBoundingBox(CGPathRef path)
{
NSUInteger count = [path count];
CGFloat minX = 0.0;
CGFloat minY = 0.0;
CGFloat maxX = 0.0;
CGFloat maxY = 0.0;
for (NSUInteger i=0; i<count; i++)
{
CGPoint points[3];
CGPathElementType type =[path elementTypeAtIndex: i points: points];
NSUInteger numPoints;
switch (type)
{
case kCGPathElementMoveToPoint:
numPoints = 1;
break;
case kCGPathElementAddLineToPoint:
numPoints = 1;
break;
case kCGPathElementAddQuadCurveToPoint:
numPoints = 2;
break;
case kCGPathElementAddCurveToPoint:
numPoints = 3;
break;
case kCGPathElementCloseSubpath:
default:
numPoints = 0;
break;
}
for (NSUInteger p=0; p<numPoints; p++)
{
if (points[p].x < minX)
{
minX = points[p].x;
}
else if (points[p].x > maxX)
{
maxX = points[p].x;
}
else if (points[p].y < minY)
{
minY = points[p].y;
}
else if (points[p].y > maxY)
{
maxY = points[p].y;
}
}
}
return CGRectMake(minX, minY, (maxX-minX), (maxY-minY));
}
CGPoint CGPathGetCurrentPoint(CGPathRef path)
{
if (CGPathIsEmpty(path))
{
return CGPointZero;
}
NSUInteger count = [path count];
// FIXME: ugly loop
for (NSUInteger i=(count-1); i>=0 && i<count; i--)
{
CGPoint points[3];
CGPathElementType type =[path elementTypeAtIndex: i points: points];
switch (type)
{
case kCGPathElementMoveToPoint:
case kCGPathElementAddLineToPoint:
return points[0];
case kCGPathElementAddQuadCurveToPoint:
return points[1];
case kCGPathElementAddCurveToPoint:
return points[2];
case kCGPathElementCloseSubpath:
default:
break;
}
}
return CGPointZero;
}
bool CGPathContainsPoint(
CGPathRef path,
const CGAffineTransform *m,
CGPoint point,
int eoFill)
{
// FIXME: use cairo function
return false;
}
/**
* Implements approximation of an arc through a cubic bezier spline. The
* algorithm used is the same as in cairo and comes from Goldapp, Michael:
* "Approximation of circular arcs by cubic poynomials". In: Computer Aided
* Geometric Design 8 (1991), pp. 227--238.
*/
static inline void
_OPPathAddArcSegment(CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y,
CGFloat radius,
CGFloat startAngle,
CGFloat endAngle)
{
CGFloat startSinR = radius * sin(startAngle);
CGFloat startCosR = radius * cos(startAngle);
CGFloat endSinR = radius * sin(endAngle);
CGFloat endCosR = radius * cos(endAngle);
CGFloat hValue = 4.0/3.0 * tan ((endAngle - startAngle) / 4.0);
CGFloat cp1x = x + startCosR - hValue * startSinR;
CGFloat cp1y = y + startSinR + hValue * startCosR;
CGFloat cp2x = x + endCosR + hValue * endSinR;
CGFloat cp2y = y + endSinR - hValue * endCosR;
CGPathAddCurveToPoint(path, m,
cp1x, cp1y,
cp2x, cp2y,
x + endCosR,
y + endSinR);
}
void CGPathAddArc(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y,
CGFloat r,
CGFloat startAngle,
CGFloat endAngle,
int clockwise)
{
CGFloat angleValue = (endAngle - startAngle);
// Normalize the distance:
while ((angleValue) > (4 * M_PI))
{
endAngle -= (2 * M_PI);
angleValue = (endAngle - startAngle);
}
/*
* When adding an arc with an angle greater than pi, do it in parts and
* recurse accordingly.
*/
if (angleValue > M_PI)
{
// Define the angle to cut the parts:
CGFloat intermediateAngle = (startAngle + (angleValue / 2.0));
// Setup part start and end angles according to direction:
CGFloat firstStart = clockwise ? startAngle : intermediateAngle;
CGFloat firstEnd = clockwise ? intermediateAngle : endAngle;
CGFloat secondStart = clockwise ? intermediateAngle: startAngle;
CGFloat secondEnd = clockwise ? endAngle : intermediateAngle;
// Add the parts:
CGPathAddArc(path, m,
x, y,
r,
firstStart, firstEnd,
clockwise);
CGPathAddArc(path, m,
x, y,
r,
secondStart, secondEnd,
clockwise);
}
else if (0 != angleValue)
{
// It only makes sense to add the arc if it actually has a non-zero angle.
NSUInteger index = 0;
NSUInteger segmentCount = 0;
CGFloat thisAngle = 0;
CGFloat angleStep = 0;
/*
* Calculate how many segments we need and set the stepping accordingly.
*
* FIXME: We are using a fixed tolerance to find the number of elements
* needed. This is necessary because we construct the path independently
* from the surface we draw on. Maybe we should store some additional data
* so we can better approximate the arc when we go to draw the curves?
*/
segmentCount = _OPPathRequiredArcSegments(angleValue, r, m);
angleStep = (angleValue / (CGFloat)segmentCount);
// Adjust for clockwiseness:
if (clockwise)
{
thisAngle = startAngle;
}
else
{
thisAngle = endAngle;
angleStep = - angleStep;
}
if (CGPathIsEmpty(path))
{
// Move to the start of drawing:
CGPathMoveToPoint(path, m,
(x + (r * cos(thisAngle))),
(y + (r * sin(thisAngle))));
}
else
{
CGPathAddLineToPoint(path, m,
(x + (r * cos(thisAngle))),
(y + (r * sin(thisAngle))));
}
// Add the segments to the path:
for (index = 0; index < segmentCount; index++, thisAngle += angleStep)
{
_OPPathAddArcSegment(path, m,
x, y,
r,
thisAngle,
(thisAngle + angleStep));
}
}
}
void CGPathAddArcToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x1,
CGFloat y1,
CGFloat x2,
CGFloat y2,
CGFloat r)
{
// FIXME:
}
void CGPathAddCurveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cx1,
CGFloat cy1,
CGFloat cx2,
CGFloat cy2,
CGFloat x,
CGFloat y)
{
CGPoint points[3];
points[0] = CGPointMake(cx1, cy1);
points[1] = CGPointMake(cx2, cy2);
points[2] = CGPointMake(x, y);
if (NULL != m)
{
NSUInteger i = 0;
for (i = 0;i < 3; i++)
{
points[i] = CGPointApplyAffineTransform(points[i], *m);
}
}
[(CGMutablePath*)path addElementWithType: kCGPathElementAddCurveToPoint
points: (CGPoint*)&points];
}
void CGPathAddLines(
CGMutablePathRef path,
const CGAffineTransform *m,
const CGPoint points[],
size_t count)
{
CGPathMoveToPoint(path, m, points[0].x, points[0].y);
for (NSUInteger i=1; i<count; i++)
{
CGPathAddLineToPoint(path, m, points[i].x, points[i].y);
}
}
void CGPathAddLineToPoint (
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y)
{
CGPoint point = CGPointMake(x, y);
if (m)
{
point = CGPointApplyAffineTransform(point, *m);
}
[(CGMutablePath*)path addElementWithType: kCGPathElementAddLineToPoint
points: &point];
}
void CGPathAddPath(
CGMutablePathRef path1,
const CGAffineTransform *m,
CGPathRef path2)
{
NSUInteger count = [path2 count];
for (NSUInteger i=0; i<count; i++)
{
CGPoint points[3];
CGPathElementType type = [path2 elementTypeAtIndex: i points: points];
if (m)
{
for (NSUInteger j=0; j<3; j++)
{
// FIXME: transforms unused points
points[j] = CGPointApplyAffineTransform(points[j], *m);
}
}
[(CGMutablePath*)path1 addElementWithType: type points: points];
}
}
void CGPathAddQuadCurveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat cx,
CGFloat cy,
CGFloat x,
CGFloat y)
{
CGPoint points[2] = {
CGPointMake(cx, cy),
CGPointMake(x, y)
};
if (m)
{
points[0] = CGPointApplyAffineTransform(points[0], *m);
points[1] = CGPointApplyAffineTransform(points[1], *m);
}
[(CGMutablePath*)path addElementWithType: kCGPathElementAddQuadCurveToPoint
points: points];
}
void CGPathAddRect(
CGMutablePathRef path,
const CGAffineTransform *m,
CGRect rect)
{
CGPathMoveToPoint(path, m, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGPathAddLineToPoint(path, m, CGRectGetMaxX(rect), CGRectGetMinY(rect));
CGPathAddLineToPoint(path, m, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGPathAddLineToPoint(path, m, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGPathCloseSubpath(path);
}
void CGPathAddRects(
CGMutablePathRef path,
const CGAffineTransform *m,
const CGRect rects[],
size_t count)
{
for (NSUInteger i=0; i<count; i++)
{
CGPathAddRect(path, m, rects[i]);
}
}
void CGPathApply(
CGPathRef path,
void *info,
CGPathApplierFunction function)
{
NSUInteger count = [path count];
for (NSUInteger i=0; i<count; i++)
{
CGPoint points[3];
CGPathElement e;
e.type = [path elementTypeAtIndex: i points: points];
e.points = points;
function(info, &e);
}
}
void CGPathMoveToPoint(
CGMutablePathRef path,
const CGAffineTransform *m,
CGFloat x,
CGFloat y)
{
CGPoint point = CGPointMake(x, y);
if (m)
{
point = CGPointApplyAffineTransform(point, *m);
}
[(CGMutablePath*)path addElementWithType: kCGPathElementMoveToPoint
points: &point];
}
void CGPathCloseSubpath(CGMutablePathRef path)
{
[(CGMutablePath*)path addElementWithType: kCGPathElementCloseSubpath
points: NULL];
}
void CGPathAddEllipseInRect(
CGMutablePathRef path,
const CGAffineTransform *m,
CGRect rect)
{
// FIXME:
}

View file

@ -0,0 +1,69 @@
/** <title>CGPattern</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPattern.h"
@interface CGPattern : NSObject
{
void *info;
}
@end
@implementation CGPattern
@end
CGPatternRef CGPatternCreate(
void *info,
CGRect bounds,
CGAffineTransform matrix,
CGFloat xStep,
CGFloat yStep,
CGPatternTiling tiling,
int isColored,
const CGPatternCallbacks *callbacks)
{
CGPatternRef pattern = nil;
// FIXME
return pattern;
}
CFTypeID CGPatternGetTypeID()
{
return (CFTypeID)[CGPattern class];
}
CGPatternRef CGPatternRetain(CGPatternRef pattern)
{
return [pattern retain];
}
void CGPatternRelease(CGPatternRef pattern)
{
[pattern release];
}

View file

@ -0,0 +1,73 @@
/** <title>CGShading</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGShading.h"
@interface CGShading : NSObject
{
}
@end
@implementation CGShading
@end
CGShadingRef CGShadingCreateAxial(
CGColorSpaceRef colorspace,
CGPoint start,
CGPoint end,
CGFunctionRef function,
int extendStart,
int extendEnd)
{
return nil;
}
CGShadingRef CGShadingCreateRadial(
CGColorSpaceRef colorspace,
CGPoint start,
CGFloat startRadius,
CGPoint end,
CGFloat endRadius,
CGFunctionRef function,
int extendStart,
int extendEnd)
{
return nil;
}
CFTypeID CGShadingGetTypeID()
{
return (CFTypeID)[CGShading class];
}
CGShadingRef CGShadingRetain(CGShadingRef shading)
{
return [shading retain];
}
void CGShadingRelease(CGShadingRef shading)
{
[shading release];
}

View file

@ -0,0 +1,60 @@
include $(GNUSTEP_MAKEFILES)/common.make
PACKAGE_NAME = opal
SUBPROJECT_NAME = OpalGraphics
$(SUBPROJECT_NAME)_OBJC_FILES = $(wildcard *.m)
$(SUBPROJECT_NAME)_OBJC_FILES += $(wildcard cairo/*.m)
$(SUBPROJECT_NAME)_OBJC_FILES += $(wildcard image/*.m)
$(SUBPROJECT_NAME)_HEADER_FILES_DIR = ../../Headers/CoreGraphics
$(SUBPROJECT_NAME)_INCLUDE_DIRS = -I../../Headers
$(SUBPROJECT_NAME)_HEADER_FILES_INSTALL_DIR = CoreGraphics
$(SUBPROJECT_NAME)_HEADER_FILES = \
CGAffineTransform.h \
CGBase.h \
CGBitmapContext.h \
CGColor.h \
CGColorSpace.h \
CGContext.h \
CGDataConsumer.h \
CGDataProvider.h \
CGFont.h \
CGFunction.h \
CGGeometry.h \
CGGradient.h \
CGImage.h \
CGImageDestination.h \
CGImageSource.h \
CGLayer.h \
CGPath.h \
CGPattern.h \
CGPDFArray.h \
CGPDFContentStream.h \
CGPDFContext.h \
CGPDFDictionary.h \
CGPDFDocument.h \
CGPDFObject.h \
CGPDFOperatorTable.h \
CGPDFPage.h \
CGPDFScanner.h \
CGPDFString.h \
CGPDFStream.h \
CGPSConverter.h \
CGShading.h \
CoreGraphics.h
ADDITIONAL_OBJCFLAGS += -Wall -g -O0 -std=gnu99
ADDITIONAL_CPPFLAGS += $(shell pkg-config --cflags cairo)
ADDITIONAL_CPPFLAGS += $(shell pkg-config --cflags lcms)
ifneq ($(GNUSTEP_TARGET_OS), mingw32)
ADDITIONAL_CPPFLAGS += $(shell pkg-config --cflags freetype2)
else
ADDITIONAL_CPPFLAGS += -D__MINGW__
endif
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/subproject.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,61 @@
/** <title>OPColorSpaceIndexed</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
Author: BALATON Zoltan <balaton@eik.bme.hu>
Date: 2006
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "CoreGraphics/CGColorSpace.h"
#import "CGColorSpace-private.h"
@interface OPColorSpaceIndexed : NSObject
{
@public
CGColorSpaceRef base;
size_t lastIndex;
unsigned char *table;
}
- (id)initWithBaseSpace: (CGColorSpaceRef)aBaseSpace
lastIndex: (size_t)aLastIndex
colorTable: (const unsigned char *)aColorTable;
- (size_t) tableSize;
- (CGColorSpaceRef) baseColorSpace;
- (void) getColorTable: (uint8_t*)tableOut;
- (size_t) colorTableCount;
- (id<OPColorTransform>) colorTransformTo: (id<CGColorSpace>)otherColor
sourceFormat: (OPImageFormat)sourceFormat
destinationFormat: (OPImageFormat)destFormat;
@end
@interface OPColorTransformIndexed : NSObject <OPColorTransform>
{
id<OPColorTransform> baseTransform;
}
- (void) transformPixelData: (const unsigned char *)input
output: (unsigned char *)output;
@end

View file

@ -0,0 +1,119 @@
/** <title>OPColorSpaceIndexed</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/Foundation.h>
#import "OPColorSpaceIndexed.h"
@implementation OPColorSpaceIndexed
- (id)initWithBaseSpace: (CGColorSpaceRef)aBaseSpace
lastIndex: (size_t)aLastIndex
colorTable: (const unsigned char *)aColorTable
{
self = [super init];
ASSIGN(base, aBaseSpace);
lastIndex = aLastIndex;
table = malloc([self tableSize]);
if (NULL == table)
{
[self release];
return nil;
}
memmove(table, aColorTable, [self tableSize]);
return self;
}
- (size_t) tableSize
{
return (lastIndex + 1) * CGColorSpaceGetNumberOfComponents(base);
}
- (void) dealloc
{
free(table);
CGColorSpaceRelease(base);
[super dealloc];
}
- (NSData*)ICCProfile
{
return [base ICCProfile]; // FIXME: ???
}
- (NSString*)name
{
return [base name]; // FIXME: ???
}
- (CGColorSpaceRef) baseColorSpace
{
return base;
}
- (size_t) numberOfComponents
{
return [base numberOfComponents];
}
- (void) getColorTable: (uint8_t*)tableOut
{
memmove(tableOut, self->table, [self tableSize]);
}
- (size_t) colorTableCount
{
return self->lastIndex + 1;
}
- (CGColorSpaceModel) model
{
return [base model];
}
- (BOOL) isEqual: (id)other
{
if ([other isKindOfClass: [OPColorSpaceIndexed class]])
{
OPColorSpaceIndexed *otherIndexed = (OPColorSpaceIndexed*)other;
return [self->base isEqual: otherIndexed->base]
&& self->lastIndex == otherIndexed->lastIndex
&& (0 == memcmp(otherIndexed->table,
self->table,
[self tableSize]));
}
return NO;
}
- (id<OPColorTransform>) colorTransformTo: (id<CGColorSpace>)otherColor
sourceFormat: (OPImageFormat)sourceFormat
destinationFormat: (OPImageFormat)destFormat
{
return [[[OPColorTransformIndexed alloc] init] autorelease];
}
@end
@implementation OPColorTransformIndexed
- (void) transformPixelData: (const unsigned char *)input
output: (unsigned char *)output
{
// FIXME:
}
@end

View file

@ -0,0 +1,127 @@
/** <title>OPColorSpaceLCMS</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lcms.h>
#include "CoreGraphics/CGColorSpace.h"
#import "CGColorSpace-private.h"
@interface OPColorSpaceLCMS : NSObject <CGColorSpace>
{
@public
cmsHPROFILE profile;
NSData *data;
}
/**
* Returns a generic RGB color space
*/
+ (id<CGColorSpace>)colorSpaceGenericRGB;
/**
* Returns a generic RGB color space with a gamma of 1.0
*/
+ (id<CGColorSpace>)colorSpaceGenericRGBLinear;
/**
* Returns a CMYK colorspace following the FOGRA39L specification.
*/
+ (id<CGColorSpace>)colorSpaceGenericCMYK;
/**
* Returns an Adobe RGB compatible color space
*/
+ (id<CGColorSpace>)colorSpaceAdobeRGB1998;
/**
* Returns an sRGB compatible color space
*/
+ (id<CGColorSpace>)colorSpaceSRGB;
/**
* Returns a grayscale color space with a D65 white point
*/
+ (id<CGColorSpace>)colorSpaceGenericGray;
/**
* Returns a grayscale color space with gamma 2.2 and a D65 white point
*/
+ (id<CGColorSpace>)colorSpaceGenericGrayGamma2_2;
// Initializers
/**
* Creates a color space with the given LCMS profile. Takes ownership of the profile
* (releases it when done.)
*/
- (id)initWithProfile: (cmsHPROFILE)profile;
/**
* Returns ICC profile data for color spaces created from ICC profiles, otherwise nil
*/
- (NSData*)ICCProfile;
- (NSString*)name;
- (id)initWithCalibratedGrayWithWhitePoint: (const CGFloat*)whiteCIEXYZ
blackPoint: (const CGFloat*)blackCIEXYZ
gamma: (CGFloat)gamma;
- (id)initWithCalibratedRGBWithWhitePointCIExy: (const CGFloat*)white
redCIExy: (const CGFloat*)red
greenCIExy: (const CGFloat*)green
blueCIExy: (const CGFloat*)blue
gamma: (CGFloat)gamma;
- (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
gamma: (const CGFloat *)gamma
matrix: (const CGFloat *)matrix;
- (id)initICCBasedWithComponents: (size_t)nComponents
range: (const CGFloat*)range
profile: (CGDataProviderRef)profile
alternateSpace: (CGColorSpaceRef)alternateSpace;
- (CGColorSpaceRef) initLabWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
range: (const CGFloat*)range;
- (CGColorSpaceRef) initWithICCProfile: (CFDataRef)profileData;
- (CGColorSpaceRef) initWithPlatformColorSpace: (void *)platformColorSpace;
- (CGColorSpaceModel) model;
- (size_t) numberOfComponents;
- (id<OPColorTransform>) colorTransformTo: (id<CGColorSpace>)aColorSpace
sourceFormat: (OPImageFormat)aSourceFormat
destinationFormat: (OPImageFormat)aDestFormat
renderingIntent: (CGColorRenderingIntent)anIntent
pixelCount: (size_t)aPixelCount;
@end

View file

@ -0,0 +1,336 @@
/** <title>OPColorSpaceLCMS</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lcms.h>
#include "CoreGraphics/CGColorSpace.h"
#import "OPColorSpaceLCMS.h"
#import "CGColorSpace-private.h"
#import "OPColorTransformLCMS.h"
@implementation OPColorSpaceLCMS
static OPColorSpaceLCMS *colorSpaceSRGB;
static OPColorSpaceLCMS *colorSpaceGenericRGBLinear;
static OPColorSpaceLCMS *colorSpaceGenericCMYK;
static OPColorSpaceLCMS *colorSpaceAdobeRGB1998;
static OPColorSpaceLCMS *colorSpaceGenericGrayGamma2_2;
/**
* Returns a generic RGB color space
*/
+ (id<CGColorSpace>)colorSpaceGenericRGB
{
return [self colorSpaceSRGB];
}
/**
* Returns a generic RGB color space with a gamma of 1.0
*/
+ (id<CGColorSpace>)colorSpaceGenericRGBLinear
{
if (nil == colorSpaceGenericRGBLinear)
{
// Use the sRGB white point and primaries with a gamma of 1.0
CGFloat whiteCIExy[2] = {0.3127, 0.3290};
CGFloat redCIExy[2] = {0.64, 0.33};
CGFloat greenCIExy[2] = {0.30, 0.60};
CGFloat blueCIExy[2] = {0.15, 0.06};
colorSpaceGenericRGBLinear = [[OPColorSpaceLCMS alloc]
initWithCalibratedRGBWithWhitePointCIExy: whiteCIExy
redCIExy: redCIExy
greenCIExy: greenCIExy
blueCIExy: blueCIExy
gamma: 1.0];
}
return colorSpaceGenericRGBLinear;
}
/**
* Returns a CMYK colorspace following the FOGRA39L specification.
*/
+ (id<CGColorSpace>)colorSpaceGenericCMYK
{
if (nil == colorSpaceGenericCMYK)
{
NSString *path = [[NSBundle bundleForClass: [self class]]
pathForResource: @"coated_FOGRA39L_argl"
ofType: @"icc"];
NSData *data = [NSData dataWithContentsOfFile: path];
colorSpaceGenericCMYK = [[OPColorSpaceLCMS alloc] initWithICCProfile: data];
}
return colorSpaceGenericCMYK;
}
/**
* Returns an Adobe RGB compatible color space
*/
+ (id<CGColorSpace>)colorSpaceAdobeRGB1998
{
if (nil == colorSpaceAdobeRGB1998)
{
CGFloat whiteCIExy[2] = {0.3127, 0.3290};
CGFloat redCIExy[2] = {0.6400, 0.3300};
CGFloat greenCIExy[2] = {0.2100, 0.7100};
CGFloat blueCIExy[2] = {0.1500, 0.0600};
colorSpaceAdobeRGB1998 = [[OPColorSpaceLCMS alloc]
initWithCalibratedRGBWithWhitePointCIExy: whiteCIExy
redCIExy: redCIExy
greenCIExy: greenCIExy
blueCIExy: blueCIExy
gamma: (563.0/256.0)];
}
return colorSpaceAdobeRGB1998;
}
/**
* Returns an sRGB compatible color space
*/
+ (id<CGColorSpace>)colorSpaceSRGB
{
if (nil == colorSpaceSRGB)
{
colorSpaceSRGB = [[OPColorSpaceLCMS alloc] initWithProfile: cmsCreate_sRGBProfile()];
}
return colorSpaceSRGB;
}
/**
* Returns a grayscale color space with a D65 white point
*/
+ (id<CGColorSpace>)colorSpaceGenericGray
{
return [self colorSpaceGenericGrayGamma2_2];
}
/**
* Returns a grayscale color space with gamma 2.2 and a D65 white point
*/
+ (id<CGColorSpace>)colorSpaceGenericGrayGamma2_2
{
if (nil == colorSpaceGenericGrayGamma2_2)
{
CGFloat whiteCIEXYZ[3] = {0.9504, 1.0000, 1.0888};
CGFloat blackCIEXYZ[3] = {0, 0, 0};
colorSpaceGenericGrayGamma2_2 = [[OPColorSpaceLCMS alloc] initWithCalibratedGrayWithWhitePoint: whiteCIEXYZ
blackPoint: blackCIEXYZ
gamma: 2.2];
}
return colorSpaceGenericGrayGamma2_2;
}
// Initializers
/**
* Creates a color space with the given LCMS profile. Takes ownership of the profile
* (releases it when done.)
*/
- (id)initWithProfile: (cmsHPROFILE)aProfile
{
self = [super init];
self->profile = aProfile;
return self;
}
/**
* Returns ICC profile data for color spaces created from ICC profiles, otherwise nil
*/
- (NSData*)ICCProfile
{
return data;
}
- (NSString*)name
{
return [NSString stringWithUTF8String: cmsTakeProductName(self->profile)];
}
static inline cmsCIExyY CIExyzToCIExyY(const CGFloat point[3])
{
// LittleCMS docs say Y is always 1
cmsCIExyY xyY = {point[0], point[1], 1.0};
return xyY;
}
static inline cmsCIExyY CIEXYZToCIExyY(const CGFloat point[3])
{
cmsCIEXYZ XYZ = {point[0], point[1], point[2]};
cmsCIExyY xyY;
cmsXYZ2xyY(&xyY, &XYZ);
return xyY;
}
- (id)initWithCalibratedGrayWithWhitePoint: (const CGFloat*)whiteCIEXYZ
blackPoint: (const CGFloat*)blackCIEXYZ
gamma: (CGFloat)gamma
{
self = [super init];
// NOTE: we ignore the black point; LCMS computes it on its own
LPGAMMATABLE table = cmsBuildGamma(256, gamma);
cmsCIExyY whiteCIExyY = CIEXYZToCIExyY(whiteCIEXYZ);
self->profile = cmsCreateGrayProfile(&whiteCIExyY, table);
cmsFreeGamma(table);
return self;
}
- (id)initWithCalibratedRGBWithWhitePointCIExy: (const CGFloat*)white
redCIExy: (const CGFloat*)red
greenCIExy: (const CGFloat*)green
blueCIExy: (const CGFloat*)blue
gamma: (CGFloat)gamma
{
self = [super init];
LPGAMMATABLE tables[3] = {cmsBuildGamma(256, gamma),
cmsBuildGamma(256, gamma),
cmsBuildGamma(256, gamma)};
cmsCIExyY whitePoint = {white[0], white[1], 1.0};
cmsCIExyYTRIPLE primaries = {
{red[0], red[1], 1.0},
{green[0], green[1], 1.0},
{blue[0], blue[1], 1.0}
};
self->profile = cmsCreateRGBProfile(&whitePoint, &primaries, tables);
cmsFreeGamma(tables[0]);
cmsFreeGamma(tables[1]);
cmsFreeGamma(tables[2]);
return self;
}
- (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
gamma: (const CGFloat *)gamma
matrix: (const CGFloat *)matrix
{
self = [super init];
// NOTE: we ignore the black point; LCMS computes it on its own
LPGAMMATABLE tables[3] = {cmsBuildGamma(256, gamma[0]),
cmsBuildGamma(256, gamma[1]),
cmsBuildGamma(256, gamma[2])};
// FIXME: I'm not 100% sure this is the correct interpretation of matrix
// We can test it by checking the results in pdf manual vs doing a trasformation
// with LCMS to XYZ.
cmsCIExyYTRIPLE primaries;
primaries.Red = CIEXYZToCIExyY(matrix);
primaries.Green = CIEXYZToCIExyY(matrix+3);
primaries.Blue = CIEXYZToCIExyY(matrix+6);
cmsCIExyY whitePointCIExyY = CIEXYZToCIExyY(whitePoint);
self->profile = cmsCreateRGBProfile(&whitePointCIExyY, &primaries, tables);
cmsFreeGamma(tables[0]);
cmsFreeGamma(tables[1]);
cmsFreeGamma(tables[2]);
return self;
}
- (id)initICCBasedWithComponents: (size_t)nComponents
range: (const CGFloat*)range
profile: (CGDataProviderRef)profile
alternateSpace: (CGColorSpaceRef)alternateSpace
{
return nil;
}
- (CGColorSpaceRef) initLabWithWhitePoint: (const CGFloat*)whitePoint
blackPoint: (const CGFloat*)blackPoint
range: (const CGFloat*)range
{
return nil;
}
- (CGColorSpaceRef) initWithICCProfile: (CFDataRef)profileData
{
self = [super init];
self->data = [profileData retain];
self->profile = cmsOpenProfileFromMem((LPVOID)[profileData bytes], [profileData length]);
return self;
}
- (CGColorSpaceRef) initWithPlatformColorSpace: (void *)platformColorSpace
{
[self release];
return nil;
}
static CGColorSpaceModel CGColorSpaceModelForSignature(icColorSpaceSignature sig)
{
switch (sig)
{
case icSigGrayData:
return kCGColorSpaceModelMonochrome;
case icSigRgbData:
return kCGColorSpaceModelRGB;
case icSigCmykData:
return kCGColorSpaceModelCMYK;
case icSigLabData:
return kCGColorSpaceModelLab;
default:
return kCGColorSpaceModelUnknown;
}
}
- (CGColorSpaceModel) model
{
return CGColorSpaceModelForSignature(cmsGetColorSpace(profile));
}
- (size_t) numberOfComponents
{
return _cmsChannelsOf(cmsGetColorSpace(profile));
}
- (id<OPColorTransform>) colorTransformTo: (id<CGColorSpace>)aColorSpace
sourceFormat: (OPImageFormat)aSourceFormat
destinationFormat: (OPImageFormat)aDestFormat
renderingIntent: (CGColorRenderingIntent)anIntent
pixelCount: (size_t)aPixelCount
{
return [[OPColorTransformLCMS alloc]
initWithSourceSpace: self
destinationSpace: aColorSpace
sourceFormat: aSourceFormat
destinationFormat: aDestFormat
renderingIntent: anIntent
pixelCount: aPixelCount];
}
- (BOOL)isEqual: (id)other
{
if ([other isKindOfClass: [OPColorSpaceLCMS class]])
{
// FIXME: Maybe there is a simple way to compare the profiles?
return ((OPColorSpaceLCMS*)other)->profile == self->profile;
}
return NO;
}
@end

View file

@ -0,0 +1,52 @@
/** <title>OPColorTransformLCMS</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lcms.h>
#include "CoreGraphics/CGColorSpace.h"
#import "CGColorSpace-private.h"
#import "OPColorSpaceLCMS.h"
@interface OPColorTransformLCMS : NSObject <OPColorTransform>
{
cmsHTRANSFORM xform;
OPColorSpaceLCMS *source, *dest;
OPImageFormat sourceFormat, destFormat;
CGColorRenderingIntent renderingIntent;
size_t pixelCount;
unsigned char *tempBuffer1, *tempBuffer2;
}
- (id) initWithSourceSpace: (OPColorSpaceLCMS *)aSourceSpace
destinationSpace: (OPColorSpaceLCMS *)aDestSpace
sourceFormat: (OPImageFormat)aSourceFormat
destinationFormat: (OPImageFormat)aDestFormat
renderingIntent: (CGColorRenderingIntent)anIntent
pixelCount: (size_t)aPixelCount;
- (void) transformPixelData: (const unsigned char *)input
output: (unsigned char *)output;
@end

View file

@ -0,0 +1,339 @@
/** <title>OPColorTransformLCMS</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lcms.h>
#include "CoreGraphics/CGColorSpace.h"
#import "CGColorSpace-private.h"
#import "OPColorTransformLCMS.h"
#import "OPPremultiplyAlpha.h"
@implementation OPColorTransformLCMS
static int LcmsIntentForCGColorRenderingIntent(CGColorRenderingIntent intent)
{
switch (intent)
{
default:
case kCGRenderingIntentDefault:
return INTENT_RELATIVE_COLORIMETRIC; // FIXME: Check a user default
case kCGRenderingIntentAbsoluteColorimetric:
return INTENT_ABSOLUTE_COLORIMETRIC;
case kCGRenderingIntentRelativeColorimetric:
return INTENT_RELATIVE_COLORIMETRIC;
case kCGRenderingIntentPerceptual:
return INTENT_PERCEPTUAL;
case kCGRenderingIntentSaturation:
return INTENT_SATURATION;
}
}
static int LcmsPixelTypeForCGColorSpaceModel(CGColorSpaceModel model)
{
switch (model)
{
case kCGColorSpaceModelMonochrome:
return PT_GRAY;
case kCGColorSpaceModelRGB:
return PT_RGB;
case kCGColorSpaceModelCMYK:
return PT_CMYK;
case kCGColorSpaceModelLab:
return PT_Lab;
case kCGColorSpaceModelUnknown:
case kCGColorSpaceModelDeviceN:
case kCGColorSpaceModelIndexed:
case kCGColorSpaceModelPattern:
default:
return PT_ANY;
}
}
static DWORD LcmsFormatForOPImageFormat(OPImageFormat opalFormat, CGColorSpaceRef colorSpace)
{
DWORD cmsFormat = 0;
switch (opalFormat.compFormat)
{
case kOPComponentFormat8bpc:
cmsFormat |= BYTES_SH(1);
break;
case kOPComponentFormat16bpc:
cmsFormat |= BYTES_SH(2);
break;
case kOPComponentFormat32bpc:
cmsFormat |= BYTES_SH(2); // Convert to 16-bit before passing to LCMS
break;
case kOPComponentFormatFloat32bpc:
cmsFormat |= BYTES_SH(2); // Convert to 16-bit before passing to LCMS
break;
}
cmsFormat |= CHANNELS_SH((DWORD)opalFormat.colorComponents);
if (opalFormat.hasAlpha)
{
cmsFormat |= EXTRA_SH(1);
}
if (!opalFormat.isAlphaLast && opalFormat.hasAlpha)
{
cmsFormat |= SWAPFIRST_SH(1);
}
cmsFormat |= COLORSPACE_SH(
LcmsPixelTypeForCGColorSpaceModel(
CGColorSpaceGetModel(colorSpace)
)
);
return cmsFormat;
}
- (id) initWithSourceSpace: (OPColorSpaceLCMS *)aSourceSpace
destinationSpace: (OPColorSpaceLCMS *)aDestSpace
sourceFormat: (OPImageFormat)aSourceFormat
destinationFormat: (OPImageFormat)aDestFormat
renderingIntent: (CGColorRenderingIntent)anIntent
pixelCount: (size_t)aPixelCount
{
self = [super init];
ASSIGN(source, aSourceSpace);
ASSIGN(dest, aDestSpace);
const int lcmsIntent = LcmsIntentForCGColorRenderingIntent(anIntent);
int lcmsSrcFormat = LcmsFormatForOPImageFormat(aSourceFormat, aSourceSpace);
int lcmsDstFormat = LcmsFormatForOPImageFormat(aDestFormat, aDestSpace);
self->xform = cmsCreateTransform(aSourceSpace->profile, lcmsSrcFormat,
aDestSpace->profile, lcmsDstFormat,
lcmsIntent, 0);
// FIXME: check for success
self->renderingIntent = anIntent;
self->sourceFormat = aSourceFormat;
self->destFormat = aDestFormat;
self->pixelCount = aPixelCount;
if (sourceFormat.compFormat == kOPComponentFormatFloat32bpc
|| sourceFormat.compFormat == kOPComponentFormat32bpc)
{
tempBuffer1 = malloc(2 * pixelCount); // Convert to 16-bit
}
else if (sourceFormat.isAlphaPremultiplied)
{
// FIXME: Don't do unnecessary premul->unpremul->premul conversions
tempBuffer1 = malloc(OPPixelNumberOfBytes(sourceFormat) * pixelCount);
}
if (destFormat.compFormat == kOPComponentFormatFloat32bpc
|| destFormat.compFormat == kOPComponentFormat32bpc)
{
tempBuffer2 = malloc(OPPixelNumberOfBytes(destFormat) * pixelCount);
}
return self;
}
- (void) dealloc
{
cmsDeleteTransform(self->xform);
[source release];
[dest release];
if (tempBuffer1)
{
free(tempBuffer1);
}
if (tempBuffer2)
{
free(tempBuffer2);
}
[super dealloc];
}
- (void) transformPixelData: (const unsigned char *)input
output: (unsigned char *)output
{
unsigned char *tempOutput = output;
const size_t totalComponentsIn = sourceFormat.colorComponents + (sourceFormat.hasAlpha ? 1 : 0);
const size_t totalComponentsOut = destFormat.colorComponents + (destFormat.hasAlpha ? 1 : 0);
const bool destIntermediateIs16bpc = (destFormat.compFormat == kOPComponentFormatFloat32bpc
|| destFormat.compFormat == kOPComponentFormat32bpc
|| destFormat.compFormat == kOPComponentFormat16bpc);
const bool sourceIntermediateIs16bpc = (sourceFormat.compFormat == kOPComponentFormatFloat32bpc
|| sourceFormat.compFormat == kOPComponentFormat32bpc
|| sourceFormat.compFormat == kOPComponentFormat16bpc);
//NSLog(@"Transform %d pixels %d comps in %d out", pixelCount, totalComponentsIn, totalComponentsOut);
// Special case for kOPComponentFormatFloat32bpc, which LCMS 1 doesn't support directly
// Copy to temp input buffer
if (sourceFormat.compFormat == kOPComponentFormatFloat32bpc)
{
for (size_t i=0; i<pixelCount; i++)
{
for (size_t j=0; j<totalComponentsIn; j++)
{
((uint16_t*)tempBuffer1)[i*totalComponentsIn + j] = UINT16_MAX * ((float*)input)[i*totalComponentsIn + j];
//NSLog(@"Input comp: %f => %d", (float)((float*)input)[i*totalComponentsIn + j],(int)((uint16_t*)tempBuffer1)[i*totalComponentsIn + j]);
if ( (float)((float*)input)[i*totalComponentsIn + j] > 1)
{
NSLog(@"oveflow");
}
}
}
input = (const unsigned char *)tempBuffer1;
}
else if (sourceFormat.compFormat == kOPComponentFormat32bpc)
{
for (size_t i=0; i<pixelCount; i++)
{
for (size_t j=0; j<totalComponentsIn; j++)
{
((uint16_t*)tempBuffer1)[i*totalComponentsIn + j] = ((uint32_t*)input)[i*totalComponentsIn + j] >> 16;
}
}
input = tempBuffer1;
}
// Special case: if outputting kOPComponentFormatFloat32bpc, we get LCMS
// to convert to uint32, then manually convert that to float
if (destFormat.compFormat == kOPComponentFormatFloat32bpc
|| destFormat.compFormat == kOPComponentFormat32bpc)
{
tempOutput = tempBuffer2;
}
// Unpremultiply alpha in input
if (sourceFormat.isAlphaPremultiplied)
{
if (sourceFormat.compFormat == kOPComponentFormatFloat32bpc
|| sourceFormat.compFormat == kOPComponentFormat32bpc)
{
OPImageFormat fake = sourceFormat;
fake.compFormat = kOPComponentFormat16bpc;
OPPremultiplyAlpha(tempBuffer1, pixelCount, fake, true);
}
else
{
const size_t numBytes = OPPixelNumberOfBytes(sourceFormat) * pixelCount;
memmove(tempBuffer1, input, numBytes);
OPPremultiplyAlpha(tempBuffer1, pixelCount, sourceFormat, true);
input = tempBuffer1;
}
}
// generate a output alpha channel of alpha=100% if necessary
if (!sourceFormat.hasAlpha && destFormat.hasAlpha)
{
size_t destIntermediateBytesPerComponent = (destIntermediateIs16bpc ? 2 : 1);
size_t destIntermediateTotalComponentsPerPixel = (destFormat.colorComponents + (destFormat.hasAlpha ? 1 : 0));
size_t destIntermediateBytesPerRow = pixelCount * destIntermediateTotalComponentsPerPixel * destIntermediateBytesPerComponent;
memset(tempOutput, 0xff, destIntermediateBytesPerRow);
}
// get LCMS to do the main conversion of the color channels
cmsDoTransform(xform, (void*)input, tempOutput, pixelCount);
// copy alpha from source to dest if necessary
if (sourceFormat.hasAlpha && destFormat.hasAlpha)
{
const size_t sourceAlphaCompIndex = (sourceFormat.isAlphaLast ? sourceFormat.colorComponents : 0);
const size_t destAlphaCompIndex = (destFormat.isAlphaLast ? destFormat.colorComponents : 0);
if (sourceIntermediateIs16bpc && destIntermediateIs16bpc) /* 16 bit -> 16 bit */
for (size_t i=0; i<pixelCount; i++)
{
((uint16_t*)tempOutput)[i*totalComponentsOut + destAlphaCompIndex] = ((uint16_t*)input)[i*totalComponentsIn + sourceAlphaCompIndex];
}
else if (!sourceIntermediateIs16bpc && destIntermediateIs16bpc) /* 8 bit -> 16 bit */
{
for (size_t i=0; i<pixelCount; i++)
{
((uint16_t*)tempOutput)[i*totalComponentsOut + destAlphaCompIndex] = ((uint8_t*)input)[i*totalComponentsIn + sourceAlphaCompIndex] << 16;
}
}
else if (sourceIntermediateIs16bpc && !destIntermediateIs16bpc) /* 16 bit -> 8 bit */
{
for (size_t i=0; i<pixelCount; i++)
{
((uint8_t*)tempOutput)[i*totalComponentsOut + destAlphaCompIndex] = ((uint16_t*)input)[i*totalComponentsIn + sourceAlphaCompIndex] >> 16;
}
}
else /* 8 bit -> 8 bit */
{
for (size_t i=0; i<pixelCount; i++)
{
((uint8_t*)tempOutput)[i*totalComponentsOut + destAlphaCompIndex] = ((uint8_t*)input)[i*totalComponentsIn + sourceAlphaCompIndex];
}
}
}
// Premultiply alpha in output buffer if necessary
if (destFormat.isAlphaPremultiplied)
{
OPImageFormat fake = destFormat;
if (destFormat.compFormat == kOPComponentFormatFloat32bpc
|| destFormat.compFormat == kOPComponentFormat32bpc)
{
fake.compFormat = kOPComponentFormat16bpc;
}
OPPremultiplyAlpha(tempOutput, pixelCount, fake, false);
}
// If using a 16-bit intermediate output, copy & convert to the real destination format
if (destFormat.compFormat == kOPComponentFormatFloat32bpc)
{
for (size_t i=0; i<pixelCount; i++)
{
for (size_t j=0; j<totalComponentsOut; j++)
{
((float*)output)[i*totalComponentsOut + j] = ((uint16_t*)tempBuffer2)[i*totalComponentsOut + j] / ((float)UINT16_MAX);
//NSLog(@"Output comp: %d => %f", (int)((uint16_t*)tempBuffer2)[i*totalComponentsOut + j], (float)((float*)output)[i*totalComponentsOut + j]);
}
}
}
else if (destFormat.compFormat == kOPComponentFormat32bpc)
{
for (size_t i=0; i<pixelCount; i++)
{
for (size_t j=0; j<totalComponentsOut; j++)
{
((uint32_t*)output)[i*totalComponentsOut + j] = ((uint16_t*)tempBuffer2)[i*totalComponentsOut + j] << 16;
}
}
}
}
@end

View file

@ -0,0 +1,71 @@
/** <title>CGImage-conversion.h</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <CoreGraphics/CGColorSpace.h>
#include <CoreGraphics/CGImage.h>
/**
* To make the internals sane and fast, we only work with these four pixel components
* internally. They are all native-endian.
*/
typedef enum OPComponentFormat
{
kOPComponentFormat8bpc,
kOPComponentFormat16bpc,
kOPComponentFormat32bpc,
kOPComponentFormatFloat32bpc
} OPComponentFormat;
typedef struct OPImageFormat
{
OPComponentFormat compFormat;
size_t colorComponents;
bool hasAlpha;
bool isAlphaPremultiplied;
bool isAlphaLast;
} OPImageFormat;
size_t OPComponentNumberOfBytes(OPComponentFormat fmt);
size_t OPPixelTotalComponents(OPImageFormat fmt);
size_t OPPixelNumberOfBytes(OPImageFormat fmt);
void OPImageFormatLog(OPImageFormat fmt, NSString *msg);
void OPImageConvert(
unsigned char *dstData,
const unsigned char *srcData,
size_t width,
size_t height,
size_t dstBitsPerComponent,
size_t srcBitsPerComponent,
size_t dstBitsPerPixel,
size_t srcBitsPerPixel,
size_t dstBytesPerRow,
size_t srcBytesPerRow,
CGBitmapInfo dstBitmapInfo,
CGBitmapInfo srcBitmapInfo,
CGColorSpaceRef dstColorSpace,
CGColorSpaceRef srcColorSpace,
CGColorRenderingIntent intent);

View file

@ -0,0 +1,309 @@
/** <title>CGImage-conversion.m</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: July, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lcms.h>
#import <Foundation/NSString.h>
#include "CoreGraphics/CGColorSpace.h"
#include "CoreGraphics/CGImage.h"
#import "CGColorSpace-private.h"
size_t OPComponentNumberOfBytes(OPComponentFormat fmt)
{
switch (fmt)
{
case kOPComponentFormat8bpc:
return 1;
case kOPComponentFormat16bpc:
return 2;
case kOPComponentFormat32bpc:
return 4;
case kOPComponentFormatFloat32bpc:
return 4;
}
return 0;
}
size_t OPPixelTotalComponents(OPImageFormat fmt)
{
return fmt.colorComponents + (fmt.hasAlpha ? 1 : 0);
}
size_t OPPixelNumberOfBytes(OPImageFormat fmt)
{
return OPComponentNumberOfBytes(fmt.compFormat) * OPPixelTotalComponents(fmt);
}
void OPImageFormatLog(OPImageFormat fmt, NSString *msg)
{
NSString *compFormatString = nil;
switch (fmt.compFormat)
{
case kOPComponentFormat8bpc:
compFormatString = @"kOPComponentFormat8bpc";
break;
case kOPComponentFormat16bpc:
compFormatString = @"kOPComponentFormat16bpc";
break;
case kOPComponentFormat32bpc:
compFormatString = @"kOPComponentFormat32bpc";
break;
case kOPComponentFormatFloat32bpc:
compFormatString = @"kOPComponentFormatFloat32bpc";
break;
}
NSLog(@"%@: <%@, color components=%d, alpha?=%d, premul?=%d, alpha last?=%d>",
msg, compFormatString, fmt.colorComponents, fmt.hasAlpha, fmt.isAlphaPremultiplied, fmt.isAlphaLast);
}
static inline uint64_t swap64(uint64_t val)
{
char out[8];
char *in = (char *)(&val);
for (unsigned int i = 0; i<8; i++)
{
out[i] = in[7-i];
}
return *((uint64_t*)&out);
}
static inline void
_set_bit_value(unsigned char *base, size_t msb_off, size_t bit_width,
uint32_t val)
{
if (msb_off % 32 == 0 && bit_width == 32)
{
((uint32_t*)base)[msb_off / 32] = val;
}
else if (msb_off % 16 == 0 && bit_width == 16)
{
((uint16_t*)base)[msb_off / 16] = val;
}
else if (msb_off % 8 == 0 && bit_width == 8)
{
((uint8_t*)base)[msb_off / 8] = val;
}
else if (bit_width <= 32)
{
int byte1 = msb_off / 8;
int shift = 64 - bit_width - (msb_off % 8);
uint64_t value = val;
value &= ((1 << bit_width) - 1);
value <<= shift;
value = swap64(value); // if little endian
uint64_t mask = ((1 << bit_width) - 1);
mask <<= shift;
mask = ~mask;
mask = swap64(mask); // if little endian
*((uint64_t*)(base + byte1)) &= mask;
*((uint64_t*)(base + byte1)) |= value;
}
else
{
abort();
}
}
static inline uint32_t
_get_bit_value(const unsigned char *base, size_t msb_off, size_t bit_width)
{
if (msb_off % 32 == 0 && bit_width == 32)
{
return ((uint32_t*)base)[msb_off / 32];
}
else if (msb_off % 16 == 0 && bit_width == 16)
{
return ((uint16_t*)base)[msb_off / 16];
}
else if (msb_off % 8 == 0 && bit_width == 8)
{
return ((uint8_t*)base)[msb_off / 8];
}
else
{
int byte1 = msb_off / 8;
int byte2 = ((msb_off + bit_width - 1) / 8);
int shift = 64 - bit_width - (msb_off % 8);
int bytes_needed = byte2 - byte1 + 1;
char chars[8];
switch (bytes_needed)
{
case 5: chars[4] = base[byte1+4];
case 4: chars[3] = base[byte1+3];
case 3: chars[2] = base[byte1+2];
case 2: chars[1] = base[byte1+1];
case 1: chars[0] = base[byte1+0];
break;
default:
abort();
}
uint64_t value = *((uint64_t*)chars);
value = swap64(value); // if little endian
value >>= shift;
value &= ((1<<bit_width)-1);
return (uint32_t)value;
}
}
/**
* Rounds up a format to a standard size.
*/
static void OPRoundUp(size_t bitsPerComponentIn, size_t bitsPerPixelIn, size_t *bitsPerComponentOut, size_t *bitsPerPixelOut)
{
if (bitsPerComponentIn < 8)
{
*bitsPerComponentOut = 8;
}
else if (bitsPerComponentIn < 16)
{
*bitsPerComponentOut = 16;
}
else if (bitsPerComponentIn < 32)
{
*bitsPerComponentOut = 32;
}
*bitsPerPixelOut = (bitsPerPixelIn / bitsPerComponentIn) * (*bitsPerComponentOut);
}
static bool OPImageFormatForCGFormat(
size_t bitsPerComponent,
size_t bitsPerPixel,
CGBitmapInfo bitmapInfo,
CGColorSpaceRef colorSpace,
OPImageFormat *out)
{
switch (bitsPerComponent)
{
case 8:
out->compFormat = kOPComponentFormat8bpc;
break;
case 16:
out->compFormat = kOPComponentFormat16bpc;
break;
case 32:
if (bitmapInfo & kCGBitmapFloatComponents)
{
out->compFormat = kOPComponentFormat32bpc;
}
else
{
out->compFormat = kOPComponentFormatFloat32bpc;
}
break;
default:
return false;
}
size_t colorComponents = CGColorSpaceGetNumberOfComponents(colorSpace);
size_t actualComponents = bitsPerPixel / bitsPerComponent;
CGImageAlphaInfo alpha = bitmapInfo & kCGBitmapAlphaInfoMask;
out->colorComponents = colorComponents;
out->hasAlpha = (alpha != kCGImageAlphaNone && actualComponents > colorComponents);
out->isAlphaPremultiplied = (alpha == kCGImageAlphaPremultipliedFirst ||
alpha == kCGImageAlphaPremultipliedLast);
out->isAlphaLast = (alpha == kCGImageAlphaPremultipliedLast ||
alpha == kCGImageAlphaLast);
return true;
}
void OPImageConvert(
unsigned char *dstData,
const unsigned char *srcData,
size_t width,
size_t height,
size_t dstBitsPerComponent,
size_t srcBitsPerComponent,
size_t dstBitsPerPixel,
size_t srcBitsPerPixel,
size_t dstBytesPerRow,
size_t srcBytesPerRow,
CGBitmapInfo dstBitmapInfo,
CGBitmapInfo srcBitmapInfo,
CGColorSpaceRef dstColorSpace,
CGColorSpaceRef srcColorSpace,
CGColorRenderingIntent intent)
{
// For now, just support conversions that OPColorTransform can docs
OPImageFormat srcFormat, dstFormat;
if (!OPImageFormatForCGFormat(srcBitsPerComponent, srcBitsPerPixel, srcBitmapInfo, srcColorSpace, &srcFormat))
{
NSLog(@"Input format not supported");
}
if (!OPImageFormatForCGFormat(dstBitsPerComponent, dstBitsPerPixel, dstBitmapInfo, dstColorSpace, &dstFormat))
{
NSLog(@"Output format not supported");
}
OPImageFormatLog(srcFormat, @"OPImageConversion source");
OPImageFormatLog(dstFormat, @"OPImageConversion dest");
id<OPColorTransform> xform = [srcColorSpace colorTransformTo: dstColorSpace
sourceFormat: srcFormat
destinationFormat: dstFormat
renderingIntent: intent
pixelCount: width];
unsigned char *tempInput = malloc(srcBytesPerRow);
for (size_t row=0; row<height; row++)
{
const unsigned char *input = srcData + (row * srcBytesPerRow);
if (srcBitmapInfo & kCGBitmapByteOrder32Little)
{
for (size_t i=0; i<width; i++)
{
((uint32_t*)tempInput)[i] = GSSwapI32(((uint32_t*)(srcData + (row * srcBytesPerRow)))[i]);
}
input = tempInput;
}
[xform transformPixelData: input
output: dstData + (row * dstBytesPerRow)];
if (dstBitmapInfo & kCGBitmapByteOrder32Little)
{
for (uint32_t *pixel = (uint32_t*) (dstData + (row * dstBytesPerRow));
pixel < (uint32_t*) (dstData + (row * dstBytesPerRow) + dstBytesPerRow);
pixel++)
{
*pixel = GSSwapI32(*pixel);
}
}
}
free(tempInput);
}

View file

@ -0,0 +1,75 @@
/** <title>CGPath</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: August 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSObject.h>
#include "CoreGraphics/CGPath.h"
typedef struct
{
CGPathElementType type;
CGPoint points[3];
} OPPathElement;
@interface CGPath : NSObject
{
NSUInteger _count;
OPPathElement *_elementsArray;
}
- (id) initWithCGPath: (CGPathRef)path;
- (NSUInteger) count;
- (CGPathElementType) elementTypeAtIndex: (NSUInteger)index points: (CGPoint*)outPoints;
- (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points;
- (BOOL) isEqual:(id)otherObj;
- (BOOL) isRect: (CGRect*)outRect;
@end
@interface CGMutablePath : CGPath
{
NSUInteger _capacity;
}
- (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points;
@end
/*
* Functions and definitions for approximating arcs through bezier curves.
*/
#define OPPathArcDefaultTolerance 0.1
/**
* Calculates the number of segments needed to approximate an arc with the given
* <var>radius</var> after applying the affine transform from <var>m</var>.
* FIXME: Uses fixed tolerance to compute the number of segments needed.
*/
NSUInteger
_OPPathRequiredArcSegments(CGFloat angle,
CGFloat radius,
const CGAffineTransform *m);

View file

@ -0,0 +1,371 @@
/** <title>CGPath</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen
Date: August 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import "OPPath.h"
static NSUInteger OPNumberOfPointsForElementType(CGPathElementType type)
{
NSUInteger numPoints;
switch (type)
{
case kCGPathElementMoveToPoint:
numPoints = 1;
break;
case kCGPathElementAddLineToPoint:
numPoints = 1;
break;
case kCGPathElementAddQuadCurveToPoint:
numPoints = 2;
break;
case kCGPathElementAddCurveToPoint:
numPoints = 3;
break;
case kCGPathElementCloseSubpath:
default:
numPoints = 0;
break;
}
return numPoints;
}
@implementation CGPath
- (id) copyWithZone: (NSZone*)zone
{
return [self retain];
}
- (id) initWithCGPath: (CGPathRef)path
{
if (path)
{
[self release];
return [path retain];
}
else
{
self = [super init];
return self;
}
}
- (void)dealloc
{
free(_elementsArray);
[super dealloc];
}
- (NSUInteger) count
{
return _count;
}
- (CGPathElementType) elementTypeAtIndex: (NSUInteger)index points: (CGPoint*)outPoints
{
OPPathElement elem = _elementsArray[index];
if (outPoints)
{
switch (OPNumberOfPointsForElementType(elem.type))
{
case 3:
outPoints[2] = elem.points[2];
case 2:
outPoints[1] = elem.points[1];
case 1:
outPoints[0] = elem.points[0];
case 0:
default:
break;
}
}
return elem.type;
}
- (BOOL)isEqual:(id)otherObj
{
if (self == otherObj)
{
return YES;
}
if (![otherObj isKindOfClass: [CGPath class]])
{
return NO;
}
CGPath *path2 = (CGPath*)otherObj;
NSUInteger count1 = [self count];
NSUInteger count2 = [path2 count];
if (count1 != count2)
{
return NO;
}
for (NSUInteger i=0; i<count1; i++)
{
CGPoint points1[3];
CGPoint points2[3];
CGPathElementType type1 = [self elementTypeAtIndex: i points: points1];
CGPathElementType type2 = [path2 elementTypeAtIndex: i points: points2];
if (type1 != type2)
{
return NO;
}
NSUInteger numPoints = OPNumberOfPointsForElementType(type1);
for (NSUInteger p=0; p<numPoints; p++)
{
if (!CGPointEqualToPoint(points1[p], points2[p]))
{
return NO;
}
}
}
return YES;
}
- (BOOL)isRect: (CGRect*)outRect
{
if (_count != 5)
{
return NO;
}
if (_elementsArray[0].type != kCGPathElementMoveToPoint ||
_elementsArray[1].type != kCGPathElementAddLineToPoint ||
_elementsArray[2].type != kCGPathElementAddLineToPoint ||
_elementsArray[3].type != kCGPathElementAddLineToPoint ||
_elementsArray[4].type != kCGPathElementCloseSubpath)
{
return NO;
}
BOOL clockwise;
if (_elementsArray[1].points[0].x == _elementsArray[0].points[0].x)
{
clockwise = YES;
}
if (_elementsArray[1].points[0].y == _elementsArray[0].points[0].y)
{
clockwise = NO;
}
else
{
return NO;
}
// Check that it is actually a rectangle
if (clockwise)
{
if (_elementsArray[2].points[0].y != _elementsArray[1].points[0].y ||
_elementsArray[3].points[0].x != _elementsArray[2].points[0].x ||
_elementsArray[3].points[0].y != _elementsArray[0].points[0].y)
{
return NO;
}
}
else
{
if (_elementsArray[2].points[0].x != _elementsArray[1].points[0].x ||
_elementsArray[3].points[0].y != _elementsArray[2].points[0].y ||
_elementsArray[3].points[0].x != _elementsArray[0].points[0].x)
{
return NO;
}
}
if (outRect)
{
outRect->origin = _elementsArray[0].points[0];
// FIXME: do we abs the width/height?
outRect->size.width = _elementsArray[2].points[0].x - _elementsArray[0].points[0].x;
outRect->size.height = _elementsArray[2].points[0].y - _elementsArray[0].points[0].y;
}
return YES;
}
- (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points
{
[NSException raise: NSGenericException format: @"Attempt to modify immutable CGPath"];
}
@end
@implementation CGMutablePath
- (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points
{
if (_elementsArray)
{
if (_count + 1 > _capacity)
{
_capacity += 32;
_elementsArray = realloc(_elementsArray, _capacity * sizeof(OPPathElement));
}
}
else
{
_capacity = 32;
_elementsArray = malloc(_capacity * sizeof(OPPathElement));
}
_elementsArray[_count].type = type;
switch (OPNumberOfPointsForElementType(type))
{
case 3:
_elementsArray[_count].points[2] = points[2];
case 2:
_elementsArray[_count].points[1] = points[1];
case 1:
_elementsArray[_count].points[0] = points[0];
case 0:
default:
break;
}
_count++;
}
- (id) initWithCGPath: (CGPathRef)path
{
self = [super init];
if ([path isKindOfClass: [CGPath class]])
{
_count = path->_count;
_capacity = path->_count;
_elementsArray = malloc(path->_count * sizeof(OPPathElement));
if (NULL == _elementsArray)
{
[self release];
return nil;
}
memcpy(_elementsArray, path->_elementsArray, _count * sizeof(OPPathElement));
}
return self;
}
- (id) copyWithZone: (NSZone*)zone
{
return [[CGMutablePath alloc] initWithCGPath: self];
}
@end
/*
* Functions to generate curves as approximations of circular arcs. Follows the
* algorithm used by cairo.
*/
/*
* The values in this table come from cairo's cairo-arc.c. We use them to get
* simliar appearance for arcs drawn by cairo itself and those added to CGPaths.
* The values apply for (M_PI / (index + 1)).
*/
static CGFloat approximationErrorTable[] = {
0.0185185185185185036127,
0.000272567143730179811158,
2.38647043651461047433e-05,
4.2455377443222443279e-06 ,
1.11281001494389081528e-06,
3.72662000942734705475e-07,
1.47783685574284411325e-07,
6.63240432022601149057e-08,
3.2715520137536980553e-08,
1.73863223499021216974e-08,
9.81410988043554039085e-09,
};
static NSUInteger approximationErrorTableCount = 11;
static inline CGFloat
_OPPathArcAxisLengthForRadiusByApplyingTransform(CGFloat radius,
const CGAffineTransform *m)
{
if (NULL == m)
{
return radius;
}
CGFloat i = ((m->a * m->a) + (m->b * m->b));
CGFloat j = ((m->c * m->c) + (m->d * m->d));
CGFloat f = (0.5 * (i + j));
CGFloat g = (0.5 * (i - j));
CGFloat h = ((m->a * m->c) + (m->b * m->d));
//TODO: Maybe provide hypot() for non C99 compliant compilers?
return (radius * sqrt(f + hypot(g, h)));
}
static inline CGFloat
_OPPathArcErrorForAngle(CGFloat angle)
{
// This formula is also used for error computation in cairo:
return 2.0/27.0 * pow (sin (angle / 4), 6) / pow (cos (angle / 4), 2);
}
// Hopefully the compiler will specialize this for tolerance == 0.1 (default):
static inline CGFloat
_OPPathArcMaxAngleForTolerance(CGFloat tolerance)
{
CGFloat angle = 0;
CGFloat error = 0;
NSUInteger index = 0;
for (index = 0; index < approximationErrorTableCount; index++)
{
if (approximationErrorTable[index] < tolerance)
{
return (M_PI / (index + 1));
}
}
// Increment to get rid of the offset:
index++;
do
{
angle = (M_PI / index++);
error = _OPPathArcErrorForAngle(angle);
} while (error > tolerance);
return 0;
}
NSUInteger
_OPPathRequiredArcSegments(CGFloat angle,
CGFloat radius,
const CGAffineTransform *m)
{
// Transformation can turn the circle arc into the arc of an ellipse, we need
// its major axis.
CGFloat majorAxis = _OPPathArcAxisLengthForRadiusByApplyingTransform(radius, m);
CGFloat maxAngle = _OPPathArcMaxAngleForTolerance((OPPathArcDefaultTolerance / majorAxis));
return ceil((fabs(angle) / maxAngle));
}

View file

@ -0,0 +1,150 @@
/** <title>OPPostScriptContext</title>
<abstract>C Interface to graphics drawing library</abstract>
Copyright <copy>(C) 2010 Free Software Foundation, Inc.</copy>
Author: Eric Wasylishen <ewasylishen@gmail.com>
Date: June, 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#import <Foundation/NSString.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSDictionary.h>
#include "CoreGraphics/OPPostScriptContext.h"
#include "CoreGraphics/CGDataConsumer.h"
#include "CGContext-private.h"
#include "CGDataConsumer-private.h"
#include <cairo.h>
#include <cairo-ps.h>
/* Constants */
const CFStringRef kOPPostScriptContextIsEPS = @"kOPPostScriptContextIsEPS";
const CFStringRef kOPPostScriptContextLanguageLevel = @"kOPPostScriptContextLanguageLevel";
/* Functions */
void OPPostScriptContextBeginPage(CGContextRef ctx, CFDictionaryRef pageInfo)
{
// FIXME: Not sure what this should do. Nothing?
}
void OPPostScriptContextClose(CGContextRef ctx)
{
cairo_status_t cret;
cairo_surface_finish(cairo_get_target(ctx->ct));
cret = cairo_status(ctx->ct);
if (cret) {
NSLog(@"OPPostScriptContextClose status: %s",
cairo_status_to_string(cret));
return;
}
}
cairo_status_t opal_OPPostScriptContextWriteFunction(
void *closure,
const unsigned char *data,
unsigned int length)
{
OPDataConsumerPutBytes((CGDataConsumerRef)closure, data, length);
return CAIRO_STATUS_SUCCESS;
}
static void opal_setProperties(cairo_surface_t *surf, CFDictionaryRef auxiliaryInfo)
{
if ([[auxiliaryInfo valueForKey: kOPPostScriptContextIsEPS] boolValue])
{
cairo_ps_surface_set_eps(surf, 1);
}
if ([[auxiliaryInfo valueForKey: kOPPostScriptContextLanguageLevel] intValue] == 2)
{
cairo_ps_surface_restrict_to_level(surf, CAIRO_PS_LEVEL_2);
}
if ([[auxiliaryInfo valueForKey: kOPPostScriptContextLanguageLevel] intValue] == 3)
{
cairo_ps_surface_restrict_to_level(surf, CAIRO_PS_LEVEL_3);
}
}
static cairo_user_data_key_t OpalDataConsumerKey;
static void opal_SurfaceDestoryFunc(void *data)
{
CGDataConsumerRelease((CGDataConsumerRef)data);
}
CGContextRef OPPostScriptContextCreate(
CGDataConsumerRef consumer,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo)
{
CGRect box;
if (mediaBox == NULL) {
box = CGRectMake(0, 0, 8.5 * 72, 11 * 72);
} else {
box = *mediaBox;
}
//FIXME: We ignore the origin of mediaBox.. is that correct?
cairo_surface_t *surf = cairo_ps_surface_create_for_stream(
opal_OPPostScriptContextWriteFunction,
CGDataConsumerRetain(consumer),
box.size.width,
box.size.height);
cairo_surface_set_user_data(surf, &OpalDataConsumerKey, consumer, opal_SurfaceDestoryFunc);
opal_setProperties(surf, auxiliaryInfo);
CGContextRef ctx = opal_new_CGContext(surf, box.size);
return ctx;
}
CGContextRef OPPostScriptContextCreateWithURL(
CFURLRef url,
const CGRect *mediaBox,
CFDictionaryRef auxiliaryInfo)
{
CGDataConsumerRef dc = CGDataConsumerCreateWithURL(url);
CGContextRef ctx = OPPostScriptContextCreate(dc, mediaBox, auxiliaryInfo);
CGDataConsumerRelease(dc);
return ctx;
}
void OPPostScriptContextEndPage(CGContextRef ctx)
{
// Make sure it is not an EPS surface, which are single-page
if (!cairo_ps_surface_get_eps(cairo_get_target(ctx->ct)))
{
cairo_status_t cret;
cairo_show_page(ctx->ct);
cret = cairo_status(ctx->ct);
if (cret) {
NSLog(@"OPPostScriptContextEndPage status: %s",
cairo_status_to_string(cret));
return;
}
}
}

Some files were not shown because too many files have changed in this diff Show more