From f9b5c7a772b147da616641ff5760fe79a7adc9a0 Mon Sep 17 00:00:00 2001 From: Daniel Ferreira Date: Tue, 11 Jul 2017 07:40:55 +1000 Subject: [PATCH 1/2] chore: apply standard coding style Apply a standard coding style for the Opal project, which suffered from terribly deviating styles in a relatively small project. All files were formatted with: > astyle --style=gnu -s2 -xM -S -xP2 -H -xU -xC79 These options preserve the GNU coding standards. --- Headers/CoreGraphics/CGAffineTransform.h | 56 +- Headers/CoreGraphics/CGBase.h | 6 +- Headers/CoreGraphics/CGBitmapContext.h | 4 +- Headers/CoreGraphics/CGColor.h | 7 +- Headers/CoreGraphics/CGColorSpace.h | 10 +- Headers/CoreGraphics/CGContext.h | 48 +- Headers/CoreGraphics/CGDataConsumer.h | 6 +- Headers/CoreGraphics/CGDataProvider.h | 38 +- Headers/CoreGraphics/CGError.h | 7 +- Headers/CoreGraphics/CGEvent.h | 5 +- Headers/CoreGraphics/CGEventType.h | 5 +- Headers/CoreGraphics/CGFont.h | 16 +- Headers/CoreGraphics/CGFunction.h | 7 +- Headers/CoreGraphics/CGGeometry.h | 57 +- Headers/CoreGraphics/CGGradient.h | 7 +- Headers/CoreGraphics/CGImage.h | 7 +- Headers/CoreGraphics/CGImageDestination.h | 8 +- Headers/CoreGraphics/CGImageSource.h | 9 +- Headers/CoreGraphics/CGLayer.h | 10 +- Headers/CoreGraphics/CGPDFArray.h | 27 +- Headers/CoreGraphics/CGPDFContentStream.h | 6 +- Headers/CoreGraphics/CGPDFContext.h | 4 +- Headers/CoreGraphics/CGPDFDictionary.h | 36 +- Headers/CoreGraphics/CGPDFDocument.h | 4 +- Headers/CoreGraphics/CGPDFObject.h | 12 +- Headers/CoreGraphics/CGPDFOperatorTable.h | 6 +- Headers/CoreGraphics/CGPDFPage.h | 9 +- Headers/CoreGraphics/CGPDFScanner.h | 9 +- Headers/CoreGraphics/CGPDFStream.h | 9 +- Headers/CoreGraphics/CGPDFString.h | 6 +- Headers/CoreGraphics/CGPSConverter.h | 25 +- Headers/CoreGraphics/CGPath.h | 23 +- Headers/CoreGraphics/CGPattern.h | 7 +- Headers/CoreGraphics/CGShading.h | 4 +- Headers/CoreGraphics/CoreGraphics.h | 6 +- Headers/CoreGraphics/OPPostScriptContext.h | 4 +- Headers/CoreGraphics/OPSVGContext.h | 4 +- Headers/CoreText/CTFont.h | 16 +- Headers/CoreText/CTFontCollection.h | 10 +- Headers/CoreText/CTFontDescriptor.h | 18 +- Headers/CoreText/CTFontManager.h | 17 +- Headers/CoreText/CTFontManagerErrors.h | 10 +- Headers/CoreText/CTFontTraits.h | 13 +- Headers/CoreText/CTFrame.h | 7 +- Headers/CoreText/CTFramesetter.h | 7 +- Headers/CoreText/CTGlyphInfo.h | 10 +- Headers/CoreText/CTLine.h | 7 +- Headers/CoreText/CTParagraphStyle.h | 22 +- Headers/CoreText/CTRun.h | 9 +- Headers/CoreText/CTStringAttributes.h | 10 +- Headers/CoreText/CTTextTab.h | 4 +- Headers/CoreText/CTTypesetter.h | 7 +- Headers/CoreText/CoreText.h | 4 +- Source/OpalGraphics/CGAffineTransform.m | 22 +- Source/OpalGraphics/CGBitmapContext.m | 344 +++---- Source/OpalGraphics/CGColor-private.h | 10 +- Source/OpalGraphics/CGColor.m | 111 +-- Source/OpalGraphics/CGColorSpace-private.h | 14 +- Source/OpalGraphics/CGColorSpace.m | 87 +- Source/OpalGraphics/CGContext+GState.m | 62 +- Source/OpalGraphics/CGContext-private.h | 7 +- Source/OpalGraphics/CGContext.m | 857 ++++++++++-------- Source/OpalGraphics/CGDataConsumer-private.h | 7 +- Source/OpalGraphics/CGDataConsumer.m | 52 +- Source/OpalGraphics/CGDataProvider-private.h | 9 +- Source/OpalGraphics/CGDataProvider.m | 191 ++-- Source/OpalGraphics/CGFont.m | 20 +- Source/OpalGraphics/CGFunction.m | 14 +- Source/OpalGraphics/CGGeometry.m | 110 ++- Source/OpalGraphics/CGGradient-private.h | 12 +- Source/OpalGraphics/CGGradient.m | 42 +- Source/OpalGraphics/CGImage-private.h | 4 +- Source/OpalGraphics/CGImage.m | 322 +++---- Source/OpalGraphics/CGImageDestination.m | 57 +- Source/OpalGraphics/CGImageSource-private.h | 9 +- Source/OpalGraphics/CGImageSource.m | 143 +-- Source/OpalGraphics/CGLayer.m | 27 +- Source/OpalGraphics/CGPDFArray.m | 31 +- Source/OpalGraphics/CGPDFContentStream.m | 14 +- Source/OpalGraphics/CGPDFContext.m | 65 +- Source/OpalGraphics/CGPDFDictionary.m | 42 +- Source/OpalGraphics/CGPDFDocument.m | 12 +- Source/OpalGraphics/CGPDFObject.m | 13 +- Source/OpalGraphics/CGPDFOperatorTable.m | 14 +- Source/OpalGraphics/CGPDFPage.m | 14 +- Source/OpalGraphics/CGPDFScanner.m | 15 +- Source/OpalGraphics/CGPDFStream.m | 10 +- Source/OpalGraphics/CGPDFString.m | 12 +- Source/OpalGraphics/CGPSConverter.m | 14 +- Source/OpalGraphics/CGPath.m | 397 ++++---- Source/OpalGraphics/CGPattern.m | 12 +- Source/OpalGraphics/CGShading.m | 16 +- Source/OpalGraphics/OPColorSpaceIndexed.h | 4 +- Source/OpalGraphics/OPColorSpaceIndexed.m | 46 +- Source/OpalGraphics/OPColorSpaceLCMS.h | 10 +- Source/OpalGraphics/OPColorSpaceLCMS.m | 183 ++-- Source/OpalGraphics/OPColorTransformLCMS.h | 6 +- Source/OpalGraphics/OPColorTransformLCMS.m | 376 ++++---- Source/OpalGraphics/OPImageConversion.h | 10 +- Source/OpalGraphics/OPImageConversion.m | 308 ++++--- Source/OpalGraphics/OPLogging.h | 4 +- Source/OpalGraphics/OPLogging.m | 4 +- Source/OpalGraphics/OPPath.h | 9 +- Source/OpalGraphics/OPPath.m | 312 +++---- Source/OpalGraphics/OPPostScriptContext.m | 98 +- Source/OpalGraphics/OPPremultiplyAlpha.h | 4 +- Source/OpalGraphics/OPPremultiplyAlpha.m | 92 +- Source/OpalGraphics/OPSVGContext.m | 80 +- Source/OpalGraphics/cairo/CairoFont.h | 14 +- Source/OpalGraphics/cairo/CairoFont.m | 10 +- Source/OpalGraphics/cairo/CairoFontWin32.h | 10 +- Source/OpalGraphics/cairo/CairoFontWin32.m | 458 +++++----- Source/OpalGraphics/cairo/CairoFontX11.h | 6 +- Source/OpalGraphics/cairo/CairoFontX11.m | 336 +++---- .../OpalGraphics/cairo/StandardGlyphNames.h | 6 +- .../OpalGraphics/cairo/StandardGlyphNames.m | 4 +- Source/OpalGraphics/image/OPImageCodecJPEG.m | 285 +++--- Source/OpalGraphics/image/OPImageCodecPNG.m | 218 ++--- Source/OpalGraphics/image/OPImageCodecTIFF.m | 159 ++-- Source/OpalGraphics/internal/CGFontInternal.h | 12 +- Source/OpalGraphics/opal-win32.m | 9 +- Source/OpalGraphics/opal-x11.m | 38 +- Source/OpalText/CTFont.m | 168 ++-- Source/OpalText/CTFontCollection.m | 61 +- Source/OpalText/CTFontDescriptor.m | 91 +- Source/OpalText/CTFontTraits.m | 4 +- Source/OpalText/CTFrame-private.h | 20 +- Source/OpalText/CTFrame.m | 37 +- Source/OpalText/CTFramesetter.m | 93 +- Source/OpalText/CTGlyphInfo.m | 47 +- Source/OpalText/CTLine-private.h | 12 +- Source/OpalText/CTLine.m | 72 +- Source/OpalText/CTParagraphStyle.m | 19 +- Source/OpalText/CTRun-private.h | 12 +- Source/OpalText/CTRun.m | 93 +- Source/OpalText/CTStringAttributes.m | 25 +- Source/OpalText/CTTextTab.m | 19 +- Source/OpalText/CTTypesetter.m | 43 +- Source/OpalText/Fontconfig/OPFontconfigFont.m | 12 +- .../Fontconfig/OPFontconfigFontCollection.m | 70 +- .../Fontconfig/OPFontconfigFontDescriptor.m | 825 +++++++++-------- Source/OpalText/FreeType/OPFreeTypeFont.h | 2 +- Source/OpalText/FreeType/OPFreeTypeFont.m | 346 +++---- Source/OpalText/FreeType/OPFreeTypeUtil.h | 16 +- Source/OpalText/GDI/NSGDIFontDescriptor.m | 204 ++--- Source/OpalText/OPFont.h | 26 +- Source/OpalText/OPFont.m | 57 +- Source/OpalText/OPFontDescriptor.h | 24 +- Source/OpalText/OPFontDescriptor.m | 144 +-- Source/OpalText/OPLayoutEngine.h | 4 +- Source/OpalText/OPSimpleLayoutEngine.h | 4 +- Source/OpalText/OPSimpleLayoutEngine.m | 36 +- Tests/arcs.m | 130 +-- Tests/bitmaps.m | 109 +-- Tests/cocoa.m | 9 +- Tests/colorspace.m | 8 +- Tests/doublebuffer.m | 8 +- Tests/gradients.m | 61 +- Tests/gstate.m | 26 +- Tests/images.m | 96 +- Tests/layers.m | 58 +- Tests/ovals.m | 102 +-- Tests/pdf.m | 144 +-- Tests/qeb2-draw.m | 172 ++-- Tests/rects.m | 141 +-- Tests/shadows.m | 19 +- Tests/shapes.m | 154 ++-- Tests/textlayout.m | 466 +++++----- Tests/texttest.m | 155 ++-- Tests/win32.m | 106 +-- Tests/x11.m | 93 +- 171 files changed, 6186 insertions(+), 5467 deletions(-) diff --git a/Headers/CoreGraphics/CGAffineTransform.h b/Headers/CoreGraphics/CGAffineTransform.h index 218f967..b890e4f 100644 --- a/Headers/CoreGraphics/CGAffineTransform.h +++ b/Headers/CoreGraphics/CGAffineTransform.h @@ -11,12 +11,12 @@ 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 @@ -54,7 +54,7 @@ extern const CGAffineTransform CGAffineTransformIdentity; */ #ifdef IN_CGAFFINETRANSFORM_C #define GS_AFTR_SCOPE extern -#define GS_AFTR_ATTR +#define GS_AFTR_ATTR #else #define GS_AFTR_SCOPE static inline #define GS_AFTR_ATTR __attribute__((unused)) @@ -106,7 +106,7 @@ GS_AFTR_SCOPE CGAffineTransform CGAffineTransformRotate( GS_AFTR_SCOPE bool CGAffineTransformEqualToTransform( CGAffineTransform t1, CGAffineTransform t2 -) GS_AFTR_ATTR; +) GS_AFTR_ATTR; GS_AFTR_SCOPE bool CGAffineTransformIsIdentity( CGAffineTransform t @@ -158,7 +158,8 @@ GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeTranslation( return matrix; } -GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy) +GS_AFTR_SCOPE CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, + CGFloat sy) { CGAffineTransform matrix; @@ -210,26 +211,33 @@ GS_AFTR_SCOPE CGAffineTransform CGAffineTransformRotate( return CGAffineTransformConcat(CGAffineTransformMakeRotation(angle), t); } -GS_AFTR_SCOPE bool CGAffineTransformEqualToTransform(CGAffineTransform t1, CGAffineTransform t2) +GS_AFTR_SCOPE bool CGAffineTransformEqualToTransform(CGAffineTransform t1, + CGAffineTransform t2) { - if (t1.a != t2.a) { - return false; - } - if (t1.b != t2.b) { - return false; - } - if (t1.c != t2.c) { - return false; - } - if (t1.d != t2.d) { - return false; - } - if (t1.tx != t2.tx) { - return false; - } - if (t1.ty != t2.ty) { - return false; - } + if (t1.a != t2.a) + { + return false; + } + if (t1.b != t2.b) + { + return false; + } + if (t1.c != t2.c) + { + return false; + } + if (t1.d != t2.d) + { + return false; + } + if (t1.tx != t2.tx) + { + return false; + } + if (t1.ty != t2.ty) + { + return false; + } return true; } diff --git a/Headers/CoreGraphics/CGBase.h b/Headers/CoreGraphics/CGBase.h index 0e50d83..cdf9aa9 100644 --- a/Headers/CoreGraphics/CGBase.h +++ b/Headers/CoreGraphics/CGBase.h @@ -11,12 +11,12 @@ 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 @@ -53,7 +53,7 @@ #define CGFLOAT_MIN FLT_MIN #define CGFLOAT_MAX FLT_MAX #endif - + typedef CGFLOAT_TYPE CGFloat; #endif // CGFLOAT_DEFINED diff --git a/Headers/CoreGraphics/CGBitmapContext.h b/Headers/CoreGraphics/CGBitmapContext.h index ac94766..34f0cf7 100644 --- a/Headers/CoreGraphics/CGBitmapContext.h +++ b/Headers/CoreGraphics/CGBitmapContext.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreGraphics/CGColor.h b/Headers/CoreGraphics/CGColor.h index d947ee2..5b1295f 100644 --- a/Headers/CoreGraphics/CGColor.h +++ b/Headers/CoreGraphics/CGColor.h @@ -11,12 +11,12 @@ 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 @@ -46,7 +46,8 @@ const extern CFStringRef kCGColorClear; /* Functions */ -extern CGColorRef CGColorCreate(CGColorSpaceRef colorspace, const CGFloat components[]); +extern CGColorRef CGColorCreate(CGColorSpaceRef colorspace, + const CGFloat components[]); CGColorRef CGColorCreateCopy(CGColorRef clr); CGColorRef CGColorCreateCopyWithAlpha(CGColorRef clr, CGFloat alpha); diff --git a/Headers/CoreGraphics/CGColorSpace.h b/Headers/CoreGraphics/CGColorSpace.h index 9dd3f58..59fcf5b 100644 --- a/Headers/CoreGraphics/CGColorSpace.h +++ b/Headers/CoreGraphics/CGColorSpace.h @@ -11,12 +11,12 @@ 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 @@ -41,7 +41,8 @@ typedef struct CGColorSpace* CGColorSpaceRef; #include #include -typedef enum CGColorSpaceModel { +typedef enum CGColorSpaceModel +{ kCGColorSpaceModelUnknown = -1, kCGColorSpaceModelMonochrome = 0, kCGColorSpaceModelRGB = 1, @@ -55,7 +56,8 @@ typedef enum CGColorSpaceModel { /* Constants */ -typedef enum CGColorRenderingIntent { +typedef enum CGColorRenderingIntent +{ kCGRenderingIntentDefault = 0, kCGRenderingIntentAbsoluteColorimetric = 1, kCGRenderingIntentRelativeColorimetric = 2, diff --git a/Headers/CoreGraphics/CGContext.h b/Headers/CoreGraphics/CGContext.h index 4424058..1564442 100644 --- a/Headers/CoreGraphics/CGContext.h +++ b/Headers/CoreGraphics/CGContext.h @@ -11,12 +11,12 @@ 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 @@ -52,7 +52,8 @@ typedef struct OPGState* OPGStateRef; /* Constants */ -typedef enum CGBlendMode { +typedef enum CGBlendMode +{ kCGBlendModeNormal = 0, kCGBlendModeMultiply = 1, kCGBlendModeScreen = 2, @@ -83,7 +84,8 @@ typedef enum CGBlendMode { kCGBlendModePlusLighter = 27 } CGBlendMode; -typedef enum CGInterpolationQuality { +typedef enum CGInterpolationQuality +{ kCGInterpolationDefault = 0, kCGInterpolationNone = 1, kCGInterpolationLow = 2, @@ -91,19 +93,22 @@ typedef enum CGInterpolationQuality { kCGInterpolationHigh = 3 } CGInterpolationQuality; -typedef enum CGLineCap { +typedef enum CGLineCap +{ kCGLineCapButt = 0, kCGLineCapRound = 1, kCGLineCapSquare = 2 } CGLineCap; -typedef enum CGLineJoin { +typedef enum CGLineJoin +{ kCGLineJoinMiter = 0, kCGLineJoinRound = 1, kCGLineJoinBevel = 2 } CGLineJoin; -typedef enum CGPathDrawingMode { +typedef enum CGPathDrawingMode +{ kCGPathFill = 0, kCGPathEOFill = 1, kCGPathStroke = 2, @@ -111,7 +116,8 @@ typedef enum CGPathDrawingMode { kCGPathEOFillStroke = 4 } CGPathDrawingMode; -typedef enum CGTextDrawingMode { +typedef enum CGTextDrawingMode +{ kCGTextFill = 0, kCGTextStroke = 1, kCGTextFillStroke = 2, @@ -122,7 +128,8 @@ typedef enum CGTextDrawingMode { kCGTextClip = 7 } CGTextDrawingMode; -typedef enum CGTextEncoding { +typedef enum CGTextEncoding +{ kCGEncodingFontSpecific = 0, kCGEncodingMacRoman = 1 } CGTextEncoding; @@ -209,7 +216,8 @@ void CGContextSetStrokePattern( void CGContextSetShouldSmoothFonts(CGContextRef ctx, int shouldSmoothFonts); -void CGContextSetAllowsFontSmoothing(CGContextRef ctx, bool allowsFontSmoothing); +void CGContextSetAllowsFontSmoothing(CGContextRef ctx, + bool allowsFontSmoothing); void CGContextSetBlendMode(CGContextRef ctx, CGBlendMode mode); @@ -321,7 +329,8 @@ void CGContextDrawPath(CGContextRef ctx, CGPathDrawingMode mode); void CGContextStrokeRect(CGContextRef ctx, CGRect rect); -void CGContextStrokeRectWithWidth(CGContextRef ctx, CGRect rect, CGFloat width); +void CGContextStrokeRectWithWidth(CGContextRef ctx, CGRect rect, + CGFloat width); void CGContextFillRect(CGContextRef ctx, CGRect rect); @@ -357,7 +366,8 @@ void CGContextEOClip(CGContextRef ctx); void CGContextClipToRect(CGContextRef ctx, CGRect rect); -void CGContextClipToRects(CGContextRef ctx, const CGRect rects[], size_t count); +void CGContextClipToRects(CGContextRef ctx, const CGRect rects[], + size_t count); void CGContextClipToMask(CGContextRef ctx, CGRect rect, CGImageRef mask); @@ -373,7 +383,8 @@ void CGContextSetAlpha(CGContextRef ctx, CGFloat alpha); void CGContextSetFillColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace); -void CGContextSetStrokeColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace); +void CGContextSetStrokeColorSpace(CGContextRef ctx, + CGColorSpaceRef colorspace); void CGContextSetFillColor(CGContextRef ctx, const CGFloat components[]); @@ -381,7 +392,8 @@ void CGContextSetStrokeColor(CGContextRef ctx, const CGFloat components[]); void CGContextSetGrayFillColor(CGContextRef ctx, CGFloat gray, CGFloat alpha); -void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, CGFloat alpha); +void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, + CGFloat alpha); void CGContextSetRGBFillColor( CGContextRef ctx, @@ -417,7 +429,8 @@ void CGContextSetCMYKStrokeColor( CGFloat alpha ); -void CGContextSetRenderingIntent(CGContextRef ctx, CGColorRenderingIntent intent); +void CGContextSetRenderingIntent(CGContextRef ctx, + CGColorRenderingIntent intent); /* Drawing Images */ @@ -537,7 +550,8 @@ void CGContextEndTransparencyLayer(CGContextRef ctx); /* User to Device Transformation */ -CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef ctx); +CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform( + CGContextRef ctx); CGPoint CGContextConvertPointToDeviceSpace(CGContextRef ctx, CGPoint point); @@ -566,7 +580,7 @@ void OPContextResetClip(CGContextRef ctx); void OPContextSetIdentityCTM(CGContextRef ctx); void OPContextSetCairoDeviceOffset(CGContextRef ctx, - CGFloat x, CGFloat y); + CGFloat x, CGFloat y); OPGStateRef OPContextCopyGState(CGContextRef ctx); diff --git a/Headers/CoreGraphics/CGDataConsumer.h b/Headers/CoreGraphics/CGDataConsumer.h index 9bed625..1a33300 100644 --- a/Headers/CoreGraphics/CGDataConsumer.h +++ b/Headers/CoreGraphics/CGDataConsumer.h @@ -6,17 +6,17 @@ Author: BALATON Zoltan 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 diff --git a/Headers/CoreGraphics/CGDataProvider.h b/Headers/CoreGraphics/CGDataProvider.h index 16b6478..3ecec3c 100644 --- a/Headers/CoreGraphics/CGDataProvider.h +++ b/Headers/CoreGraphics/CGDataProvider.h @@ -11,12 +11,12 @@ 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 @@ -62,7 +62,7 @@ typedef void (*CGDataProviderReleaseInfoCallback)(void *info); /** * Direct access data provider callbacks */ - + typedef const void *(*CGDataProviderGetBytePointerCallback)(void *info); typedef void (*CGDataProviderReleaseBytePointerCallback)( @@ -84,7 +84,7 @@ typedef size_t (*CGDataProviderGetBytesAtPositionCallback)( size_t count ); -/** +/** * Callback for CGDataProviderCreateWithData */ @@ -101,11 +101,11 @@ typedef void (*CGDataProviderReleaseDataCallback)( */ typedef struct CGDataProviderDirectCallbacks { - unsigned int version; - CGDataProviderGetBytePointerCallback getBytePointer; - CGDataProviderReleaseBytePointerCallback releaseBytePointer; - CGDataProviderGetBytesAtPositionCallback getBytesAtPosition; - CGDataProviderReleaseInfoCallback releaseInfo; + unsigned int version; + CGDataProviderGetBytePointerCallback getBytePointer; + CGDataProviderReleaseBytePointerCallback releaseBytePointer; + CGDataProviderGetBytesAtPositionCallback getBytesAtPosition; + CGDataProviderReleaseInfoCallback releaseInfo; } CGDataProviderDirectCallbacks; /** @@ -124,11 +124,11 @@ typedef struct CGDataProviderDirectAccessCallbacks */ typedef struct CGDataProviderSequentialCallbacks { - unsigned int version; - CGDataProviderGetBytesCallback getBytes; - CGDataProviderSkipForwardCallback skipForward; - CGDataProviderRewindCallback rewind; - CGDataProviderReleaseInfoCallback releaseInfo; + unsigned int version; + CGDataProviderGetBytesCallback getBytes; + CGDataProviderSkipForwardCallback skipForward; + CGDataProviderRewindCallback rewind; + CGDataProviderReleaseInfoCallback releaseInfo; } CGDataProviderSequentialCallbacks; /** @@ -146,14 +146,14 @@ typedef struct CGDataProviderCallbacks /* Functions */ CGDataProviderRef CGDataProviderCreateDirect( - void *info, - off_t size, - const CGDataProviderDirectCallbacks *callbacks + void *info, + off_t size, + const CGDataProviderDirectCallbacks *callbacks ); CGDataProviderRef CGDataProviderCreateSequential( - void *info, - const CGDataProviderSequentialCallbacks *callbacks + void *info, + const CGDataProviderSequentialCallbacks *callbacks ); /** diff --git a/Headers/CoreGraphics/CGError.h b/Headers/CoreGraphics/CGError.h index 05f87fc..d7d8666 100644 --- a/Headers/CoreGraphics/CGError.h +++ b/Headers/CoreGraphics/CGError.h @@ -12,18 +12,19 @@ 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 */ -typedef enum { +typedef enum +{ kCGErrorSuccess = 0, kCGErrorFailure = 1000, diff --git a/Headers/CoreGraphics/CGEvent.h b/Headers/CoreGraphics/CGEvent.h index 68cbe71..5b617f6 100644 --- a/Headers/CoreGraphics/CGEvent.h +++ b/Headers/CoreGraphics/CGEvent.h @@ -1,5 +1,5 @@ -/* +/* CGEvent.h Copyright (C) 2012 Free Software Foundation, Inc. @@ -28,5 +28,6 @@ #import "CGEventType.h" -extern int64_t CGEventGetIntegerValueField(CGEventRef event, CGEventField field); +extern int64_t CGEventGetIntegerValueField(CGEventRef event, + CGEventField field); extern CGEventSourceRef CGEventCreateSourceFromEvent(CGEventRef event); diff --git a/Headers/CoreGraphics/CGEventType.h b/Headers/CoreGraphics/CGEventType.h index 9bc2800..5dddd33 100644 --- a/Headers/CoreGraphics/CGEventType.h +++ b/Headers/CoreGraphics/CGEventType.h @@ -1,5 +1,5 @@ -/* +/* CGEventType.h Copyright (C) 2012 Free Software Foundation, Inc. @@ -29,7 +29,8 @@ typedef struct __CGEvent *CGEventRef; typedef struct __CGEventSource *CGEventSourceRef; -typedef enum { +typedef enum +{ kCGScrollWheelEventIsContinuous = 88, kCGScrollWheelEventFixedPtDeltaAxis1 = 93, kCGScrollWheelEventFixedPtDeltaAxis2 = 94, diff --git a/Headers/CoreGraphics/CGFont.h b/Headers/CoreGraphics/CGFont.h index 665438e..3b7c090 100644 --- a/Headers/CoreGraphics/CGFont.h +++ b/Headers/CoreGraphics/CGFont.h @@ -11,12 +11,12 @@ 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 @@ -44,13 +44,15 @@ typedef unsigned short CGFontIndex; /* Constants */ -enum { - kCGFontIndexMax = ((1 << 16) - 2), - kCGFontIndexInvalid = ((1 << 16) - 1), - kCGGlyphMax = kCGFontIndexMax +enum +{ + kCGFontIndexMax = ((1 << 16) - 2), + kCGFontIndexInvalid = ((1 << 16) - 1), + kCGGlyphMax = kCGFontIndexMax }; -typedef enum CGFontPostScriptFormat { +typedef enum CGFontPostScriptFormat +{ kCGFontPostScriptFormatType1 = 1, kCGFontPostScriptFormatType3 = 3, kCGFontPostScriptFormatType42 = 42 diff --git a/Headers/CoreGraphics/CGFunction.h b/Headers/CoreGraphics/CGFunction.h index 38a5c42..c7a7149 100644 --- a/Headers/CoreGraphics/CGFunction.h +++ b/Headers/CoreGraphics/CGFunction.h @@ -11,12 +11,12 @@ 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 @@ -46,7 +46,8 @@ typedef void (*CGFunctionEvaluateCallback)( typedef void (*CGFunctionReleaseInfoCallback)(void *info); -typedef struct CGFunctionCallbacks { +typedef struct CGFunctionCallbacks +{ unsigned int version; CGFunctionEvaluateCallback evaluate; CGFunctionReleaseInfoCallback releaseInfo; diff --git a/Headers/CoreGraphics/CGGeometry.h b/Headers/CoreGraphics/CGGeometry.h index 8d17b52..42c5564 100644 --- a/Headers/CoreGraphics/CGGeometry.h +++ b/Headers/CoreGraphics/CGGeometry.h @@ -11,12 +11,12 @@ 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 @@ -82,7 +82,7 @@ extern const CGRect CGRectInfinite; */ #ifdef IN_CGGEOMETRY_C #define OP_GEOM_SCOPE extern -#define OP_GEOM_ATTR +#define OP_GEOM_ATTR #else #define OP_GEOM_SCOPE static inline #define OP_GEOM_ATTR __attribute__((unused)) @@ -97,7 +97,8 @@ OP_GEOM_SCOPE CGPoint CGPointMake(CGFloat x, CGFloat y) OP_GEOM_ATTR; 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; +OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, + CGFloat height) OP_GEOM_ATTR; OP_GEOM_SCOPE CGRect NSRectToCGRect(NSRect rect); OP_GEOM_SCOPE NSRect NSRectFromCGRect(CGRect rect); @@ -111,13 +112,15 @@ 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; +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; +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. */ @@ -179,7 +182,8 @@ OP_GEOM_SCOPE int CGRectIsEmpty(CGRect rect) OP_GEOM_ATTR; int CGRectIsInfinite(CGRect rect); /** Returns 1 iff rect1 and rect2 are intersecting. */ -OP_GEOM_SCOPE int CGRectIntersectsRect(CGRect rect1, CGRect rect2) OP_GEOM_ATTR; +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; @@ -194,19 +198,23 @@ OP_GEOM_SCOPE int CGRectEqualToRect(CGRect rect1, CGRect rect2) OP_GEOM_ATTR; 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; +OP_GEOM_SCOPE int CGPointEqualToPoint(CGPoint point1, + CGPoint point2) OP_GEOM_ATTR; CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point); - -bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point); + +bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, + CGPoint *point); CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size); -bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size); +bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, + CGSize *size); CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect rect); -bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGRect *rect); +bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict, + CGRect *rect); /* Inlined functions */ @@ -327,7 +335,8 @@ OP_GEOM_SCOPE CGSize CGSizeMake(CGFloat width, CGFloat height) return size; } -OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) +OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, + CGFloat height) { CGRect rect; @@ -341,7 +350,7 @@ OP_GEOM_SCOPE CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat hei OP_GEOM_SCOPE CGRect NSRectToCGRect(NSRect rect) { CGRect cgrect; - + cgrect.origin.x = rect.origin.x; cgrect.origin.y = rect.origin.y; cgrect.size.width = rect.size.width; @@ -352,7 +361,7 @@ OP_GEOM_SCOPE CGRect NSRectToCGRect(NSRect rect) OP_GEOM_SCOPE NSRect NSRectFromCGRect(CGRect rect) { NSRect nsrect; - + nsrect.origin.x = rect.origin.x; nsrect.origin.y = rect.origin.y; nsrect.size.width = rect.size.width; @@ -398,14 +407,16 @@ OP_GEOM_SCOPE CGSize NSSizeToCGSize(NSSize size) 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; - } + 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; } diff --git a/Headers/CoreGraphics/CGGradient.h b/Headers/CoreGraphics/CGGradient.h index c2db0ac..0584c75 100644 --- a/Headers/CoreGraphics/CGGradient.h +++ b/Headers/CoreGraphics/CGGradient.h @@ -10,12 +10,12 @@ 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 @@ -38,7 +38,8 @@ typedef struct CGGradient* CGGradientRef; /* Constants */ -typedef enum { +typedef enum +{ kCGGradientDrawsBeforeStartLocation = (1 << 0), kCGGradientDrawsAfterEndLocation = (1 << 1) } CGGradientDrawingOptions; diff --git a/Headers/CoreGraphics/CGImage.h b/Headers/CoreGraphics/CGImage.h index 7283f9f..6eff9db 100644 --- a/Headers/CoreGraphics/CGImage.h +++ b/Headers/CoreGraphics/CGImage.h @@ -11,12 +11,12 @@ 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 @@ -53,7 +53,8 @@ typedef enum CGImageAlphaInfo kCGImageAlphaOnly = 7 } CGImageAlphaInfo; -typedef enum CGBitmapInfo { +typedef enum CGBitmapInfo +{ kCGBitmapAlphaInfoMask = 0x1F, kCGBitmapFloatComponents = (1 << 8), kCGBitmapByteOrderMask = 0x7000, diff --git a/Headers/CoreGraphics/CGImageDestination.h b/Headers/CoreGraphics/CGImageDestination.h index 6639741..3f47181 100644 --- a/Headers/CoreGraphics/CGImageDestination.h +++ b/Headers/CoreGraphics/CGImageDestination.h @@ -4,22 +4,22 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 diff --git a/Headers/CoreGraphics/CGImageSource.h b/Headers/CoreGraphics/CGImageSource.h index 063d4e8..47f6c1d 100644 --- a/Headers/CoreGraphics/CGImageSource.h +++ b/Headers/CoreGraphics/CGImageSource.h @@ -4,17 +4,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -28,7 +28,8 @@ /* Constants */ -typedef enum CGImageSourceStatus { +typedef enum CGImageSourceStatus +{ kCGImageStatusUnexpectedEOF = -5, kCGImageStatusInvalidData = -4, kCGImageStatusUnknownType = -3, diff --git a/Headers/CoreGraphics/CGLayer.h b/Headers/CoreGraphics/CGLayer.h index d7d9bf3..1617a1e 100644 --- a/Headers/CoreGraphics/CGLayer.h +++ b/Headers/CoreGraphics/CGLayer.h @@ -1,22 +1,22 @@ /** CGLayer - + C Interface to graphics drawing library - + Copyright (C) 2009 Free Software Foundation, Inc. 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 diff --git a/Headers/CoreGraphics/CGPDFArray.h b/Headers/CoreGraphics/CGPDFArray.h index 3547ac4..bafe14e 100644 --- a/Headers/CoreGraphics/CGPDFArray.h +++ b/Headers/CoreGraphics/CGPDFArray.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -41,15 +41,19 @@ typedef struct CGPDFArray* CGPDFArrayRef; /* Functions */ -bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, CGPDFArrayRef *value); +bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, + CGPDFArrayRef *value); -bool CGPDFArrayGetBoolean(CGPDFArrayRef array, size_t index, CGPDFBoolean *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 CGPDFArrayGetDictionary(CGPDFArrayRef array, size_t index, + CGPDFDictionaryRef *value); -bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, CGPDFInteger *value); +bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, + CGPDFInteger *value); bool CGPDFArrayGetName(CGPDFArrayRef array, size_t index, const char **value); @@ -57,10 +61,13 @@ 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 CGPDFArrayGetObject(CGPDFArrayRef array, size_t index, + CGPDFObjectRef *value); -bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, CGPDFStreamRef *value); +bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, + CGPDFStreamRef *value); -bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, CGPDFStringRef *value); +bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, + CGPDFStringRef *value); #endif /* OPAL_CGPDFArray_h */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFContentStream.h b/Headers/CoreGraphics/CGPDFContentStream.h index 5ec9cf1..cdb4c95 100644 --- a/Headers/CoreGraphics/CGPDFContentStream.h +++ b/Headers/CoreGraphics/CGPDFContentStream.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 diff --git a/Headers/CoreGraphics/CGPDFContext.h b/Headers/CoreGraphics/CGPDFContext.h index e6c596c..8c34feb 100644 --- a/Headers/CoreGraphics/CGPDFContext.h +++ b/Headers/CoreGraphics/CGPDFContext.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreGraphics/CGPDFDictionary.h b/Headers/CoreGraphics/CGPDFDictionary.h index aa215a3..631a2ac 100644 --- a/Headers/CoreGraphics/CGPDFDictionary.h +++ b/Headers/CoreGraphics/CGPDFDictionary.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -48,26 +48,36 @@ typedef void (*CGPDFDictionaryApplierFunction)( /* Functions */ -void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, CGPDFDictionaryApplierFunction function, void *info); +void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, + CGPDFDictionaryApplierFunction function, void *info); size_t CGPDFDictionaryGetCount(CGPDFDictionaryRef dict); -bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, CGPDFArrayRef *value); +bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, + CGPDFArrayRef *value); -bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, CGPDFBoolean *value); +bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, + CGPDFBoolean *value); -bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, CGPDFDictionaryRef *value); +bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, + CGPDFDictionaryRef *value); -bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, CGPDFInteger *value); +bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, + CGPDFInteger *value); -bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, const char **value); +bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, + const char **value); -bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, CGPDFReal *value); +bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, + CGPDFReal *value); -bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, CGPDFObjectRef *value); +bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, + CGPDFObjectRef *value); -bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, CGPDFStreamRef *value); +bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, + CGPDFStreamRef *value); -bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, CGPDFStringRef *value); +bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, + CGPDFStringRef *value); #endif /* OPAL_CGPDFDictionary_h */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFDocument.h b/Headers/CoreGraphics/CGPDFDocument.h index 66926b1..f2906cb 100644 --- a/Headers/CoreGraphics/CGPDFDocument.h +++ b/Headers/CoreGraphics/CGPDFDocument.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreGraphics/CGPDFObject.h b/Headers/CoreGraphics/CGPDFObject.h index 28b7a43..02e4b3e 100644 --- a/Headers/CoreGraphics/CGPDFObject.h +++ b/Headers/CoreGraphics/CGPDFObject.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -43,7 +43,8 @@ typedef struct CGPDFObject* CGPDFObjectRef; /* Constants */ -typedef enum CGPDFObjectType { +typedef enum CGPDFObjectType +{ kCGPDFObjectTypeNull = 1, kCGPDFObjectTypeBoolean = 2, kCGPDFObjectTypeInteger = 3, @@ -59,6 +60,7 @@ typedef enum CGPDFObjectType { CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object); -bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, void *value); +bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, + void *value); #endif /* OPAL_CGPDFDictionary_h */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFOperatorTable.h b/Headers/CoreGraphics/CGPDFOperatorTable.h index fe23595..d1692aa 100644 --- a/Headers/CoreGraphics/CGPDFOperatorTable.h +++ b/Headers/CoreGraphics/CGPDFOperatorTable.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 diff --git a/Headers/CoreGraphics/CGPDFPage.h b/Headers/CoreGraphics/CGPDFPage.h index 7f93378..e1a9950 100644 --- a/Headers/CoreGraphics/CGPDFPage.h +++ b/Headers/CoreGraphics/CGPDFPage.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -40,7 +40,8 @@ typedef struct CGPDFPage* CGPDFPageRef; /* Constants */ -typedef enum CGPDFBox { +typedef enum CGPDFBox +{ kCGPDFMediaBox = 0, kCGPDFCropBox = 1, kCGPDFBleedBox = 2, diff --git a/Headers/CoreGraphics/CGPDFScanner.h b/Headers/CoreGraphics/CGPDFScanner.h index b370a14..74a3d2a 100644 --- a/Headers/CoreGraphics/CGPDFScanner.h +++ b/Headers/CoreGraphics/CGPDFScanner.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -56,7 +56,8 @@ bool CGPDFScannerPopArray(CGPDFScannerRef scanner, CGPDFArrayRef *value); bool CGPDFScannerPopBoolean(CGPDFScannerRef scanner, CGPDFBoolean *value); -bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, CGPDFDictionaryRef *value); +bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, + CGPDFDictionaryRef *value); bool CGPDFScannerPopInteger(CGPDFScannerRef scanner, CGPDFInteger *value); diff --git a/Headers/CoreGraphics/CGPDFStream.h b/Headers/CoreGraphics/CGPDFStream.h index f6a5d99..2f27468 100644 --- a/Headers/CoreGraphics/CGPDFStream.h +++ b/Headers/CoreGraphics/CGPDFStream.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -38,7 +38,8 @@ typedef struct CGPDFStream* CGPDFStreamRef; /* Constants */ -typedef enum CGPDFDataFormat { +typedef enum CGPDFDataFormat +{ CGPDFDataFormatRaw = 0, CGPDFDataFormatJPEGEncoded = 1, CGPDFDataFormatJPEG2000 = 2 diff --git a/Headers/CoreGraphics/CGPDFString.h b/Headers/CoreGraphics/CGPDFString.h index 50367c3..36d6fb5 100644 --- a/Headers/CoreGraphics/CGPDFString.h +++ b/Headers/CoreGraphics/CGPDFString.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 diff --git a/Headers/CoreGraphics/CGPSConverter.h b/Headers/CoreGraphics/CGPSConverter.h index 334b5ec..af50ef5 100644 --- a/Headers/CoreGraphics/CGPSConverter.h +++ b/Headers/CoreGraphics/CGPSConverter.h @@ -5,17 +5,17 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -54,15 +54,16 @@ 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; +typedef struct CGPSConverterCallbacks +{ + unsigned int version; + CGPSConverterBeginDocumentCallback beginDocument; + CGPSConverterEndDocumentCallback endDocument; + CGPSConverterBeginPageCallback beginPage; + CGPSConverterEndPageCallback endPage; + CGPSConverterProgressCallback noteProgress; + CGPSConverterMessageCallback noteMessage; + CGPSConverterReleaseInfoCallback releaseInfo; } CGPSConverterCallbacks; diff --git a/Headers/CoreGraphics/CGPath.h b/Headers/CoreGraphics/CGPath.h index f183ea7..2e51974 100644 --- a/Headers/CoreGraphics/CGPath.h +++ b/Headers/CoreGraphics/CGPath.h @@ -11,12 +11,12 @@ 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 @@ -30,7 +30,8 @@ /* Constants */ -typedef enum CGPathElementType { +typedef enum CGPathElementType +{ kCGPathElementMoveToPoint = 0, kCGPathElementAddLineToPoint = 1, kCGPathElementAddQuadCurveToPoint = 2, @@ -54,14 +55,16 @@ typedef CGMutablePath* CGMutablePathRef; typedef struct CGMutablePath* CGMutablePathRef; #endif -typedef struct CGPathElement { +typedef struct CGPathElement +{ CGPathElementType type; CGPoint *points; } CGPathElement; /* Callbacks */ -typedef void (*CGPathApplierFunction)(void *info, const CGPathElement *element); +typedef void (*CGPathApplierFunction)(void *info, + const CGPathElement *element); /* Functions */ @@ -86,9 +89,9 @@ CGRect CGPathGetPathBoundingBox(CGPathRef path); CGPoint CGPathGetCurrentPoint(CGPathRef path); bool CGPathContainsPoint( - CGPathRef path, - const CGAffineTransform *m, - CGPoint point, + CGPathRef path, + const CGAffineTransform *m, + CGPoint point, int eoFill ); @@ -182,8 +185,8 @@ void CGPathMoveToPoint( void CGPathCloseSubpath(CGMutablePathRef path); void CGPathAddEllipseInRect( - CGMutablePathRef path, - const CGAffineTransform *m, + CGMutablePathRef path, + const CGAffineTransform *m, CGRect rect ); diff --git a/Headers/CoreGraphics/CGPattern.h b/Headers/CoreGraphics/CGPattern.h index 4efd7b2..5f1cb55 100644 --- a/Headers/CoreGraphics/CGPattern.h +++ b/Headers/CoreGraphics/CGPattern.h @@ -11,12 +11,12 @@ 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 @@ -54,7 +54,8 @@ typedef void(*CGPatternDrawPatternCallback)(void *info, CGContextRef ctx); typedef void(*CGPatternReleaseInfoCallback)(void *info); -typedef struct CGPatternCallbacks { +typedef struct CGPatternCallbacks +{ unsigned int version; CGPatternDrawPatternCallback drawPattern; CGPatternReleaseInfoCallback releaseInfo; diff --git a/Headers/CoreGraphics/CGShading.h b/Headers/CoreGraphics/CGShading.h index a687dc7..7aecd7c 100644 --- a/Headers/CoreGraphics/CGShading.h +++ b/Headers/CoreGraphics/CGShading.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreGraphics/CoreGraphics.h b/Headers/CoreGraphics/CoreGraphics.h index 155f536..442a6c4 100644 --- a/Headers/CoreGraphics/CoreGraphics.h +++ b/Headers/CoreGraphics/CoreGraphics.h @@ -10,17 +10,17 @@ 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 diff --git a/Headers/CoreGraphics/OPPostScriptContext.h b/Headers/CoreGraphics/OPPostScriptContext.h index 436a630..48def31 100644 --- a/Headers/CoreGraphics/OPPostScriptContext.h +++ b/Headers/CoreGraphics/OPPostScriptContext.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreGraphics/OPSVGContext.h b/Headers/CoreGraphics/OPSVGContext.h index 07be836..2bfda35 100644 --- a/Headers/CoreGraphics/OPSVGContext.h +++ b/Headers/CoreGraphics/OPSVGContext.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreText/CTFont.h b/Headers/CoreText/CTFont.h index f6893d3..1ae7260 100644 --- a/Headers/CoreText/CTFont.h +++ b/Headers/CoreText/CTFont.h @@ -11,12 +11,12 @@ 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 @@ -90,13 +90,15 @@ extern const CFStringRef kCTFontFeatureSelectorNameKey; extern const CFStringRef kCTFontFeatureSelectorDefaultKey; extern const CFStringRef kCTFontFeatureSelectorSettingKey; -typedef enum { +typedef enum +{ kCTFontOptionsDefault = 0, kCTFontOptionsPreventAutoActivation = 1 << 0, kCTFontOptionsPreferSystemFont = 1 << 2, } CTFontOptions; -typedef enum { +typedef enum +{ kCTFontTableOptionNoOptions = 0, kCTFontTableOptionExcludeSynthetic = 1 << 0 } CTFontTableOptions; @@ -107,7 +109,8 @@ typedef enum { #define OP_TABLETAG(a,b,c,d) ((((int)d) << 24) | (((int)c) << 16) | (((int)b) << 8) | ((int)a)) #endif -typedef enum { +typedef enum +{ kCTFontTableBASE = OP_TABLETAG('B','A','S','E'), kCTFontTableCFF = OP_TABLETAG('C','F','F',' '), kCTFontTableDSIG = OP_TABLETAG('D','S','I','G'), @@ -163,7 +166,8 @@ typedef enum { kCTFontTableVmtx = OP_TABLETAG('v','m','t','x') } CTFontTableTag; -typedef enum { +typedef enum +{ kCTFontNoFontType = -1, kCTFontUserFontType = 0, kCTFontUserFixedPitchFontType = 1, diff --git a/Headers/CoreText/CTFontCollection.h b/Headers/CoreText/CTFontCollection.h index 24a55dd..085faf4 100644 --- a/Headers/CoreText/CTFontCollection.h +++ b/Headers/CoreText/CTFontCollection.h @@ -11,12 +11,12 @@ 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 @@ -57,9 +57,11 @@ CTFontCollectionRef CTFontCollectionCreateCopyWithFontDescriptors( CFDictionaryRef opts ); -CTFontCollectionRef CTFontCollectionCreateFromAvailableFonts(CFDictionaryRef opts); +CTFontCollectionRef CTFontCollectionCreateFromAvailableFonts( + CFDictionaryRef opts); -CFArrayRef CTFontCollectionCreateMatchingFontDescriptors(CTFontCollectionRef collection); +CFArrayRef CTFontCollectionCreateMatchingFontDescriptors( + CTFontCollectionRef collection); CFArrayRef CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback( CTFontCollectionRef collection, diff --git a/Headers/CoreText/CTFontDescriptor.h b/Headers/CoreText/CTFontDescriptor.h index bb5676e..8678e75 100644 --- a/Headers/CoreText/CTFontDescriptor.h +++ b/Headers/CoreText/CTFontDescriptor.h @@ -11,12 +11,12 @@ 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 @@ -62,13 +62,15 @@ extern const CFStringRef kCTFontFormatAttribute; extern const CFStringRef kCTFontRegistrationScopeAttribute; extern const CFStringRef kCTFontPriorityAttribute; -typedef enum { +typedef enum +{ kCTFontDefaultOrientation = 0, kCTFontHorizontalOrientation = 1, kCTFontVerticalOrientation = 2 } CTFontOrientation; -typedef enum { +typedef enum +{ kCTFontFormatUnrecognized = 0, kCTFontFormatOpenTypePostScript = 1, kCTFontFormatOpenTypeTrueType = 2, @@ -77,7 +79,8 @@ typedef enum { kCTFontFormatBitmap = 5 } CTFontFormat; -typedef enum { +typedef enum +{ kCTFontPrioritySystem = 10000, kCTFontPriorityNetwork = 20000, kCTFontPriorityComputer = 30000, @@ -93,8 +96,9 @@ CTFontDescriptorRef CTFontDescriptorCreateWithNameAndSize( CGFloat size ); -CTFontDescriptorRef CTFontDescriptorCreateWithAttributes(CFDictionaryRef attributes); - +CTFontDescriptorRef CTFontDescriptorCreateWithAttributes( + CFDictionaryRef attributes); + CTFontDescriptorRef CTFontDescriptorCreateCopyWithAttributes( CTFontDescriptorRef original, CFDictionaryRef attributes diff --git a/Headers/CoreText/CTFontManager.h b/Headers/CoreText/CTFontManager.h index 42829e0..cfbf0aa 100644 --- a/Headers/CoreText/CTFontManager.h +++ b/Headers/CoreText/CTFontManager.h @@ -11,17 +11,17 @@ 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 @@ -34,14 +34,16 @@ extern const CFStringRef kCTFontManagerBundleIdentifier; extern const CFStringRef kCTFontManagerRegisteredFontsChangedNotification; -typedef enum { +typedef enum +{ kCTFontManagerScopeNone = 0, kCTFontManagerScopeProcess = 1, kCTFontManagerScopeUser = 2, kCTFontManagerScopeSession = 3 } CTFontManagerScope; -typedef enum { +typedef enum +{ kCTFontManagerAutoActivationDefault = 0, kCTFontManagerAutoActivationDisabled = 1, kCTFontManagerAutoActivationEnabled = 2, @@ -99,8 +101,9 @@ bool CTFontManagerIsSupportedFont(CFURLRef fontURL); #if defined(__BLOCKS__) CFRunLoopSourceRef CTFontManagerCreateFontRequestRunLoopSource( - CFIndex sourceOrder, - CFArrayRef (^createMatchesCallback)(CFDictionaryRef requestAttributes, pid_t requestingProcess) + CFIndex sourceOrder, + CFArrayRef (^createMatchesCallback)(CFDictionaryRef requestAttributes, + pid_t requestingProcess) ); #endif diff --git a/Headers/CoreText/CTFontManagerErrors.h b/Headers/CoreText/CTFontManagerErrors.h index c4cc61c..5110cd2 100644 --- a/Headers/CoreText/CTFontManagerErrors.h +++ b/Headers/CoreText/CTFontManagerErrors.h @@ -11,12 +11,12 @@ 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 @@ -36,7 +36,8 @@ typedef CFIndex CTFontManagerError; extern const CFStringRef kCTFontManagerErrorDomain; extern const CFStringRef kCTFontManagerErrorFontURLsKey; -enum { +enum +{ kCTFontManagerErrorFileNotFound = 101, kCTFontManagerErrorInsufficientPermissions = 102, kCTFontManagerErrorUnrecognizedFormat = 103, @@ -44,7 +45,8 @@ enum { kCTFontManagerErrorAlreadyRegistered = 105, }; -enum { +enum +{ kCTFontManagerErrorNotRegistered = 201, kCTFontManagerErrorInUse = 202, kCTFontManagerErrorSystemRequired = 202, diff --git a/Headers/CoreText/CTFontTraits.h b/Headers/CoreText/CTFontTraits.h index 57e8ba3..34b869b 100644 --- a/Headers/CoreText/CTFontTraits.h +++ b/Headers/CoreText/CTFontTraits.h @@ -11,12 +11,12 @@ 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 @@ -34,11 +34,13 @@ extern const CFStringRef kCTFontWeightTrait; extern const CFStringRef kCTFontWidthTrait; extern const CFStringRef kCTFontSlantTrait; -enum { +enum +{ kCTFontClassMaskShift = 28 }; -typedef enum { +typedef enum +{ kCTFontItalicTrait = (1 << 0), kCTFontBoldTrait = (1 << 1), kCTFontExpandedTrait = (1 << 5), @@ -49,7 +51,8 @@ typedef enum { kCTFontClassMaskTrait = (15 << 28) } CTFontSymbolicTraits; -typedef enum { +typedef enum +{ kCTFontUnknownClass = (0 << 28), kCTFontOldStyleSerifsClass = (1 << 28), kCTFontTransitionalSerifsClass = (2 << 28), diff --git a/Headers/CoreText/CTFrame.h b/Headers/CoreText/CTFrame.h index 1c8759d..cbeb0f0 100644 --- a/Headers/CoreText/CTFrame.h +++ b/Headers/CoreText/CTFrame.h @@ -11,12 +11,12 @@ 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 @@ -43,7 +43,8 @@ typedef struct CTFrame* CTFrameRef; extern const CFStringRef kCTFrameProgressionAttributeName; -typedef enum { +typedef enum +{ kCTFrameProgressionTopToBottom = 0, kCTFrameProgressionRightToLeft = 1 } CTFrameProgression; diff --git a/Headers/CoreText/CTFramesetter.h b/Headers/CoreText/CTFramesetter.h index 1baab7e..a10c510 100644 --- a/Headers/CoreText/CTFramesetter.h +++ b/Headers/CoreText/CTFramesetter.h @@ -11,12 +11,12 @@ 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 @@ -44,7 +44,8 @@ typedef struct CTFramesetter* CTFramesetterRef; CFTypeID CTFramesetterGetTypeID(); -CTFramesetterRef CTFramesetterCreateWithAttributedString(CFAttributedStringRef string); +CTFramesetterRef CTFramesetterCreateWithAttributedString( + CFAttributedStringRef string); CTFrameRef CTFramesetterCreateFrame( CTFramesetterRef framesetter, diff --git a/Headers/CoreText/CTGlyphInfo.h b/Headers/CoreText/CTGlyphInfo.h index a03d021..7021ccd 100644 --- a/Headers/CoreText/CTGlyphInfo.h +++ b/Headers/CoreText/CTGlyphInfo.h @@ -11,12 +11,12 @@ 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 @@ -40,7 +40,8 @@ typedef struct CTGlyphInfo* CTGlyphInfoRef; /* Constants */ -typedef enum { +typedef enum +{ kCTIdentityMappingCharacterCollection = 0, kCTAdobeCNS1CharacterCollection = 1, kCTAdobeGB1CharacterCollection = 2, @@ -75,6 +76,7 @@ CFStringRef CTGlyphInfoGetGlyphName(CTGlyphInfoRef glyphInfo); CGFontIndex CTGlyphInfoGetCharacterIdentifier(CTGlyphInfoRef glyphInfo); -CTCharacterCollection CTGlyphInfoGetCharacterCollection(CTGlyphInfoRef glyphInfo); +CTCharacterCollection CTGlyphInfoGetCharacterCollection( + CTGlyphInfoRef glyphInfo); #endif diff --git a/Headers/CoreText/CTLine.h b/Headers/CoreText/CTLine.h index aa62ddb..5316534 100644 --- a/Headers/CoreText/CTLine.h +++ b/Headers/CoreText/CTLine.h @@ -11,12 +11,12 @@ 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 @@ -41,7 +41,8 @@ typedef struct CTLine* CTLineRef; /* Constants */ -typedef enum { +typedef enum +{ kCTLineTruncationStart = 0, kCTLineTruncationEnd = 1, kCTLineTruncationMiddle = 2 diff --git a/Headers/CoreText/CTParagraphStyle.h b/Headers/CoreText/CTParagraphStyle.h index 7e76697..ccfc368 100644 --- a/Headers/CoreText/CTParagraphStyle.h +++ b/Headers/CoreText/CTParagraphStyle.h @@ -11,12 +11,12 @@ 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 @@ -38,7 +38,8 @@ typedef struct CTParagraphStyle* CTParagraphStyleRef; /* Constants */ -typedef enum { +typedef enum +{ kCTLeftTextAlignment = 0, kCTRightTextAlignment = 1, kCTCenterTextAlignment = 2, @@ -46,7 +47,8 @@ typedef enum { kCTNaturalTextAlignment = 4 } CTTextAlignment; -typedef enum { +typedef enum +{ kCTLineBreakByWordWrapping = 0, kCTLineBreakByCharWrapping = 1, kCTLineBreakByClipping = 2, @@ -55,13 +57,15 @@ typedef enum { kCTLineBreakByTruncatingMiddle = 5 } CTLineBreakMode; -typedef enum { +typedef enum +{ kCTWritingDirectionNatural = -1, kCTWritingDirectionLeftToRight = 0, kCTWritingDirectionRightToLeft = 1 } CTWritingDirection; -typedef enum { +typedef enum +{ kCTParagraphStyleSpecifierAlignment = 0, kCTParagraphStyleSpecifierFirstLineHeadIndent = 1, kCTParagraphStyleSpecifierHeadIndent = 2, @@ -82,7 +86,8 @@ typedef enum { /* Data Types */ -typedef struct CTParagraphStyleSetting { +typedef struct CTParagraphStyleSetting +{ CTParagraphStyleSpecifier spec; size_t valueSize; const void *value; @@ -98,7 +103,8 @@ CTParagraphStyleRef CTParagraphStyleCreate( CFIndex settingCount ); -CTParagraphStyleRef CTParagraphStyleCreateCopy(CTParagraphStyleRef paragraphStyle); +CTParagraphStyleRef CTParagraphStyleCreateCopy(CTParagraphStyleRef + paragraphStyle); bool CTParagraphStyleGetValueForSpecifier( CTParagraphStyleRef paragraphStyle, diff --git a/Headers/CoreText/CTRun.h b/Headers/CoreText/CTRun.h index 1ffde6f..86c9df2 100644 --- a/Headers/CoreText/CTRun.h +++ b/Headers/CoreText/CTRun.h @@ -11,12 +11,12 @@ 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 @@ -41,7 +41,8 @@ typedef struct CTRun* CTRunRef; /* Constants */ -typedef enum { +typedef enum +{ kCTRunStatusNoStatus = 0, kCTRunStatusRightToLeft = (1 << 0), kCTRunStatusNonMonotonic = (1 << 1), @@ -49,7 +50,7 @@ typedef enum { } CTRunStatus; /* Functions */ - + CFIndex CTRunGetGlyphCount(CTRunRef run); CFDictionaryRef CTRunGetAttributes(CTRunRef run); diff --git a/Headers/CoreText/CTStringAttributes.h b/Headers/CoreText/CTStringAttributes.h index 83f5a4d..85bfbf9 100644 --- a/Headers/CoreText/CTStringAttributes.h +++ b/Headers/CoreText/CTStringAttributes.h @@ -11,12 +11,12 @@ 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 @@ -44,14 +44,16 @@ extern const CFStringRef kCTVerticalFormsAttributeName; extern const CFStringRef kCTGlyphInfoAttributeName; extern const CFStringRef kCTCharacterShapeAttributeName; -typedef enum { +typedef enum +{ kCTUnderlineStyleNone = 0, kCTUnderlineStyleSingle = 1, kCTUnderlineStyleThick = 2, kCTUnderlineStyleDouble = 9 } CTUnderlineStyle; -typedef enum { +typedef enum +{ kCTUnderlinePatternSolid = 0x0000, kCTUnderlinePatternDot = 0x0100, kCTUnderlinePatternDash = 0x0200, diff --git a/Headers/CoreText/CTTextTab.h b/Headers/CoreText/CTTextTab.h index 37e3aa5..9e5840e 100644 --- a/Headers/CoreText/CTTextTab.h +++ b/Headers/CoreText/CTTextTab.h @@ -11,12 +11,12 @@ 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 diff --git a/Headers/CoreText/CTTypesetter.h b/Headers/CoreText/CTTypesetter.h index 20cc8e6..d7e4312 100644 --- a/Headers/CoreText/CTTypesetter.h +++ b/Headers/CoreText/CTTypesetter.h @@ -11,12 +11,12 @@ 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 @@ -44,7 +44,8 @@ extern const CFStringRef kCTTypesetterOptionForcedEmbeddingLevel; /* Functions */ -CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef string); +CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef + string); CTTypesetterRef CTTypesetterCreateWithAttributedStringAndOptions( CFAttributedStringRef string, diff --git a/Headers/CoreText/CoreText.h b/Headers/CoreText/CoreText.h index c64d09b..78464fe 100644 --- a/Headers/CoreText/CoreText.h +++ b/Headers/CoreText/CoreText.h @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalGraphics/CGAffineTransform.m b/Source/OpalGraphics/CGAffineTransform.m index aa8a6c7..bd25de2 100644 --- a/Source/OpalGraphics/CGAffineTransform.m +++ b/Source/OpalGraphics/CGAffineTransform.m @@ -11,12 +11,12 @@ 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 @@ -51,10 +51,11 @@ CGAffineTransform CGAffineTransformInvert(CGAffineTransform t) CGFloat det; det = t.a * t.d - t.b *t.c; - if (det == 0) { - NSLog(@"CGAffineTransformInvert: Cannot invert matrix, determinant is 0"); - return t; - } + if (det == 0) + { + NSLog(@"CGAffineTransformInvert: Cannot invert matrix, determinant is 0"); + return t; + } inv.a = t.d / det; inv.b = -t.b / det; @@ -69,13 +70,14 @@ CGAffineTransform CGAffineTransformInvert(CGAffineTransform t) /** * Returns the smallest rectangle which contains the four supplied points. */ -static CGRect make_bounding_rect(CGPoint p1, CGPoint p2, CGPoint p3, CGPoint p4) +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)); } @@ -86,11 +88,11 @@ CGRect CGRectApplyAffineTransform(CGRect rect, CGAffineTransform t) 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); } diff --git a/Source/OpalGraphics/CGBitmapContext.m b/Source/OpalGraphics/CGBitmapContext.m index 683c9c9..40a1f09 100644 --- a/Source/OpalGraphics/CGBitmapContext.m +++ b/Source/OpalGraphics/CGBitmapContext.m @@ -1,29 +1,29 @@ /** CGBitmapContext - + C Interface to graphics drawing library - + Copyright (C) 2009 Free Software Foundation, Inc. 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" +#include "CGContext-private.h" #include "CGImage-private.h" #import "OPImageConversion.h" @@ -45,23 +45,23 @@ @interface CGBitmapContext : CGContext /** * Creates a bitmap editing context. Since cairo only supports drawing in a few formats, - * usually we'll need two memory buffers, one for cairo to draw in and one for the user to + * usually we'll need two memory buffers, one for cairo to draw in and one for the user to * read from. */ - (id) initWithSurface: (cairo_surface_t *)target -isCairoDrawingIntoUserBuffer: (BOOL)isCairoDrawingIntoUserBuffer - userBufferColorspace: (CGColorSpaceRef)colorspace - userBufferBitsPerComponent: (size_t)userBufferBitsPerComponent - userBufferBytesPerRow: (size_t)userBufferBytesPerRow - userBufferBitmapInfo: (CGBitmapInfo)bitmapInfo - userBufferReleaseInfo: (void*)i - userBuffer: (void*)userBuffer - releaseCallback: (CGBitmapContextReleaseDataCallback)releaseCallback; + isCairoDrawingIntoUserBuffer: (BOOL)isCairoDrawingIntoUserBuffer + userBufferColorspace: (CGColorSpaceRef)colorspace + userBufferBitsPerComponent: (size_t)userBufferBitsPerComponent + userBufferBytesPerRow: (size_t)userBufferBytesPerRow + userBufferBitmapInfo: (CGBitmapInfo)bitmapInfo + userBufferReleaseInfo: (void*)i + userBuffer: (void*)userBuffer + releaseCallback: (CGBitmapContextReleaseDataCallback)releaseCallback; @end @implementation CGBitmapContext -/* +/* ARGB => Alpha First & Big Endian BGRA => Alpha First & Little Endian RGBA => Alpha Last & Big Endian @@ -69,9 +69,9 @@ @implementation CGBitmapContext */ static BOOL isFormatNativelySupportedByCairo( - CGBitmapInfo info, - CGColorSpaceRef cs, - size_t bitsPerComponent, + CGBitmapInfo info, + CGColorSpaceRef cs, + size_t bitsPerComponent, size_t width, size_t bytesPerRow, cairo_format_t *outFormat) @@ -82,15 +82,15 @@ static BOOL isFormatNativelySupportedByCairo( { return NO; } - + // NOTE: kCGBitmapByteOrderDefault means big-endian (a.k.a unpacked) // cairo can only draw into native-endian integer-packed pixels const int order = info & kCGBitmapByteOrderMask; if (!((NSHostByteOrder() == NS_LittleEndian) && (order == kCGBitmapByteOrder32Little)) - && !((NSHostByteOrder() == NS_BigEndian) - && (order == kCGBitmapByteOrder32Big - || order == kCGBitmapByteOrderDefault))) + && !((NSHostByteOrder() == NS_BigEndian) + && (order == kCGBitmapByteOrder32Big + || order == kCGBitmapByteOrderDefault))) { return NO; } @@ -105,22 +105,22 @@ static BOOL isFormatNativelySupportedByCairo( && model == kCGColorSpaceModelRGB && alpha == kCGImageAlphaNoneSkipFirst) { - format = CAIRO_FORMAT_RGB24; + format = CAIRO_FORMAT_RGB24; } else if (bitsPerComponent == 8 - && numComps == 3 - && model == kCGColorSpaceModelRGB - && (alpha == kCGImageAlphaPremultipliedFirst)) + && numComps == 3 + && model == kCGColorSpaceModelRGB + && (alpha == kCGImageAlphaPremultipliedFirst)) { - format = CAIRO_FORMAT_ARGB32; + format = CAIRO_FORMAT_ARGB32; } else if (bitsPerComponent == 8 && alpha == kCGImageAlphaOnly) { - format = CAIRO_FORMAT_A8; + format = CAIRO_FORMAT_A8; } else if (bitsPerComponent == 1 && alpha == kCGImageAlphaOnly) { - format = CAIRO_FORMAT_A1; + format = CAIRO_FORMAT_A1; } else { @@ -130,31 +130,31 @@ static BOOL isFormatNativelySupportedByCairo( // Now that we have the format we're going to use, check that the stride // is acceptable to cairo. if (cairo_format_stride_for_width(format, width) != bytesPerRow) - { - return NO; - } - - *outFormat = format; + { + return NO; + } + + *outFormat = format; return YES; } - (id) initWithSurface: (cairo_surface_t *)target -isCairoDrawingIntoUserBuffer: (BOOL)isIntoUserBuffer - userBufferColorspace: (CGColorSpaceRef)colorspace - userBufferBitsPerComponent: (size_t)bitsPerComponent - userBufferBytesPerRow: (size_t)bytesPerRow - userBufferBitmapInfo: (CGBitmapInfo)bitmapInfo - userBufferReleaseInfo: (void*)i - userBuffer: (void*)aUserBuffer - releaseCallback: (CGBitmapContextReleaseDataCallback)releaseCallback + isCairoDrawingIntoUserBuffer: (BOOL)isIntoUserBuffer + userBufferColorspace: (CGColorSpaceRef)colorspace + userBufferBitsPerComponent: (size_t)bitsPerComponent + userBufferBytesPerRow: (size_t)bytesPerRow + userBufferBitmapInfo: (CGBitmapInfo)bitmapInfo + userBufferReleaseInfo: (void*)i + userBuffer: (void*)aUserBuffer + 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; - } + { + return nil; + } self->isCairoDrawingIntoUserBuffer = isIntoUserBuffer; self->cs = CGColorSpaceRetain(colorspace); self->userBufferBitsPerComponent = bitsPerComponent; @@ -171,10 +171,10 @@ - (void) dealloc CGContextFlush(self); CGColorSpaceRelease(cs); if (cb) - { - cb(releaseInfo, userBuffer); - } - [super dealloc]; + { + cb(releaseInfo, userBuffer); + } + [super dealloc]; } - (void*) data @@ -182,36 +182,38 @@ - (void*) data CGContextFlush(self); if (!isCairoDrawingIntoUserBuffer) - { - cairo_surface_t *srcCairoSurface = cairo_get_target(self->ct); - const unsigned char *srcData = cairo_image_surface_get_data(srcCairoSurface); - const size_t srcWidth = CGBitmapContextGetWidth(self); - const size_t srcHeight = CGBitmapContextGetHeight(self); - const size_t srcBitsPerComponent = 8; - const size_t srcBitsPerPixel = 32; - const size_t srcBytesPerRow = cairo_format_stride_for_width(cairo_image_surface_get_format(srcCairoSurface), srcWidth); - const CGBitmapInfo srcBitmapInfo = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; - const CGColorSpaceRef srcColorSpace = CGColorSpaceCreateDeviceRGB(); - const CGColorRenderingIntent srcIntent = kCGRenderingIntentDefault; - - unsigned char *dstData = userBuffer; - const size_t dstBitsPerComponent = CGBitmapContextGetBitsPerComponent(self); - const size_t dstBitsPerPixel = CGBitmapContextGetBitsPerPixel(self); - const size_t dstBytesPerRow = CGBitmapContextGetBytesPerRow(self); - - CGBitmapInfo dstBitmapInfo = CGBitmapContextGetBitmapInfo(self); - const CGColorSpaceRef dstColorSpace = CGBitmapContextGetColorSpace(self); - - OPImageConvert( - dstData, srcData, - srcWidth, srcHeight, - dstBitsPerComponent, srcBitsPerComponent, - dstBitsPerPixel, srcBitsPerPixel, - dstBytesPerRow, srcBytesPerRow, - dstBitmapInfo, srcBitmapInfo, - dstColorSpace, srcColorSpace, - srcIntent); - } + { + cairo_surface_t *srcCairoSurface = cairo_get_target(self->ct); + const unsigned char *srcData = cairo_image_surface_get_data(srcCairoSurface); + const size_t srcWidth = CGBitmapContextGetWidth(self); + const size_t srcHeight = CGBitmapContextGetHeight(self); + const size_t srcBitsPerComponent = 8; + const size_t srcBitsPerPixel = 32; + const size_t srcBytesPerRow = cairo_format_stride_for_width( + cairo_image_surface_get_format(srcCairoSurface), srcWidth); + const CGBitmapInfo srcBitmapInfo = kCGBitmapByteOrder32Host | + kCGImageAlphaPremultipliedFirst; + const CGColorSpaceRef srcColorSpace = CGColorSpaceCreateDeviceRGB(); + const CGColorRenderingIntent srcIntent = kCGRenderingIntentDefault; + + unsigned char *dstData = userBuffer; + const size_t dstBitsPerComponent = CGBitmapContextGetBitsPerComponent(self); + const size_t dstBitsPerPixel = CGBitmapContextGetBitsPerPixel(self); + const size_t dstBytesPerRow = CGBitmapContextGetBytesPerRow(self); + + CGBitmapInfo dstBitmapInfo = CGBitmapContextGetBitmapInfo(self); + const CGColorSpaceRef dstColorSpace = CGBitmapContextGetColorSpace(self); + + OPImageConvert( + dstData, srcData, + srcWidth, srcHeight, + dstBitsPerComponent, srcBitsPerComponent, + dstBitsPerPixel, srcBitsPerPixel, + dstBytesPerRow, srcBytesPerRow, + dstBitmapInfo, srcBitmapInfo, + dstColorSpace, srcColorSpace, + srcIntent); + } return userBuffer; } @@ -230,8 +232,8 @@ CGContextRef CGBitmapContextCreate( { OPLOGCALL("ctx, %p, %d, %d, %d, %d, , ", data, width, height, bitsPerComponent, bytesPerRow) - CGContextRef r = CGBitmapContextCreateWithData(data, width, height, - bitsPerComponent, bytesPerRow, cs, info, NULL, NULL); + CGContextRef r = CGBitmapContextCreateWithData(data, width, height, + bitsPerComponent, bytesPerRow, cs, info, NULL, NULL); OPRESTORELOGGING() return r; } @@ -248,9 +250,9 @@ static void checkSurf(cairo_surface_t *surf) const char *statusString = cairo_status_to_string(status); if (CAIRO_STATUS_SUCCESS != status) - { - printf("surf status: %s", statusString); - } + { + printf("surf status: %s", statusString); + } } CGContextRef CGBitmapContextCreateWithData( @@ -268,37 +270,40 @@ CGContextRef CGBitmapContextCreateWithData( ", ", data, width, height, bitsPerComponent, bytesPerRow) cairo_format_t format = CAIRO_FORMAT_INVALID; - cairo_surface_t *surf; + cairo_surface_t *surf; // Create the user requested buffer if (data == NULL) - { + { data = calloc(height * bytesPerRow, 1); // FIXME: checks callback = (CGBitmapContextReleaseDataCallback)OPBitmapDataReleaseCallback; - } + } // Set up the user-requested surface - const BOOL nativeCairoSupport = isFormatNativelySupportedByCairo(info, cs, bitsPerComponent, width, bytesPerRow, &format); + const BOOL nativeCairoSupport = isFormatNativelySupportedByCairo(info, cs, + bitsPerComponent, width, bytesPerRow, &format); if (nativeCairoSupport) - { - // Cairo can draw directly into the buffer format the caller provided or requested - surf = cairo_image_surface_create_for_data(data, format, width, height, bytesPerRow); + { + // Cairo can draw directly into the buffer format the caller provided or requested + surf = cairo_image_surface_create_for_data(data, format, width, height, + bytesPerRow); - NSDebugLLog(@"Opal", @"CGBitmapContext: using native drawing"); - } + NSDebugLLog(@"Opal", @"CGBitmapContext: using native drawing"); + } else - { - // Cairo can't draw into the buffer the user provided or requested. Allocate a temporary - // ARGB32 buffer. - format = CAIRO_FORMAT_ARGB32; - - const size_t cairoBytesPerRow = cairo_format_stride_for_width(format, width); - void *cairoData = calloc(height * cairoBytesPerRow, 1); - surf = cairo_image_surface_create_for_data(cairoData, format, width, height, cairoBytesPerRow); - - NSDebugLLog(@"Opal", @"CGBitmapContext: using drawing through buffer"); - } - + { + // Cairo can't draw into the buffer the user provided or requested. Allocate a temporary + // ARGB32 buffer. + format = CAIRO_FORMAT_ARGB32; + + const size_t cairoBytesPerRow = cairo_format_stride_for_width(format, width); + void *cairoData = calloc(height * cairoBytesPerRow, 1); + surf = cairo_image_surface_create_for_data(cairoData, format, width, height, + cairoBytesPerRow); + + NSDebugLLog(@"Opal", @"CGBitmapContext: using drawing through buffer"); + } + checkSurf(surf); OPRESTORELOGGING() @@ -308,99 +313,100 @@ CGContextRef CGBitmapContextCreateWithData( userBufferBitsPerComponent: bitsPerComponent userBufferBytesPerRow: bytesPerRow userBufferBitmapInfo: info - userBufferReleaseInfo: releaseInfo + userBufferReleaseInfo: releaseInfo userBuffer: data - releaseCallback: callback]; + releaseCallback: callback]; } CGImageAlphaInfo CGBitmapContextGetAlphaInfo(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return ((CGBitmapContext *)ctx)->userBufferBitmapInfo & kCGBitmapAlphaInfoMask; - } + { + return ((CGBitmapContext *)ctx)->userBufferBitmapInfo & kCGBitmapAlphaInfoMask; + } return kCGImageAlphaNone; } CGBitmapInfo CGBitmapContextGetBitmapInfo(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return ((CGBitmapContext *)ctx)->userBufferBitmapInfo; - } + { + return ((CGBitmapContext *)ctx)->userBufferBitmapInfo; + } return 0; } size_t CGBitmapContextGetBitsPerComponent(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return ((CGBitmapContext *)ctx)->userBufferBitsPerComponent; - } + { + return ((CGBitmapContext *)ctx)->userBufferBitsPerComponent; + } return 0; } size_t CGBitmapContextGetBitsPerPixel(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - size_t colorComps = CGColorSpaceGetNumberOfComponents(((CGBitmapContext *)ctx)->cs); + { + size_t colorComps = CGColorSpaceGetNumberOfComponents((( + CGBitmapContext *)ctx)->cs); size_t alphaComps = 0; if (CGBitmapContextGetAlphaInfo(ctx) != kCGImageAlphaNone) - { - alphaComps = 1; - } - + { + alphaComps = 1; + } + size_t bitsPerComp = CGBitmapContextGetBitsPerComponent(ctx); - return bitsPerComp * (colorComps + alphaComps); - } + return bitsPerComp * (colorComps + alphaComps); + } return 0; } size_t CGBitmapContextGetBytesPerRow(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return ((CGBitmapContext *)ctx)->userBufferBytesPerRow; - } + { + return ((CGBitmapContext *)ctx)->userBufferBytesPerRow; + } return 0; } CGColorSpaceRef CGBitmapContextGetColorSpace(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return ((CGBitmapContext*)ctx)->cs; - } + { + return ((CGBitmapContext*)ctx)->cs; + } return nil; } void *CGBitmapContextGetData(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return [(CGBitmapContext *)ctx data]; - } + { + return [(CGBitmapContext *)ctx data]; + } return 0; } size_t CGBitmapContextGetHeight(CGContextRef ctx) { if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - return cairo_image_surface_get_height(cairo_get_target(ctx->ct)); - } + { + 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 cairo_image_surface_get_width(cairo_get_target(ctx->ct)); + } return 0; } @@ -413,35 +419,35 @@ CGImageRef CGBitmapContextCreateImage(CGContextRef ctx) { OPLOGCALL("ctx") if ([ctx isKindOfClass: [CGBitmapContext class]]) - { - // FIXME: Use the cairo format - - 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 - ); - - img->surf = cairo_surface_reference(cairo_get_target(ctx->ct)); - CGDataProviderRelease(dp); - OPRESTORELOGGING() - return img; - } + { + // FIXME: Use the cairo format + + 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 + ); + + img->surf = cairo_surface_reference(cairo_get_target(ctx->ct)); + CGDataProviderRelease(dp); + OPRESTORELOGGING() + return img; + } OPRESTORELOGGING() return nil; } diff --git a/Source/OpalGraphics/CGColor-private.h b/Source/OpalGraphics/CGColor-private.h index 2e97611..1ba9880 100644 --- a/Source/OpalGraphics/CGColor-private.h +++ b/Source/OpalGraphics/CGColor-private.h @@ -11,12 +11,12 @@ 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 @@ -32,9 +32,11 @@ CGPatternRef pattern; } -- (CGColor*) transformToColorSpace: (CGColorSpaceRef)space withRenderingIntent: (CGColorRenderingIntent)intent; +- (CGColor*) transformToColorSpace: (CGColorSpaceRef)space withRenderingIntent +: (CGColorRenderingIntent)intent; @end -CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, CGColorRenderingIntent intent); +CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, + CGColorRenderingIntent intent); diff --git a/Source/OpalGraphics/CGColor.m b/Source/OpalGraphics/CGColor.m index 6902381..83916ac 100644 --- a/Source/OpalGraphics/CGColor.m +++ b/Source/OpalGraphics/CGColor.m @@ -11,12 +11,12 @@ 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 @@ -40,7 +40,8 @@ @implementation CGColor -- (id) initWithColorSpace: (CGColorSpaceRef)cs components: (const CGFloat*)components +- (id) initWithColorSpace: (CGColorSpaceRef)cs components: + (const CGFloat*)components { self = [super init]; if (nil == self) return nil; @@ -48,16 +49,17 @@ - (id) initWithColorSpace: (CGColorSpaceRef)cs components: (const CGFloat*)compo size_t nc, i; nc = CGColorSpaceGetNumberOfComponents(cs); self->comps = malloc((nc+1)*sizeof(CGFloat)); - if (NULL == self->comps) { - NSLog(@"malloc failed"); - [self release]; - return nil; - } + 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; + self->comps[i] = components[i]; + return self; } - (void) dealloc @@ -65,27 +67,29 @@ - (void) dealloc CGColorSpaceRelease(self->cspace); CGPatternRelease(self->pattern); free(self->comps); - [super dealloc]; + [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; - } + + 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 +- (CGColor*) transformToColorSpace: (CGColorSpaceRef)destSpace + withRenderingIntent: (CGColorRenderingIntent)intent { CGColorSpaceRef sourceSpace = CGColorGetColorSpace(self); @@ -96,9 +100,9 @@ - (CGColor*) transformToColorSpace: (CGColorSpaceRef)destSpace withRenderingInte float tranformedComps[CGColorSpaceGetNumberOfComponents(destSpace) + 1]; for (size_t i=0; i < CGColorSpaceGetNumberOfComponents(sourceSpace) + 1; i++) - { - originalComps[i] = comps[i]; - } + { + originalComps[i] = comps[i]; + } OPImageFormat sourceFormat; sourceFormat.compFormat = kOPComponentFormatFloat32bpc; @@ -117,35 +121,39 @@ - (CGColor*) transformToColorSpace: (CGColorSpaceRef)destSpace withRenderingInte destFormat.needs32Swap = false; id xform = [sourceSpace colorTransformTo: destSpace - sourceFormat: sourceFormat - destinationFormat: destFormat - renderingIntent: intent - pixelCount: 1]; + sourceFormat: sourceFormat + destinationFormat: destFormat + renderingIntent: intent + pixelCount: 1]; [xform transformPixelData: (const unsigned char *)originalComps output: (unsigned char *)tranformedComps]; - - CGFloat cgfloatTransformedComps[CGColorSpaceGetNumberOfComponents(destSpace) + 1]; + + CGFloat cgfloatTransformedComps[CGColorSpaceGetNumberOfComponents( + destSpace) + 1]; for (size_t i=0; i < CGColorSpaceGetNumberOfComponents(destSpace) + 1; i++) - { - cgfloatTransformedComps[i] = tranformedComps[i]; - } - // FIXME: release xform? + { + cgfloatTransformedComps[i] = tranformedComps[i]; + } +// FIXME: release xform? - return [[[CGColor alloc] initWithColorSpace: destSpace components: cgfloatTransformedComps] autorelease]; + return [[[CGColor alloc] initWithColorSpace: destSpace components: + cgfloatTransformedComps] autorelease]; } @end -CGColorRef CGColorCreate(CGColorSpaceRef colorspace, const CGFloat components[]) +CGColorRef CGColorCreate(CGColorSpaceRef colorspace, + const CGFloat components[]) { - CGColor *clr = [[CGColor alloc] initWithColorSpace: colorspace components: components]; + CGColor *clr = [[CGColor alloc] initWithColorSpace: colorspace components: + components]; return clr; } CFTypeID CGColorGetTypeID() { - return (CFTypeID)[CGColor class]; + return (CFTypeID)[CGColor class]; } CGColorRef CGColorRetain(CGColorRef clr) @@ -244,29 +252,29 @@ CGColorSpaceRef CGColorGetColorSpace(CGColorRef clr) CGColorRef CGColorGetConstantColor(CFStringRef name) { if ([name isEqual: kCGColorWhite]) - { - if (nil == _whiteColor) { - _whiteColor = CGColorCreateGenericGray(1, 1); + if (nil == _whiteColor) + { + _whiteColor = CGColorCreateGenericGray(1, 1); + } + return _whiteColor; } - return _whiteColor; - } else if ([name isEqual: kCGColorBlack]) - { - if (nil == _blackColor) { - _blackColor = CGColorCreateGenericGray(0, 1); + if (nil == _blackColor) + { + _blackColor = CGColorCreateGenericGray(0, 1); + } + return _blackColor; } - return _blackColor; - } else if ([name isEqual: kCGColorClear]) - { - if (nil == _clearColor) { - _clearColor = CGColorCreateGenericGray(0, 0); + if (nil == _clearColor) + { + _clearColor = CGColorCreateGenericGray(0, 0); + } + return _clearColor; } - return _clearColor; - } return nil; } @@ -280,7 +288,8 @@ CGPatternRef CGColorGetPattern(CGColorRef clr) return clr->pattern; } -CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, CGColorRenderingIntent intent) +CGColorRef OPColorGetTransformedToSpace(CGColorRef clr, CGColorSpaceRef space, + CGColorRenderingIntent intent) { return [clr transformToColorSpace: space withRenderingIntent: intent]; } diff --git a/Source/OpalGraphics/CGColorSpace-private.h b/Source/OpalGraphics/CGColorSpace-private.h index d150a85..ebb0051 100644 --- a/Source/OpalGraphics/CGColorSpace-private.h +++ b/Source/OpalGraphics/CGColorSpace-private.h @@ -11,12 +11,12 @@ 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 @@ -36,7 +36,7 @@ @end -/** +/** * Abstract superclass for color spaces. */ @protocol CGColorSpace @@ -72,10 +72,10 @@ - (size_t) numberOfComponents; - (id) colorTransformTo: (id)aColorSpace - sourceFormat: (OPImageFormat)aSourceFormat - destinationFormat: (OPImageFormat)aDestFormat - renderingIntent: (CGColorRenderingIntent)anIntent - pixelCount: (size_t)aPixelCount; + sourceFormat: (OPImageFormat)aSourceFormat + destinationFormat: (OPImageFormat)aDestFormat + renderingIntent: (CGColorRenderingIntent)anIntent + pixelCount: (size_t)aPixelCount; @end diff --git a/Source/OpalGraphics/CGColorSpace.m b/Source/OpalGraphics/CGColorSpace.m index d91c0c3..c0d50eb 100644 --- a/Source/OpalGraphics/CGColorSpace.m +++ b/Source/OpalGraphics/CGColorSpace.m @@ -13,12 +13,12 @@ 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 @@ -34,10 +34,12 @@ const CFStringRef kCGColorSpaceGenericGray = @"kCGColorSpaceGenericGray"; const CFStringRef kCGColorSpaceGenericRGB = @"kCGColorSpaceGenericRGB"; const CFStringRef kCGColorSpaceGenericCMYK = @"kCGColorSpaceGenericCMYK"; -const CFStringRef kCGColorSpaceGenericRGBLinear = @"kCGColorSpaceGenericRGBLinear"; +const CFStringRef kCGColorSpaceGenericRGBLinear = + @"kCGColorSpaceGenericRGBLinear"; const CFStringRef kCGColorSpaceAdobeRGB1998 = @"kCGColorSpaceAdobeRGB1998"; const CFStringRef kCGColorSpaceSRGB = @"kCGColorSpaceSRGB"; -const CFStringRef kCGColorSpaceGenericGrayGamma2_2 = @"kCGColorSpaceGenericGrayGamma2_2"; +const CFStringRef kCGColorSpaceGenericGrayGamma2_2 = + @"kCGColorSpaceGenericGrayGamma2_2"; /** @@ -96,9 +98,9 @@ CGColorSpaceRef CGColorSpaceCreateCalibratedGray( CGFloat gamma) { return [[OPColorSpaceClass() alloc] - initWithCalibratedGrayWithWhitePoint: whitePoint - blackPoint: blackPoint - gamma: gamma]; + initWithCalibratedGrayWithWhitePoint: whitePoint + blackPoint: blackPoint + gamma: gamma]; } @@ -108,11 +110,11 @@ CGColorSpaceRef CGColorSpaceCreateCalibratedRGB( const CGFloat *gamma, const CGFloat *matrix) { - return [[OPColorSpaceClass() alloc] - initWithCalibratedRGBWithWhitePoint: whitePoint - blackPoint: blackPoint - gamma: gamma - matrix: matrix]; + return [[OPColorSpaceClass() alloc] + initWithCalibratedRGBWithWhitePoint: whitePoint + blackPoint: blackPoint + gamma: gamma + matrix: matrix]; } CGColorSpaceRef CGColorSpaceCreateDeviceCMYK() @@ -137,9 +139,9 @@ CGColorSpaceRef CGColorSpaceCreateICCBased( CGColorSpaceRef alternateSpace) { return [[OPColorSpaceClass() alloc] initICCBasedWithComponents: nComponents - range: range - profile: profile - alternateSpace: alternateSpace]; + range: range + profile: profile + alternateSpace: alternateSpace]; } CGColorSpaceRef CGColorSpaceCreateIndexed( @@ -150,7 +152,7 @@ CGColorSpaceRef CGColorSpaceCreateIndexed( return [[OPColorSpaceIndexed alloc] initWithBaseSpace: baseSpace lastIndex: lastIndex colorTable: colorTable]; -} +} CGColorSpaceRef CGColorSpaceCreateLab( const CGFloat *whitePoint, @@ -158,8 +160,8 @@ CGColorSpaceRef CGColorSpaceCreateLab( const CGFloat *range) { return [[OPColorSpaceClass() alloc] initLabWithWhitePoint: whitePoint - blackPoint: blackPoint - range: range]; + blackPoint: blackPoint + range: range]; } CGColorSpaceRef CGColorSpaceCreatePattern(CGColorSpaceRef baseSpace) @@ -176,46 +178,47 @@ CGColorSpaceRef CGColorSpaceCreateWithICCProfile(CFDataRef data) CGColorSpaceRef CGColorSpaceCreateWithName(CFStringRef name) { if ([name isEqualToString: kCGColorSpaceGenericGray]) - { - return [[OPColorSpaceClass() colorSpaceGenericGray] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceGenericGray] retain]; + } else if ([name isEqualToString: kCGColorSpaceGenericRGB]) - { - return [[OPColorSpaceClass() colorSpaceGenericRGB] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceGenericRGB] retain]; + } else if ([name isEqualToString: kCGColorSpaceGenericCMYK]) - { - return [[OPColorSpaceClass() colorSpaceGenericCMYK] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceGenericCMYK] retain]; + } else if ([name isEqualToString: kCGColorSpaceGenericRGBLinear]) - { - return [[OPColorSpaceClass() colorSpaceGenericRGBLinear] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceGenericRGBLinear] retain]; + } else if ([name isEqualToString: kCGColorSpaceAdobeRGB1998]) - { - return [[OPColorSpaceClass() colorSpaceAdobeRGB1998] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceAdobeRGB1998] retain]; + } else if ([name isEqualToString: kCGColorSpaceSRGB]) - { - return [[OPColorSpaceClass() colorSpaceSRGB] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceSRGB] retain]; + } else if ([name isEqualToString: kCGColorSpaceGenericGrayGamma2_2]) - { - return [[OPColorSpaceClass() colorSpaceGenericGrayGamma2_2] retain]; - } + { + return [[OPColorSpaceClass() colorSpaceGenericGrayGamma2_2] retain]; + } return nil; } CGColorSpaceRef CGColorSpaceCreateWithPlatformColorSpace( void *platformColorSpace) { - return [[OPColorSpaceClass() alloc] initWithPlatformColorSpace: platformColorSpace]; + return [[OPColorSpaceClass() alloc] initWithPlatformColorSpace: + platformColorSpace]; } CGColorSpaceRef CGColorSpaceGetBaseColorSpace(CGColorSpaceRef cs) { // FIXME: fail silently on non-indexed space? - return [(OPColorSpaceIndexed*)cs baseColorSpace]; + return [(OPColorSpaceIndexed*)cs baseColorSpace]; } void CGColorSpaceGetColorTable(CGColorSpaceRef cs, unsigned char *table) @@ -242,7 +245,7 @@ size_t CGColorSpaceGetNumberOfComponents(CGColorSpaceRef cs) CFTypeID CGColorSpaceGetTypeID() { - return (CFTypeID)OPColorSpaceClass(); + return (CFTypeID)OPColorSpaceClass(); } CGColorSpaceRef CGColorSpaceRetain(CGColorSpaceRef cs) diff --git a/Source/OpalGraphics/CGContext+GState.m b/Source/OpalGraphics/CGContext+GState.m index 2be3c2f..f92c71d 100644 --- a/Source/OpalGraphics/CGContext+GState.m +++ b/Source/OpalGraphics/CGContext+GState.m @@ -62,10 +62,10 @@ - (id) initWithContext: (CGContext *)ctx; if (status != CAIRO_STATUS_SUCCESS) { /* - Due to an interesting programming concept in cairo this does not - mean that an error has occured. It may as well just be that the - old path had no elements. - At least in cairo 1.4.10 (See file cairo-path.c, line 379). + Due to an interesting programming concept in cairo this does not + mean that an error has occured. It may as well just be that the + old path had no elements. + At least in cairo 1.4.10 (See file cairo-path.c, line 379). */ // NSLog(@"Cairo status '%s' in copy path", cairo_status_to_string(status)); } @@ -84,14 +84,14 @@ - (id) initWithContext: (CGContext *)ctx; dashes_count = cairo_get_dash_count(aCairo); if (dashes_count > 0) - { - dashes = malloc(dashes_count); - - if (dashes != NULL) - { - cairo_get_dash(aCairo, dashes, &dashes_offset); - } - } + { + dashes = malloc(dashes_count); + + if (dashes != NULL) + { + cairo_get_dash(aCairo, dashes, &dashes_offset); + } + } cliprects = cairo_copy_clip_rectangle_list(aCairo); // opal additions @@ -123,9 +123,9 @@ - (void) applyToContext: (CGContext *)ctx status = cairo_status(aCairo); if (status != CAIRO_STATUS_SUCCESS) - { - NSLog(@"Cairo status '%s' in set matrix", cairo_status_to_string(status)); - } + { + NSLog(@"Cairo status '%s' in set matrix", cairo_status_to_string(status)); + } // next restore the clip rects, since setting the clip involves // setting the path. @@ -133,27 +133,27 @@ - (void) applyToContext: (CGContext *)ctx cairo_new_path(aCairo); if (cliprects != NULL && cliprects->status == CAIRO_STATUS_SUCCESS) - { - for (int i=0; inum_rectangles; i++) { - cairo_rectangle_t rect = cliprects->rectangles[i]; - - cairo_rectangle(aCairo, rect.x, rect.y, rect.width, rect.height); + for (int i=0; inum_rectangles; i++) + { + cairo_rectangle_t rect = cliprects->rectangles[i]; + + cairo_rectangle(aCairo, rect.x, rect.y, rect.width, rect.height); + } + cairo_clip(aCairo); + + status = cairo_status(aCairo); + if (status != CAIRO_STATUS_SUCCESS) + { + NSLog(@"Cairo status '%s' in restore clip", cairo_status_to_string(status)); + } } - cairo_clip(aCairo); - - status = cairo_status(aCairo); - if (status != CAIRO_STATUS_SUCCESS) - { - NSLog(@"Cairo status '%s' in restore clip", cairo_status_to_string(status)); - } - } cairo_new_path(aCairo); if (path->status == CAIRO_STATUS_SUCCESS) - { - cairo_append_path(aCairo, path); - } + { + cairo_append_path(aCairo, path); + } cairo_set_operator(aCairo, op); cairo_set_source(aCairo, pattern); diff --git a/Source/OpalGraphics/CGContext-private.h b/Source/OpalGraphics/CGContext-private.h index 518a7f2..3772bfc 100644 --- a/Source/OpalGraphics/CGContext-private.h +++ b/Source/OpalGraphics/CGContext-private.h @@ -11,12 +11,12 @@ 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 @@ -65,6 +65,7 @@ struct ct_additions 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 opal_draw_surface_in_rect(CGContextRef ctxt, CGRect dest, + cairo_surface_t *src, CGRect srcRect); #endif diff --git a/Source/OpalGraphics/CGContext.m b/Source/OpalGraphics/CGContext.m index f22382f..99d7b71 100644 --- a/Source/OpalGraphics/CGContext.m +++ b/Source/OpalGraphics/CGContext.m @@ -11,12 +11,12 @@ 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 @@ -38,10 +38,12 @@ * used if no other color is set on the context yet */ static cairo_pattern_t *default_cp; -extern cairo_surface_t *opal_CGImageGetSurfaceForImage(CGImageRef img, cairo_surface_t *contextSurface); +extern cairo_surface_t *opal_CGImageGetSurfaceForImage(CGImageRef img, + cairo_surface_t *contextSurface); extern CGRect opal_CGImageGetSourceRect(CGImageRef image); -static inline void set_color(cairo_pattern_t **cp, CGColorRef clr, double alpha); +static inline void set_color(cairo_pattern_t **cp, CGColorRef clr, + double alpha); static void start_shadow(CGContextRef ctx); static void end_shadow(CGContextRef ctx, CGRect bounds); @@ -58,31 +60,34 @@ - (id) initWithSurface: (cairo_surface_t *)target size: (CGSize)size self->add = NULL; self->ct = cairo_create(target); cret = cairo_status(self->ct); - if (cret) { - NSLog(@"cairo_create status: %s", - cairo_status_to_string(cret)); - [self release]; - return NULL; - } + if (cret) + { + NSLog(@"cairo_create status: %s", + cairo_status_to_string(cret)); + [self release]; + return NULL; + } self->add = calloc(1, sizeof(struct ct_additions)); - if (!self->add) { - NSLog(@"calloc failed"); - [self release]; - return NULL; - } + if (!self->add) + { + NSLog(@"calloc failed"); + [self release]; + return NULL; + } self->add->alpha = 1; self->add->font_size = 0; - - if (!default_cp) { - default_cp = cairo_get_source(self->ct); - cairo_pattern_reference(default_cp); - } + + if (!default_cp) + { + default_cp = cairo_get_source(self->ct); + cairo_pattern_reference(default_cp); + } /* Cairo defaults to line width 2.0 (see http://cairographics.org/FAQ) */ cairo_set_line_width(self->ct, 1); - /* Perform the flip transformation. Note that this is 'hidden' in + /* Perform the flip transformation. Note that this is 'hidden' in CGContextGetCTM() */ cairo_scale(self->ct, 1, -1); cairo_translate(self->ct, 0, -size.height); @@ -90,7 +95,7 @@ - (id) initWithSurface: (cairo_surface_t *)target size: (CGSize)size self->txtmatrix = CGAffineTransformIdentity; self->scale_factor = 1; self->device_size = size; - + return self; } @@ -99,21 +104,22 @@ - (void) dealloc ct_additions *ctadd, *next; ctadd = self->add; - while (ctadd) { - CGColorRelease(ctadd->fill_color); - cairo_pattern_destroy(ctadd->fill_cp); - CGColorRelease(ctadd->stroke_color); - cairo_pattern_destroy(ctadd->stroke_cp); - CGColorRelease(ctadd->shadow_color); - cairo_pattern_destroy(ctadd->shadow_cp); - CGFontRelease(ctadd->font); - next = ctadd->next; - free(ctadd); - ctadd = next; - } + while (ctadd) + { + CGColorRelease(ctadd->fill_color); + cairo_pattern_destroy(ctadd->fill_cp); + CGColorRelease(ctadd->stroke_color); + cairo_pattern_destroy(ctadd->stroke_cp); + CGColorRelease(ctadd->shadow_color); + cairo_pattern_destroy(ctadd->shadow_cp); + CGFontRelease(ctadd->font); + next = ctadd->next; + free(ctadd); + ctadd = next; + } cairo_destroy(self->ct); - + [super dealloc]; } @@ -121,7 +127,7 @@ - (void) setSize: (CGSize) size { cairo_matrix_t oldCTM; cairo_get_matrix(self->ct, &oldCTM); - + cairo_matrix_t oldFlipInverse; cairo_matrix_init_scale(&oldFlipInverse, 1, -1); cairo_matrix_translate(&oldFlipInverse, 0, -self->device_size.height); @@ -200,8 +206,8 @@ void CGContextSynchronize(CGContextRef ctx) void CGContextBeginPage(CGContextRef ctx, const CGRect *mediaBox) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g,%g,%g,%g)", ctx, mediaBox->origin.x, - mediaBox->origin.y, mediaBox->size.width, mediaBox->size.height) + OPLOGCALL("ctx /*%p*/, CGRectMake(%g,%g,%g,%g)", ctx, mediaBox->origin.x, + mediaBox->origin.y, mediaBox->size.width, mediaBox->size.height) /* FIXME: should we reset gstate?, mediaBox is ignored */ cairo_copy_page(ctx->ct); OPRESTORELOGGING() @@ -237,8 +243,9 @@ void CGContextRotateCTM(CGContextRef ctx, CGFloat angle) void CGContextConcatCTM(CGContextRef ctx, CGAffineTransform transform) { - OPLOGCALL("ctx /*%p*/, CGAffineTransformMake(%g, %g, %g, %g, %g, %g)", ctx, transform.a, - transform.b, transform.c, transform.d, transform.tx, transform.ty) + OPLOGCALL("ctx /*%p*/, CGAffineTransformMake(%g, %g, %g, %g, %g, %g)", ctx, + transform.a, + transform.b, transform.c, transform.d, transform.tx, transform.ty) cairo_matrix_t cmat; cmat.xx = transform.a; @@ -278,22 +285,23 @@ CGAffineTransform CGContextGetCTM(CGContextRef ctx) cairo_matrix_t cairoMatrix; cairo_get_matrix(ctx->ct, &cairoMatrix); - cairo_matrix_t undoFlip; + cairo_matrix_t undoFlip; cairo_matrix_init_identity(&undoFlip); cairo_matrix_scale(&undoFlip, 1, -1); cairo_matrix_translate(&undoFlip, 0, -ctx->device_size.height); - + cairo_matrix_t result; cairo_matrix_multiply(&result, &cairoMatrix, &undoFlip); OPRESTORELOGGING() - return CGAffineTransformMake(result.xx, result.yx, result.xy, result.yy, result.x0, result.y0); + return CGAffineTransformMake(result.xx, result.yx, result.xy, result.yy, + result.x0, result.y0); } void OPContextSetCairoDeviceOffset(CGContextRef ctx, CGFloat x, CGFloat y) { OPLOGCALL("ctx /*%p*/, %g, %g", ctx, x, y) - if(ctx && ctx->ct) + if (ctx && ctx->ct) cairo_surface_set_device_offset(cairo_get_target(ctx->ct), x, y); OPRESTORELOGGING() } @@ -312,21 +320,23 @@ void CGContextSaveGState(CGContextRef ctx) } ctadd = calloc(1, sizeof(struct ct_additions)); - if (!ctadd) { - NSLog(@"%s(%p): calloc failed", __PRETTY_FUNCTION__, ctx); - OPRESTORELOGGING() - return; - } + if (!ctadd) + { + NSLog(@"%s(%p): calloc failed", __PRETTY_FUNCTION__, ctx); + OPRESTORELOGGING() + return; + } cairo_save(ctx->ct); cret = cairo_status(ctx->ct); - if (cret) { - NSLog(@"cairo_save status: %s", - cairo_status_to_string(cret)); - free(ctadd); - OPRESTORELOGGING() - return; - } + if (cret) + { + NSLog(@"cairo_save status: %s", + cairo_status_to_string(cret)); + free(ctadd); + OPRESTORELOGGING() + return; + } *ctadd = *ctx->add; CGColorRetain(ctadd->fill_color); @@ -343,7 +353,7 @@ void CGContextRestoreGState(CGContextRef ctx) OPLOGCALL("ctx /*%p*/", ctx) OPRESTORELOGGING() ct_additions *ctadd; - + if (!ctx) { NSLog(@"%s: ctx == NULL", __PRETTY_FUNCTION__); @@ -361,7 +371,7 @@ void CGContextRestoreGState(CGContextRef ctx) free(ctx->add); ctx->add = ctadd; - if(!ctx->add) + if (!ctx->add) { NSLog(@"%s(%p): restoring produced null 'ct_additions'", __FUNCTION__, ctx); } @@ -373,7 +383,7 @@ void CGContextSetShouldAntialias(CGContextRef ctx, int shouldAntialias) { OPLOGCALL("ctx /*%p*/, %d", ctx, shouldAntialias) cairo_set_antialias(ctx->ct, - (shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE)); + (shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE)); OPRESTORELOGGING() } @@ -414,7 +424,8 @@ void CGContextSetLineDash( OPLOGCALL("ctx /*%p*/, %g, , %d", ctx, phase, count) if (!lengths && count != 0) { - NSLog(@"%s: null 'lengths' passed with count %d. Fixing by setting count to 0.", lengths, (int)count); + NSLog(@"%s: null 'lengths' passed with count %d. Fixing by setting count to 0.", + lengths, (int)count); count = 0; } @@ -480,7 +491,8 @@ void CGContextSetShouldSmoothFonts(CGContextRef ctx, int shouldSmoothFonts) OPRESTORELOGGING() } -void CGContextSetAllowsFontSmoothing(CGContextRef ctx, bool allowsFontSmoothing) +void CGContextSetAllowsFontSmoothing(CGContextRef ctx, + bool allowsFontSmoothing) { OPLOGCALL("ctx /*%p*/, %s", ctx, allowsFontSmoothing ? "true" : "false") OPRESTORELOGGING() @@ -502,7 +514,8 @@ void CGContextSetShouldSubpixelPositionFonts( CGContextRef ctx, bool shouldSubpixelPositionFonts) { - OPLOGCALL("ctx /*%p*/, %s", ctx, shouldSubpixelPositionFonts ? "true" : "false") + OPLOGCALL("ctx /*%p*/, %s", ctx, + shouldSubpixelPositionFonts ? "true" : "false") OPRESTORELOGGING() } @@ -510,7 +523,8 @@ void CGContextSetAllowsFontSubpixelPositioning( CGContextRef ctx, bool allowsFontSubpixelPositioning) { - OPLOGCALL("ctx /*%p*/, %s", ctx, allowsFontSubpixelPositioning ? "true" : "false") + OPLOGCALL("ctx /*%p*/, %s", ctx, + allowsFontSubpixelPositioning ? "true" : "false") OPRESTORELOGGING() } @@ -518,15 +532,17 @@ void CGContextSetShouldSubpixelQuantizeFonts( CGContextRef ctx, bool shouldSubpixelQuantizeFonts) { - OPLOGCALL("ctx /*%p*/, %s", ctx, shouldSubpixelQuantizeFonts ? "true" : "false") + OPLOGCALL("ctx /*%p*/, %s", ctx, + shouldSubpixelQuantizeFonts ? "true" : "false") OPRESTORELOGGING() -} - +} + void CGContextSetAllowsFontSubpixelQuantization( CGContextRef ctx, bool allowsFontSubpixelQuantization) { - OPLOGCALL("ctx /*%p*/, %s", ctx, allowsFontSubpixelQuantization ? "true" : "false") + OPLOGCALL("ctx /*%p*/, %s", ctx, + allowsFontSubpixelQuantization ? "true" : "false") OPRESTORELOGGING() } @@ -534,8 +550,9 @@ void CGContextSetShadow( CGContextRef ctx, CGSize offset, CGFloat radius) -{ - OPLOGCALL("ctx /*%p*/, CGSizeMake(%g, %g), %g", ctx, offset.width, offset.height, +{ + OPLOGCALL("ctx /*%p*/, CGSizeMake(%g, %g), %g", ctx, offset.width, + offset.height, radius) CGColorRef defaultShadowColor = CGColorCreateGenericGray(0, 0.3); CGContextSetShadowWithColor(ctx, offset, radius, defaultShadowColor); @@ -549,12 +566,13 @@ void CGContextSetShadowWithColor( CGFloat radius, CGColorRef color) { - OPLOGCALL("ctx /*%p*/, CGSizeMake(%g, %g), %g, ", ctx, offset.width, offset.height, + OPLOGCALL("ctx /*%p*/, CGSizeMake(%g, %g), %g, ", ctx, offset.width, + offset.height, radius) CGColorRelease(ctx->add->shadow_color); ctx->add->shadow_color = color; CGColorRetain(color); - + ctx->add->shadow_offset = offset; ctx->add->shadow_radius = radius; set_color(&ctx->add->shadow_cp, color, 1.0); @@ -610,7 +628,8 @@ void CGContextAddCurveToPoint( CGFloat x, CGFloat y) { - OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g, %g", ctx, cp1x, cp1y, cp2x, cp2y, x, y) + OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g, %g", ctx, cp1x, cp1y, cp2x, cp2y, x, + y) cairo_curve_to(ctx->ct, cp1x, cp1y, cp2x, cp2y, x, y); OPRESTORELOGGING() } @@ -624,15 +643,17 @@ void CGContextAddQuadCurveToPoint( { OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g", ctx, cpx, cpy, x, y) CGPoint curr = CGContextGetPathCurrentPoint(ctx); - CGContextAddCurveToPoint(ctx, (curr.x/3.0) + (2.0*cpx/3.0), (curr.y/3.0) + (2.0*cpy/3.0), - (2.0*cpx/3.0) + (x/3.0), (2.0*cpy/3.0) + (y/3.0), - x, y); + CGContextAddCurveToPoint(ctx, (curr.x/3.0) + (2.0*cpx/3.0), + (curr.y/3.0) + (2.0*cpy/3.0), + (2.0*cpx/3.0) + (x/3.0), (2.0*cpy/3.0) + (y/3.0), + x, y); OPRESTORELOGGING() } void CGContextAddRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) cairo_rectangle(ctx->ct, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); @@ -658,7 +679,8 @@ void CGContextAddArc( CGFloat endAngle, int clockwise) { - OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g, %d", ctx, x, y, radius, startAngle, endAngle, + OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g, %d", ctx, x, y, radius, startAngle, + endAngle, clockwise) if (clockwise) cairo_arc_negative(ctx->ct, x, y, radius, startAngle, endAngle); @@ -695,27 +717,31 @@ void CGContextAddArcToPoint( xl2 = sqrt(dx2*dx2 + dy2*dy2); san = dx2*dy0 - dx0*dy2; - if (san == 0) { - CGContextAddLineToPoint(ctx, x1, y1); - OPRESTORELOGGING() - return; - } - - if (san < 0) { - n0x = -dy0 / xl0; - n0y = dx0 / xl0; - n2x = dy2 / xl2; - n2y = -dx2 / xl2; - } else { - n0x = dy0 / xl0; - n0y = -dx0 / xl0; - n2x = -dy2 / xl2; - n2y = dx2 / xl2; - } + if (san == 0) + { + CGContextAddLineToPoint(ctx, x1, y1); + OPRESTORELOGGING() + return; + } + + if (san < 0) + { + n0x = -dy0 / xl0; + n0y = dx0 / xl0; + n2x = dy2 / xl2; + n2y = -dx2 / xl2; + } + else + { + n0x = dy0 / xl0; + n0y = -dx0 / xl0; + n2x = -dy2 / xl2; + n2y = dx2 / xl2; + } t = (dx2*n2y - dx2*n0y - dy2*n2x + dy2*n0x) / san; CGContextAddArc(ctx, - x1 + radius * (t * dx0 + n0x), y1 + radius * (t * dy0 + n0y), - radius, atan2(-n0y, -n0x), atan2(-n2y, -n2x), (san < 0)); + x1 + radius * (t * dx0 + n0x), y1 + radius * (t * dy0 + n0y), + radius, atan2(-n0y, -n0x), atan2(-n2y, -n2x), (san < 0)); OPRESTORELOGGING() } @@ -723,28 +749,28 @@ static void OPAddPathApplier(void *info, const CGPathElement *elem) { CGContextRef ctx = (CGContextRef)info; switch (elem->type) - { - case kCGPathElementMoveToPoint: - CGContextMoveToPoint(ctx, elem->points[0].x, elem->points[0].y); - break; - case kCGPathElementAddLineToPoint: - CGContextAddLineToPoint(ctx, elem->points[0].x, elem->points[0].y); - break; - case kCGPathElementAddQuadCurveToPoint: - CGContextAddQuadCurveToPoint(ctx, elem->points[0].x, elem->points[0].y, - elem->points[1].x, elem->points[1].y); - break; - case kCGPathElementAddCurveToPoint: - CGContextAddCurveToPoint(ctx, elem->points[0].x, elem->points[0].y, - elem->points[1].x, elem->points[1].y, - elem->points[2].x, elem->points[2].y); - break; - case kCGPathElementCloseSubpath: - CGContextClosePath(ctx); - break; - default: - break; - } + { + case kCGPathElementMoveToPoint: + CGContextMoveToPoint(ctx, elem->points[0].x, elem->points[0].y); + break; + case kCGPathElementAddLineToPoint: + CGContextAddLineToPoint(ctx, elem->points[0].x, elem->points[0].y); + break; + case kCGPathElementAddQuadCurveToPoint: + CGContextAddQuadCurveToPoint(ctx, elem->points[0].x, elem->points[0].y, + elem->points[1].x, elem->points[1].y); + break; + case kCGPathElementAddCurveToPoint: + CGContextAddCurveToPoint(ctx, elem->points[0].x, elem->points[0].y, + elem->points[1].x, elem->points[1].y, + elem->points[2].x, elem->points[2].y); + break; + case kCGPathElementCloseSubpath: + CGContextClosePath(ctx); + break; + default: + break; + } } void CGContextAddPath(CGContextRef ctx, CGPathRef path) @@ -756,7 +782,8 @@ void CGContextAddPath(CGContextRef ctx, CGPathRef path) void CGContextAddEllipseInRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) OPRESTORELOGGING() } @@ -772,21 +799,23 @@ void CGContextStrokePath(CGContextRef ctx) OPLOGCALL("ctx /*%p*/", ctx) cairo_status_t cret; - if (ctx->add->shadow_cp) { - start_shadow(ctx); - } + if (ctx->add->shadow_cp) + { + start_shadow(ctx); + } - if(ctx->add->stroke_cp) + if (ctx->add->stroke_cp) cairo_set_source(ctx->ct, ctx->add->stroke_cp); else cairo_set_source(ctx->ct, default_cp); cairo_stroke(ctx->ct); - - if (ctx->add->shadow_cp) { - end_shadow(ctx, CGRectMake(0,0,500,500)); //FIXME - } - + + if (ctx->add->shadow_cp) + { + end_shadow(ctx, CGRectMake(0,0,500,500)); //FIXME + } + cret = cairo_status(ctx->ct); if (cret) NSLog(@"cairo_stroke status: %s", @@ -797,20 +826,21 @@ void CGContextStrokePath(CGContextRef ctx) static void fill_path(CGContextRef ctx, int eorule, int preserve) { cairo_status_t cret; - - if(!ctx || !ctx->add) + + if (!ctx || !ctx->add) { NSLog(@"null %s%s%s in %s", !ctx ? "ctx" : "", - (!ctx && !ctx->add) ? " and " : "", + (!ctx && !ctx->add) ? " and " : "", !ctx->add ? "ctx->add" : "", __PRETTY_FUNCTION__); return; } - if (ctx->add->shadow_cp) { - start_shadow(ctx); - } + if (ctx->add->shadow_cp) + { + start_shadow(ctx); + } if (ctx->add->fill_cp) cairo_set_source(ctx->ct, ctx->add->fill_cp); else @@ -823,11 +853,12 @@ static void fill_path(CGContextRef ctx, int eorule, int preserve) cairo_fill_preserve(ctx->ct); if (!preserve) cairo_new_path(ctx->ct); - - if (ctx->add->shadow_cp) { - end_shadow(ctx, CGRectMake(0,0,500,500)); //FIXME - } - + + if (ctx->add->shadow_cp) + { + end_shadow(ctx, CGRectMake(0,0,500,500)); //FIXME + } + cret = cairo_status(ctx->ct); if (cret) NSLog(@"cairo_fill status: %s", @@ -842,7 +873,8 @@ void CGContextFillPath(CGContextRef ctx) } void CGContextClearPath(CGContextRef ctx) -{ //FIXME +{ + //FIXME OPLOGCALL("ctx /*%p*/", ctx) cairo_status_t cret; @@ -871,27 +903,29 @@ void CGContextEOFillPath(CGContextRef ctx) void CGContextDrawPath(CGContextRef ctx, CGPathDrawingMode mode) { OPLOGCALL("ctx /*%p*/, %d", ctx, mode) - switch (mode) { - case kCGPathFill: - case kCGPathEOFill: - fill_path(ctx, (mode == kCGPathEOFill), 0); - break; - case kCGPathFillStroke: - case kCGPathEOFillStroke: - fill_path(ctx, (mode == kCGPathEOFillStroke), 1); + switch (mode) + { + case kCGPathFill: + case kCGPathEOFill: + fill_path(ctx, (mode == kCGPathEOFill), 0); + break; + case kCGPathFillStroke: + case kCGPathEOFillStroke: + fill_path(ctx, (mode == kCGPathEOFillStroke), 1); /* fall through */ - case kCGPathStroke: - CGContextStrokePath(ctx); - break; - default: - NSLog(@"CGContextDrawPath invalid CGPathDrawingMode: %d", mode); - } + case kCGPathStroke: + CGContextStrokePath(ctx); + break; + default: + NSLog(@"CGContextDrawPath invalid CGPathDrawingMode: %d", mode); + } OPRESTORELOGGING() } void CGContextStrokeRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) CGContextBeginPath(ctx); CGContextAddRect(ctx, rect); @@ -901,7 +935,8 @@ void CGContextStrokeRect(CGContextRef ctx, CGRect rect) void CGContextStrokeRectWithWidth(CGContextRef ctx, CGRect rect, CGFloat width) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), %g", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), %g", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height, width) CGContextSetLineWidth(ctx, width); CGContextStrokeRect(ctx, rect); @@ -911,7 +946,8 @@ void CGContextStrokeRectWithWidth(CGContextRef ctx, CGRect rect, CGFloat width) void CGContextFillRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) CGContextBeginPath(ctx); CGContextAddRect(ctx, rect); @@ -930,7 +966,8 @@ void CGContextFillRects(CGContextRef ctx, const CGRect rects[], size_t count) void CGContextClearRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) CGContextBeginPath(ctx); CGContextAddRect(ctx, rect); @@ -947,17 +984,18 @@ void CGContextStrokeLineSegments( size_t i; CGContextBeginPath(ctx); - for (i=1; ict, &x1, &y1, &x2, &y2); if (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0) - { - return CGRectNull; - } + { + return CGRectNull; + } else - { - // FIXME: check non-negative width/height - return CGRectMake(x1, y1, (x2-x1), (y2-y1)); - } + { + // FIXME: check non-negative width/height + return CGRectMake(x1, y1, (x2-x1), (y2-y1)); + } } CGPathRef CGContextCopyPath(CGContextRef ctx) @@ -988,26 +1026,26 @@ CGPathRef CGContextCopyPath(CGContextRef ctx) CGMutablePathRef path = CGPathCreateMutable(); cairo_path_t *cairopath = cairo_copy_path(ctx->ct); for (int i=0; inum_data; i+=cairopath->data[i].header.length) - { - cairo_path_data_t *data = &cairopath->data[i]; - switch (data[0].header.type) { - case CAIRO_PATH_MOVE_TO: - CGPathMoveToPoint(path, NULL, data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_LINE_TO: - CGPathAddLineToPoint(path, NULL, data[1].point.x, data[1].point.y); - break; - case CAIRO_PATH_CURVE_TO: - CGPathAddCurveToPoint(path, NULL, data[1].point.x, data[1].point.y, - data[2].point.x, data[2].point.y, - data[3].point.x, data[3].point.y); - break; - case CAIRO_PATH_CLOSE_PATH: - CGPathCloseSubpath(path); - break; + cairo_path_data_t *data = &cairopath->data[i]; + switch (data[0].header.type) + { + case CAIRO_PATH_MOVE_TO: + CGPathMoveToPoint(path, NULL, data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_LINE_TO: + CGPathAddLineToPoint(path, NULL, data[1].point.x, data[1].point.y); + break; + case CAIRO_PATH_CURVE_TO: + CGPathAddCurveToPoint(path, NULL, data[1].point.x, data[1].point.y, + data[2].point.x, data[2].point.y, + data[3].point.x, data[3].point.y); + break; + case CAIRO_PATH_CLOSE_PATH: + CGPathCloseSubpath(path); + break; + } } - } cairo_path_destroy(cairopath); return (CGPathRef)path; } @@ -1030,7 +1068,8 @@ void CGContextEOClip(CGContextRef ctx) void CGContextClipToRect(CGContextRef ctx, CGRect rect) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, rect.origin.y, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g)", ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height) CGContextBeginPath(ctx); CGContextAddRect(ctx, rect); @@ -1049,11 +1088,11 @@ void CGContextClipToRects(CGContextRef ctx, const CGRect rects[], size_t count) void CGContextClipToMask(CGContextRef ctx, CGRect rect, CGImageRef mask) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), ", ctx, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), ", ctx, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height) /* Attach a temporay image mask to the surface. - Then, all drawing needs a: + Then, all drawing needs a: push_group() do the drawing pop_group_to_source(); @@ -1066,11 +1105,11 @@ CGFloat OPContextGetAlpha(CGContextRef ctx) { OPLOGCALL("ctx /*%p*/", ctx) - if(!ctx || !ctx->add) + if (!ctx || !ctx->add) { NSLog(@"null %s%s%s in %s", !ctx ? "ctx" : "", - (!ctx && !ctx->add) ? " and " : "", + (!ctx && !ctx->add) ? " and " : "", !ctx->add ? "ctx->add" : "", __PRETTY_FUNCTION__); return 0; @@ -1086,9 +1125,9 @@ void OPContextResetClip(CGContextRef ctx) { OPLOGCALL("ctx /*%p*/", ctx) if (ctx && ctx->ct) - { - cairo_reset_clip(ctx->ct); - } + { + cairo_reset_clip(ctx->ct); + } OPRESTORELOGGING() } @@ -1097,7 +1136,8 @@ CGRect CGContextGetClipBoundingBox(CGContextRef ctx) return CGRectNull; } -static inline void set_color(cairo_pattern_t **cp, CGColorRef clr, double alpha) +static inline void set_color(cairo_pattern_t **cp, CGColorRef clr, + double alpha) { // FIXME: check why this might be called with a NULL clr if (!clr) return; @@ -1105,34 +1145,37 @@ static inline void set_color(cairo_pattern_t **cp, CGColorRef clr, double alpha) cairo_status_t cret; CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - CGColorRef srgbClr = OPColorGetTransformedToSpace(clr, srgb, kCGRenderingIntentRelativeColorimetric); + CGColorRef srgbClr = OPColorGetTransformedToSpace(clr, srgb, + kCGRenderingIntentRelativeColorimetric); CGColorSpaceRelease(srgb); const CGFloat *cc = CGColorGetComponents(srgbClr); - NSDebugLLog(@"Opal", @"Set color with %f %f %f %f", (float)cc[0], (float)cc[1], (float)cc[2], (float)cc[3]*alpha); + NSDebugLLog(@"Opal", @"Set color with %f %f %f %f", (float)cc[0], (float)cc[1], + (float)cc[2], (float)cc[3]*alpha); newcp = cairo_pattern_create_rgba(cc[0], cc[1], cc[2], cc[3]*alpha); cret = cairo_pattern_status(newcp); - if (cret) { - NSLog(@" cairo_pattern_create_rgba status: %s", - cairo_status_to_string(cret)); - return; - } + if (cret) + { + NSLog(@" cairo_pattern_create_rgba status: %s", + cairo_status_to_string(cret)); + return; + } if (*cp != NULL) - { - cairo_pattern_destroy(*cp); - } + { + cairo_pattern_destroy(*cp); + } *cp = newcp; } void CGContextSetFillColorWithColor(CGContextRef ctx, CGColorRef color) { OPLOGCALL("ctx /*%p*/, ", ctx) - if(!ctx || !ctx->add) + if (!ctx || !ctx->add) { NSLog(@"null %s%s%s in %s", !ctx ? "ctx" : "", - (!ctx && !ctx->add) ? " and " : "", + (!ctx && !ctx->add) ? " and " : "", !ctx->add ? "ctx->add" : "", __PRETTY_FUNCTION__); OPRESTORELOGGING() @@ -1149,11 +1192,11 @@ void CGContextSetFillColorWithColor(CGContextRef ctx, CGColorRef color) void CGContextSetStrokeColorWithColor(CGContextRef ctx, CGColorRef color) { OPLOGCALL("ctx /*%p*/, ", ctx) - if(!ctx || !ctx->add) + if (!ctx || !ctx->add) { NSLog(@"null %s%s%s in %s", !ctx ? "ctx" : "", - (!ctx && !ctx->add) ? " and " : "", + (!ctx && !ctx->add) ? " and " : "", !ctx->add ? "ctx->add" : "", __PRETTY_FUNCTION__); OPRESTORELOGGING() @@ -1170,11 +1213,11 @@ void CGContextSetStrokeColorWithColor(CGContextRef ctx, CGColorRef color) void CGContextSetAlpha(CGContextRef ctx, CGFloat alpha) { OPLOGCALL("ctx /*%p*/, %g", ctx, alpha) - if(!ctx || !ctx->add) + if (!ctx || !ctx->add) { - NSLog(@"null %s%s%s in %s", + NSLog(@"null %s%s%s in %s", !ctx ? "ctx" : "", - (!ctx && !ctx->add) ? " and " : "", + (!ctx && !ctx->add) ? " and " : "", !ctx->add ? "ctx->add" : "", __PRETTY_FUNCTION__); OPRESTORELOGGING() @@ -1188,7 +1231,7 @@ void CGContextSetAlpha(CGContextRef ctx, CGFloat alpha) // FIXME: Should we really check that these are non-null? if (ctx->add->stroke_color) set_color(&ctx->add->stroke_cp, ctx->add->stroke_color, ctx->add->alpha); - if (ctx->add->fill_color) + if (ctx->add->fill_color) set_color(&ctx->add->fill_cp, ctx->add->fill_color, ctx->add->alpha); OPRESTORELOGGING() } @@ -1202,10 +1245,11 @@ void CGContextSetFillColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace) nc = CGColorSpaceGetNumberOfComponents(colorspace); components = calloc(nc+1, sizeof(CGFloat)); - if (components) { - NSLog(@"%s: calloc failed", __PRETTY_FUNCTION__); - return; - } + if (components) + { + NSLog(@"%s: calloc failed", __PRETTY_FUNCTION__); + return; + } /* Default is an opaque, zero intensity color (usually black) */ components[nc] = 1; color = CGColorCreate(colorspace, components); @@ -1224,10 +1268,11 @@ void CGContextSetStrokeColorSpace(CGContextRef ctx, CGColorSpaceRef colorspace) nc = CGColorSpaceGetNumberOfComponents(colorspace); components = calloc(nc+1, sizeof(CGFloat)); - if (components) { - NSLog(@"%s: calloc failed", __PRETTY_FUNCTION__); - return; - } + if (components) + { + NSLog(@"%s: calloc failed", __PRETTY_FUNCTION__); + return; + } /* Default is an opaque, zero intensity color (usually black) */ components[nc] = 1; color = CGColorCreate(colorspace, components); @@ -1298,7 +1343,7 @@ void CGContextSetGrayStrokeColor(CGContextRef ctx, CGFloat gray, CGFloat alpha) } void CGContextSetRGBFillColor(CGContextRef ctx, - CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) + CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) { OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g", ctx, r, g, b, alpha) CGFloat comps[4]; @@ -1318,7 +1363,7 @@ void CGContextSetRGBFillColor(CGContextRef ctx, } void CGContextSetRGBStrokeColor(CGContextRef ctx, - CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) + CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) { OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g", ctx, r, g, b, alpha) CGFloat comps[4]; @@ -1338,9 +1383,10 @@ void CGContextSetRGBStrokeColor(CGContextRef ctx, } void CGContextSetCMYKFillColor(CGContextRef ctx, - CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha) + CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha) { - OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g", ctx, cyan, magenta, yellow, black, alpha) + OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g", ctx, cyan, magenta, yellow, black, + alpha) CGColorRef color; color = CGColorCreateGenericCMYK(cyan, magenta, yellow, black, alpha); @@ -1350,9 +1396,10 @@ void CGContextSetCMYKFillColor(CGContextRef ctx, } void CGContextSetCMYKStrokeColor(CGContextRef ctx, - CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha) + CGFloat cyan, CGFloat magenta, CGFloat yellow, CGFloat black, CGFloat alpha) { - OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g", ctx, cyan, magenta, yellow, black, alpha) + OPLOGCALL("ctx /*%p*/, %g, %g, %g, %g, %g", ctx, cyan, magenta, yellow, black, + alpha) CGColorRef color; color = CGColorCreateGenericCMYK(cyan, magenta, yellow, black, alpha); @@ -1361,27 +1408,28 @@ void CGContextSetCMYKStrokeColor(CGContextRef ctx, OPRESTORELOGGING() } -void opal_draw_surface_in_rect(CGContextRef ctxt, CGRect rect, cairo_surface_t *src, CGRect srcRect) -{ +void opal_draw_surface_in_rect(CGContextRef ctxt, CGRect rect, + cairo_surface_t *src, CGRect srcRect) +{ cairo_pattern_t *pattern = cairo_pattern_create_for_surface(src); - + cairo_matrix_t patternMatrix; cairo_matrix_init_identity(&patternMatrix); - + // Move to the place where the layer should be drawn cairo_matrix_translate(&patternMatrix, srcRect.origin.x, srcRect.origin.y); // Scale the pattern to the correct size cairo_matrix_scale(&patternMatrix, - srcRect.size.width / rect.size.width, - srcRect.size.height / rect.size.height); + srcRect.size.width / rect.size.width, + srcRect.size.height / rect.size.height); // Flip the layer up-side-down cairo_matrix_scale(&patternMatrix, 1, -1); cairo_matrix_translate(&patternMatrix, 0, -rect.size.height); cairo_pattern_set_matrix(pattern, &patternMatrix); - + // FIXME: do we always want this? cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD); @@ -1395,10 +1443,10 @@ void opal_draw_surface_in_rect(CGContextRef ctxt, CGRect rect, cairo_surface_t * cairo_set_source(destCairo, pattern); cairo_pattern_destroy(pattern); - + // FIXME: What is the fastest way to draw? cairo_paint? clip? fill a rect? cairo_rectangle(destCairo, 0, 0, - rect.size.width, rect.size.height); + rect.size.width, rect.size.height); cairo_clip(destCairo); cairo_paint_with_alpha(destCairo, ctxt->add->alpha); @@ -1408,19 +1456,22 @@ void opal_draw_surface_in_rect(CGContextRef ctxt, CGRect rect, cairo_surface_t * void CGContextDrawImage(CGContextRef ctx, CGRect rect, CGImageRef image) { CGRect srcrect = opal_CGImageGetSourceRect(image); - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), (%p, subrect %g %g %g %g)", ctx, rect.origin.x, - rect.origin.y, rect.size.width, rect.size.height, image, srcrect.origin.x, srcrect.origin.y, srcrect.size.width, srcrect.size.height) + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), (%p, subrect %g %g %g %g)", + ctx, rect.origin.x, + rect.origin.y, rect.size.width, rect.size.height, image, srcrect.origin.x, + srcrect.origin.y, srcrect.size.width, srcrect.size.height) opal_draw_surface_in_rect(ctx, rect, - opal_CGImageGetSurfaceForImage(image, cairo_get_target(ctx->ct)), - opal_CGImageGetSourceRect(image)); + opal_CGImageGetSurfaceForImage(image, cairo_get_target(ctx->ct)), + opal_CGImageGetSourceRect(image)); OPRESTORELOGGING() } void CGContextDrawTiledImage(CGContextRef ctx, CGRect rect, CGImageRef image) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), ", ctx, rect.origin.x, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), ", ctx, + rect.origin.x, rect.origin.y, rect.size.width, rect.size.height) OPRESTORELOGGING() } @@ -1431,7 +1482,8 @@ void CGContextDrawPDFDocument( CGPDFDocumentRef document, int page) { - OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), , %d", ctx, rect.origin.x, + OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), , %d", ctx, + rect.origin.x, rect.origin.y, rect.size.width, rect.size.height, page) OPRESTORELOGGING() } @@ -1446,23 +1498,25 @@ static void opal_AddStops(cairo_pattern_t *pat, CGGradientRef grad) { // FIXME: support other colorspaces by converting to deviceRGB if (![CGColorSpaceCreateDeviceRGB() isEqual: OPGradientGetColorSpace(grad)]) - { - NSLog(@"%s: Only DeviceRGB supported for gradients", __PRETTY_FUNCTION__); - return; - } - - size_t cs_numcomps = 4; // == (CGColorSpaceGetNumberOfComponents(OPGradientGetColorSpace(grad)) + 1); - + { + NSLog(@"%s: Only DeviceRGB supported for gradients", __PRETTY_FUNCTION__); + return; + } + + size_t cs_numcomps = + 4; // == (CGColorSpaceGetNumberOfComponents(OPGradientGetColorSpace(grad)) + 1); + size_t numcomps = OPGradientGetCount(grad); - + const CGFloat *components = OPGradientGetComponents(grad); const CGFloat *locations = OPGradientGetLocations(grad); - + for (int i=0; i, CGPointMake(%g, %g), CGPointMake(%g, %g), %d", ctx, + OPLOGCALL("ctx /*%p*/, , CGPointMake(%g, %g), CGPointMake(%g, %g), %d", + ctx, startPoint.x, startPoint.y, endPoint.x, endPoint.y, options) - cairo_pattern_t *pat = cairo_pattern_create_linear(startPoint.x, startPoint.y, endPoint.x, endPoint.y); + cairo_pattern_t *pat = cairo_pattern_create_linear(startPoint.x, startPoint.y, + endPoint.x, endPoint.y); opal_AddStops(pat, gradient); - + cairo_set_source(ctx->ct, pat); // FIXME: respect CGGradientDrawingOptions cairo_paint(ctx->ct); - + cairo_pattern_destroy(pat); OPRESTORELOGGING() } @@ -1497,14 +1553,15 @@ void CGContextDrawRadialGradient( OPLOGCALL("ctx, , CGPointMake(%g, %g),%g, CGPointMake(%g, %g),%g, " "%d", startCenter.x, startCenter.y, startRadius, endCenter.x, endCenter.y, endRadius, options) - cairo_pattern_t *pat = cairo_pattern_create_radial(startCenter.x, startCenter.y, startRadius, - endCenter.x, endCenter.y, endRadius); + cairo_pattern_t *pat = cairo_pattern_create_radial(startCenter.x, + startCenter.y, startRadius, + endCenter.x, endCenter.y, endRadius); opal_AddStops(pat, gradient); - + cairo_set_source(ctx->ct, pat); // FIXME: respect CGGradientDrawingOptions cairo_paint(ctx->ct); - + cairo_pattern_destroy(pat); OPRESTORELOGGING() } @@ -1517,11 +1574,13 @@ void CGContextDrawShading( void CGContextSetFont(CGContextRef ctx, CGFontRef font) { OPLOGCALL("ctx /*%p*/, ", ctx) - if (!font) { - NSLog(@" CGContextSetFont got NULL"); - return; - } - cairo_set_font_face(ctx->ct, cairo_scaled_font_get_font_face(((CairoFont*)font)->cairofont)); + if (!font) + { + NSLog(@" CGContextSetFont got NULL"); + return; + } + cairo_set_font_face(ctx->ct, + cairo_scaled_font_get_font_face(((CairoFont*)font)->cairofont)); ctx->add->font = CGFontRetain(font); OPRESTORELOGGING() } @@ -1576,8 +1635,9 @@ CGPoint CGContextGetTextPosition(CGContextRef ctx) void CGContextSetTextMatrix(CGContextRef ctx, CGAffineTransform transform) { - OPLOGCALL("ctx /*%p*/, CGAffineTransformMake(%g, %g, %g, %g, %g, %g)", ctx, transform.a, - transform.b, transform.c, transform.d, transform.tx, transform.ty) + OPLOGCALL("ctx /*%p*/, CGAffineTransformMake(%g, %g, %g, %g, %g, %g)", ctx, + transform.a, + transform.b, transform.c, transform.d, transform.tx, transform.ty) ctx->txtmatrix = transform; OPRESTORELOGGING() } @@ -1594,30 +1654,30 @@ void CGContextShowText(CGContextRef ctx, const char *string, size_t length) char *cString; if (length + 1 > 0) - { - cString = (char *)malloc(length+1); - memcpy(cString, string, length); - cString[length] = '\0'; - } + { + cString = (char *)malloc(length+1); + memcpy(cString, string, length); + cString[length] = '\0'; + } else - { - OPRESTORELOGGING() - return; - } + { + OPRESTORELOGGING() + return; + } // Save the cairo current point and move to the origin bool hadPoint; double oldX, oldY; if (cairo_has_current_point(ctx->ct)) - { - cairo_get_current_point(ctx->ct, &oldX, &oldY); - hadPoint = true; - } + { + cairo_get_current_point(ctx->ct, &oldX, &oldY); + hadPoint = true; + } else - { - hadPoint = false; - } + { + hadPoint = false; + } cairo_move_to(ctx->ct, 0, 0); // Compute the cairo text matrix @@ -1635,14 +1695,15 @@ void CGContextShowText(CGContextRef ctx, const char *string, size_t length) cairo_matrix_scale(&cairotextmatrix, ctx->add->font_size, ctx->add->font_size); - cairo_matrix_init(&opaltextmatrix, ctx->txtmatrix.a, ctx->txtmatrix.b, ctx->txtmatrix.c, - ctx->txtmatrix.d, ctx->txtmatrix.tx, ctx->txtmatrix.ty); + cairo_matrix_init(&opaltextmatrix, ctx->txtmatrix.a, ctx->txtmatrix.b, + ctx->txtmatrix.c, + ctx->txtmatrix.d, ctx->txtmatrix.tx, ctx->txtmatrix.ty); cairo_matrix_multiply(&cairotextmatrix, &cairotextmatrix, &opaltextmatrix); cairo_set_font_matrix(ctx->ct, &cairotextmatrix); - if(ctx->add->fill_cp) + if (ctx->add->fill_cp) cairo_set_source(ctx->ct, ctx->add->fill_cp); else cairo_set_source(ctx->ct, default_cp); @@ -1654,7 +1715,7 @@ void CGContextShowText(CGContextRef ctx, const char *string, size_t length) double dx, dy; cairo_get_current_point(ctx->ct, &dx, &dy); - + CGPoint textPos = CGContextGetTextPosition(ctx); CGContextSetTextPosition(ctx, textPos.x + dx, textPos.y + dy); // FXIME: scaled? @@ -1662,13 +1723,13 @@ void CGContextShowText(CGContextRef ctx, const char *string, size_t length) // Restore the cairo path to the way it was before we did any text if (hadPoint) - { - cairo_move_to(ctx->ct, oldX, oldY); - } + { + cairo_move_to(ctx->ct, oldX, oldY); + } else - { - cairo_new_path(ctx->ct); - } + { + cairo_new_path(ctx->ct); + } OPRESTORELOGGING() } @@ -1694,22 +1755,25 @@ void CGContextShowGlyphs(CGContextRef ctx, const CGGlyph *glyphs, size_t count) // FIXME: Okay to stack allocate? int advances[count]; if (CGFontGetGlyphAdvances(ctx->add->font, glyphs, count, advances)) - { - CGSize fAdvances[count]; - - CGFloat glyphSpaceToTextSpace = ctx->add->font_size / CGFontGetUnitsPerEm(ctx->add->font); - for (int i=0; iadd->char_spacing; - fAdvances[i].height = 0; - - // Convert the width from text space to user space - fAdvances[i] = CGSizeApplyAffineTransform(fAdvances[i], CGContextGetTextMatrix(ctx)); + CGSize fAdvances[count]; + + CGFloat glyphSpaceToTextSpace = ctx->add->font_size / CGFontGetUnitsPerEm( + ctx->add->font); + for (int i=0; iadd->char_spacing; + fAdvances[i].height = 0; + + // Convert the width from text space to user space + fAdvances[i] = CGSizeApplyAffineTransform(fAdvances[i], + CGContextGetTextMatrix(ctx)); + } + CGContextShowGlyphsWithAdvances(ctx, glyphs, fAdvances, count); } - CGContextShowGlyphsWithAdvances(ctx, glyphs, fAdvances, count); - } OPRESTORELOGGING() } @@ -1742,22 +1806,24 @@ void CGContextShowGlyphsAtPositions( { OPLOGCALL("ctx /*%p*/, , , %d", ctx, count) - // This matches CG; nothing is drawn unless a font size is explicitly set. + // This matches CG; nothing is drawn unless a font size is explicitly set. if (ctx->add->font_size == 0) - { - NSLog(@"%s: context's font size is set to zero.", __PRETTY_FUNCTION__); - OPRESTORELOGGING() - return; - } + { + NSLog(@"%s: context's font size is set to zero.", __PRETTY_FUNCTION__); + OPRESTORELOGGING() + return; + } // FIXME: Okay to stack allocate? cairo_glyph_t cairoGlyphs[count]; - for (int i=0; iadd->font_size, ctx->add->font_size); - cairo_matrix_init(&opaltextmatrix, ctx->txtmatrix.a, ctx->txtmatrix.b, ctx->txtmatrix.c, - ctx->txtmatrix.d, 0, 0); + cairo_matrix_init(&opaltextmatrix, ctx->txtmatrix.a, ctx->txtmatrix.b, + ctx->txtmatrix.c, + ctx->txtmatrix.d, 0, 0); cairo_matrix_multiply(&cairotextmatrix, &cairotextmatrix, &opaltextmatrix); @@ -1784,17 +1851,18 @@ void CGContextShowGlyphsAtPositions( // Show the glpyhs - if(ctx->add->fill_cp) + if (ctx->add->fill_cp) cairo_set_source(ctx->ct, ctx->add->fill_cp); else cairo_set_source(ctx->ct, default_cp); - + // FIXME: Report this as a cairo bug.. the following places the glyphs after the first one incorrectly //cairo_show_glyphs(ctx->ct, cairoGlyphs, count); // WORKAROUND: - for (int i=0; ict, &(cairoGlyphs[i]), 1); - } + for (int i=0; ict, &(cairoGlyphs[i]), 1); + } OPRESTORELOGGING() } @@ -1809,27 +1877,31 @@ void CGContextShowGlyphsWithAdvances ( size_t count) { OPLOGCALL("ctx /*%p*/, , , %d", ctx, count) - if (count <= 0) { - OPRESTORELOGGING() - return; - } + if (count <= 0) + { + OPRESTORELOGGING() + return; + } // FIXME: Okay to stack allocate? CGPoint positions[count]; positions[0] = CGPointMake(0,0); - for (size_t i=1; i", ctx) // Save cairo state, to match CGContextBeginTransparencyLayerWithRect - cairo_save(ctx->ct); - + cairo_save(ctx->ct); + // Save Opal state, and set alpha to 1 and shadows off (within the // transparency layer) CGContextSaveGState(ctx); @@ -1853,9 +1925,9 @@ void CGContextBeginTransparencyLayer( } void CGContextBeginTransparencyLayerWithRect( - CGContextRef ctx, - CGRect rect, - CFDictionaryRef auxiliaryInfo) + CGContextRef ctx, + CGRect rect, + CFDictionaryRef auxiliaryInfo) { OPLOGCALL("ctx /*%p*/, CGRectMake(%g, %g, %g, %g), ", ctx, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height) @@ -1879,15 +1951,15 @@ void CGContextEndTransparencyLayer(CGContextRef ctx) { OPLOGCALL("ctx /*%p*/", ctx) cairo_pattern_t *group = cairo_pop_group(ctx->ct); - + // Now undo the change to alpha and shadow state CGContextRestoreGState(ctx); - + // Paint the contents of the transparency layer. cairo_set_source(ctx->ct, group); cairo_pattern_destroy(group); cairo_paint_with_alpha(ctx->ct, ctx->add->alpha); - + // Undo the clipping (if any) cairo_restore(ctx->ct); OPRESTORELOGGING() @@ -1902,43 +1974,44 @@ CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef ctx) cairo_matrix_t cmat; cairo_get_matrix(ctx->ct, &cmat); cairo_matrix_invert(&cmat); - return CGAffineTransformMake(cmat.xx, cmat.yx, cmat.xy, cmat.yy, cmat.x0, cmat.y0); + return CGAffineTransformMake(cmat.xx, cmat.yx, cmat.xy, cmat.yy, cmat.x0, + cmat.y0); } CGPoint CGContextConvertPointToDeviceSpace(CGContextRef ctx, CGPoint point) { - return CGPointApplyAffineTransform(point, - CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); + return CGPointApplyAffineTransform(point, + CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); } CGPoint CGContextConvertPointToUserSpace(CGContextRef ctx, CGPoint point) { return CGPointApplyAffineTransform(point, - CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); + CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); } CGSize CGContextConvertSizeToDeviceSpace(CGContextRef ctx, CGSize size) { - return CGSizeApplyAffineTransform(size, - CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); + return CGSizeApplyAffineTransform(size, + CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); } CGSize CGContextConvertSizeToUserSpace(CGContextRef ctx, CGSize size) { - return CGSizeApplyAffineTransform(size, - CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); + return CGSizeApplyAffineTransform(size, + CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); } CGRect CGContextConvertRectToDeviceSpace(CGContextRef ctx, CGRect rect) { - return CGRectApplyAffineTransform(rect, - CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); + return CGRectApplyAffineTransform(rect, + CGContextGetUserSpaceToDeviceSpaceTransform(ctx)); } CGRect CGContextConvertRectToUserSpace(CGContextRef ctx, CGRect rect) { - return CGRectApplyAffineTransform(rect, - CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); + return CGRectApplyAffineTransform(rect, + CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx))); } void OpalContextSetScaleFactor(CGContextRef ctx, CGFloat scale) @@ -1954,20 +2027,22 @@ void OpalContextSetScaleFactor(CGContextRef ctx, CGFloat scale) // Shadow support /** - * Perform a box blur on a one dimensional strip of an 8-bit alpha image + * Perform a box blur on a one dimensional strip of an 8-bit alpha image */ static inline void blur_1D(unsigned char *input, unsigned char *output, - int stride, int width, int radius) + int stride, int width, int radius) { int i, sum = 0; - for (i = -radius; i <= radius; i++) { - sum += input[stride * MAX(0,MIN(width-1,i))]; - } - for (i = 0; i < width; i++) { - output[stride * i] = (sum / ((2*radius) + 1)); - sum += input[stride * MAX(0,MIN(width-1, i+1+radius))]; - sum -= input[stride * MAX(0,MIN(width-1, i-radius))]; - } + for (i = -radius; i <= radius; i++) + { + sum += input[stride * MAX(0,MIN(width-1,i))]; + } + for (i = 0; i < width; i++) + { + output[stride * i] = (sum / ((2*radius) + 1)); + sum += input[stride * MAX(0,MIN(width-1, i+1+radius))]; + sum -= input[stride * MAX(0,MIN(width-1, i-radius))]; + } } static void blur_alpha_image_surface(cairo_surface_t *surface, float radius) @@ -1985,7 +2060,7 @@ static void blur_alpha_image_surface(cairo_surface_t *surface, float radius) if (cairo_image_surface_get_format(surface) != CAIRO_FORMAT_A8) return; - + for (iteration = 0; iteration < 3; iteration++) { // Horizontal blur @@ -2013,37 +2088,37 @@ static void start_shadow(CGContextRef ctx) static void end_shadow(CGContextRef ctx, CGRect bounds) { cairo_pattern_t *pattern = cairo_pop_group(ctx->ct); - - // writeOut(pattern); - + +// writeOut(pattern); + cairo_save(ctx->ct); - + //#if 0 // Create the shadow mask - cairo_surface_t *alphaSurface = + cairo_surface_t *alphaSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 500, 250); - //ceil(bounds.size.width + 2*radius), - //ceil(bounds.size.height + 2*radius)); + //ceil(bounds.size.width + 2*radius), + //ceil(bounds.size.height + 2*radius)); cairo_t *alphaCt = cairo_create(alphaSurface); - //cairo_surface_set_device_offset(alphaSurface, 0, 250); + //cairo_surface_set_device_offset(alphaSurface, 0, 250); //cairo_scale(alphaCt, 1.0, -1.0); - + cairo_set_source(alphaCt, pattern); cairo_paint(alphaCt); cairo_surface_flush(alphaSurface); blur_alpha_image_surface(alphaSurface, ctx->add->shadow_radius); - + // Draw the shadow // cairo_set_source(ctx->ct, ctx->add->shadow_cp); cairo_set_source_rgba(ctx->ct, 0, 0, 0, 0.3); // FIXME hardcoded - + // FIXME: the offset is not supposed to be affected by the CTM - cairo_mask_surface(ctx->ct, alphaSurface, ctx->add->shadow_offset.width, - ctx->add->shadow_offset.height); - + cairo_mask_surface(ctx->ct, alphaSurface, ctx->add->shadow_offset.width, + ctx->add->shadow_offset.height); + // Draw the actual content cairo_set_source(ctx->ct, pattern); cairo_paint(ctx->ct); - + cairo_restore(ctx->ct); } diff --git a/Source/OpalGraphics/CGDataConsumer-private.h b/Source/OpalGraphics/CGDataConsumer-private.h index c7b4fe6..1395c7b 100644 --- a/Source/OpalGraphics/CGDataConsumer-private.h +++ b/Source/OpalGraphics/CGDataConsumer-private.h @@ -11,12 +11,12 @@ 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 @@ -24,4 +24,5 @@ #include "CoreGraphics/CGDataConsumer.h" -size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, size_t count); \ No newline at end of file +size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, + size_t count); \ No newline at end of file diff --git a/Source/OpalGraphics/CGDataConsumer.m b/Source/OpalGraphics/CGDataConsumer.m index b03cf41..14ba35e 100644 --- a/Source/OpalGraphics/CGDataConsumer.m +++ b/Source/OpalGraphics/CGDataConsumer.m @@ -11,12 +11,12 @@ 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 @@ -49,25 +49,26 @@ - (id) initWithCallbacks: (CGDataConsumerCallbacks)callbacks info: (void*)i - (void) dealloc { if (cb.releaseConsumer) - { - cb.releaseConsumer(info); - } - [super dealloc]; + { + cb.releaseConsumer(info); + } + [super dealloc]; } @end /* Opal-internal access */ -size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, size_t count) +size_t OPDataConsumerPutBytes(CGDataConsumerRef dc, const void *buffer, + size_t count) { if (NULL != dc) - { - return dc->cb.putBytes( - dc->info, - buffer, - count); - } + { + return dc->cb.putBytes( + dc->info, + buffer, + count); + } return 0; } @@ -82,10 +83,10 @@ static size_t opal_URLConsumerPutBytes( length: count freeWhenDone: NO]; // FIXME: catch exceptions? - [(NSFileHandle*)info writeData: data]; - + [(NSFileHandle*)info writeData: data]; + [data release]; - return count; + return count; } static void opal_URLConsumerReleaseInfo(void *info) @@ -97,9 +98,9 @@ static void opal_URLConsumerReleaseInfo(void *info) /* CFData consumer */ static size_t opal_CFDataConsumerPutBytes( - void *info, - const void *buffer, - size_t count) + void *info, + const void *buffer, + size_t count) { [(NSMutableData*)info appendBytes: buffer length: count]; return count; @@ -122,16 +123,18 @@ CGDataConsumerRef CGDataConsumerCreate( CGDataConsumerRef CGDataConsumerCreateWithCFData(CFMutableDataRef data) { - CGDataConsumerCallbacks opal_CFDataConsumerCallbacks = { - opal_CFDataConsumerPutBytes, opal_CFDataConsumerReleaseInfo + CGDataConsumerCallbacks opal_CFDataConsumerCallbacks = + { + opal_CFDataConsumerPutBytes, opal_CFDataConsumerReleaseInfo }; return CGDataConsumerCreate([data retain], &opal_CFDataConsumerCallbacks); } CGDataConsumerRef CGDataConsumerCreateWithURL(CFURLRef url) { - CGDataConsumerCallbacks opal_URLConsumerCallbacks = { - opal_URLConsumerPutBytes, opal_URLConsumerReleaseInfo + CGDataConsumerCallbacks opal_URLConsumerCallbacks = + { + opal_URLConsumerPutBytes, opal_URLConsumerReleaseInfo }; NSString *path = [(NSURL*)url path]; @@ -139,7 +142,8 @@ CGDataConsumerRef CGDataConsumerCreateWithURL(CFURLRef url) NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath: path]; if (handle == nil) { - [[NSFileManager defaultManager] createFileAtPath: path contents:nil attributes:nil]; + [[NSFileManager defaultManager] createFileAtPath: path contents: nil + attributes: nil]; handle = [NSFileHandle fileHandleForWritingAtPath: path]; } diff --git a/Source/OpalGraphics/CGDataProvider-private.h b/Source/OpalGraphics/CGDataProvider-private.h index 3b34d9d..cd7b9e8 100644 --- a/Source/OpalGraphics/CGDataProvider-private.h +++ b/Source/OpalGraphics/CGDataProvider-private.h @@ -13,12 +13,12 @@ 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 @@ -35,7 +35,8 @@ /* Sequential Access */ -size_t OPDataProviderGetBytes(CGDataProviderRef dp, void *buffer, size_t count); +size_t OPDataProviderGetBytes(CGDataProviderRef dp, void *buffer, + size_t count); off_t OPDataProviderSkipForward(CGDataProviderRef dp, off_t count); @@ -53,7 +54,7 @@ void OPDataProviderReleaseBytePointer( ); size_t OPDataProviderGetBytesAtPosition( - CGDataProviderRef dp, + CGDataProviderRef dp, void *buffer, off_t position, size_t count diff --git a/Source/OpalGraphics/CGDataProvider.m b/Source/OpalGraphics/CGDataProvider.m index a998561..6081ade 100644 --- a/Source/OpalGraphics/CGDataProvider.m +++ b/Source/OpalGraphics/CGDataProvider.m @@ -13,12 +13,12 @@ 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 @@ -48,7 +48,8 @@ - (void) rewind; - (size_t) size; - (const void *)bytePointer; - (void)releaseBytePointer: (const void *)pointer; -- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count; +- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: + (size_t)count; - (CFDataRef) copyData; @@ -84,7 +85,8 @@ - (void)releaseBytePointer: (const void *)pointer { [self doesNotRecognizeSelector: _cmd]; } -- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count +- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: + (size_t)count { [self doesNotRecognizeSelector: _cmd]; return (size_t)0; @@ -121,13 +123,13 @@ @implementation CGDataProviderDirect - (void) dealloc { if (releaseInfoCallback) - { - releaseInfoCallback(info); - } + { + releaseInfoCallback(info); + } [super dealloc]; } - - + + /* Opal internal access - Sequential */ - (size_t)getBytes: (void *)buffer count: (size_t)count @@ -136,9 +138,9 @@ - (size_t)getBytes: (void *)buffer count: (size_t)count const void *bytePointer = [self bytePointer]; memcpy(buffer, bytePointer + pos, bytesToCopy); [self releaseBytePointer: bytePointer]; - + pos += bytesToCopy; - + return bytesToCopy; } - (off_t)skipForward: (off_t)count @@ -160,28 +162,29 @@ - (size_t)size - (const void *)bytePointer { if (getBytePointerCallback) - { - return getBytePointerCallback(info); - } + { + return getBytePointerCallback(info); + } return NULL; } - (void)releaseBytePointer: (const void *)pointer { if (releaseBytePointerCallback) - { - releaseBytePointerCallback(info, pointer); - } + { + releaseBytePointerCallback(info, pointer); + } } -- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count +- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: + (size_t)count { if (getBytesAtOffsetCallback) - { - return getBytesAtOffsetCallback(info, buffer, position, count); - } + { + return getBytesAtOffsetCallback(info, buffer, position, count); + } else if (getBytesAtPositionCallback) - { - return getBytesAtPositionCallback(info, buffer, (int)position, count); - } + { + return getBytesAtPositionCallback(info, buffer, (int)position, count); + } return 0; } @@ -211,9 +214,9 @@ @implementation CGDataProviderSequential - (void) dealloc { if (releaseInfoCallback) - { - releaseInfoCallback(info); - } + { + releaseInfoCallback(info); + } [directBuffer release]; [super dealloc]; } @@ -223,30 +226,30 @@ - (void) dealloc - (size_t)getBytes: (void *)buffer count: (size_t)count { if (getBytesCallback) - { - return getBytesCallback(info, buffer, count); - } + { + return getBytesCallback(info, buffer, count); + } return 0; } - (off_t)skipForward: (off_t)count { if (skipBytesCallback) - { - skipBytesCallback(info, count); - return count; - } + { + skipBytesCallback(info, count); + return count; + } else if (skipForwardCallback) - { - return skipForwardCallback(info, count); - } + { + return skipForwardCallback(info, count); + } return 0; } - (void)rewind { if (rewindCallback) - { - rewindCallback(info); - } + { + rewindCallback(info); + } } /* Opal internal access - Direct */ @@ -254,20 +257,20 @@ - (void)rewind - (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]; + 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; } - [buf setLength: total]; - - directBuffer = buf; - } return directBuffer; } - (size_t)size @@ -282,10 +285,12 @@ - (void)releaseBytePointer: (const void *)pointer { ; } -- (size_t) getBytes: (void *)buffer atPosition: (off_t)position count: (size_t)count +- (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)]; + [[self directBuffer] getBytes: buffer range: NSMakeRange(position, + bytesToCopy)]; return bytesToCopy; } @@ -325,13 +330,14 @@ size_t OPDataProviderGetSize(CGDataProviderRef dp) return [dp bytePointer]; } -void OPDataProviderReleaseBytePointer(CGDataProviderRef dp, const void *pointer) +void OPDataProviderReleaseBytePointer(CGDataProviderRef dp, + const void *pointer) { [dp releaseBytePointer: pointer]; } size_t OPDataProviderGetBytesAtPositionCallback( - CGDataProviderRef dp, + CGDataProviderRef dp, void *buffer, off_t position, size_t count) @@ -346,7 +352,8 @@ size_t OPDataProviderGetBytesAtPositionCallback( /* Data callbacks */ -typedef struct DataInfo { +typedef struct DataInfo +{ size_t size; const void *data; CGDataProviderReleaseDataCallback releaseData; @@ -360,7 +367,7 @@ size_t OPDataProviderGetBytesAtPositionCallback( static void opal_DataReleaseBytePointer(void *info, const void *pointer) { ; -} +} static size_t opal_DataGetBytesAtPosition( void *info, @@ -378,12 +385,13 @@ static void opal_DataReleaseInfo(void *info) free((DataInfo*)info); } -static const CGDataProviderDirectCallbacks opal_DataCallbacks = { - 0, - opal_DataGetBytePointer, - opal_DataReleaseBytePointer, - opal_DataGetBytesAtPosition, - opal_DataReleaseInfo +static const CGDataProviderDirectCallbacks opal_DataCallbacks = +{ + 0, + opal_DataGetBytePointer, + opal_DataReleaseBytePointer, + opal_DataGetBytesAtPosition, + opal_DataReleaseInfo }; /* CFData callbacks */ @@ -396,7 +404,7 @@ static void opal_DataReleaseInfo(void *info) static void opal_CFDataReleaseBytePointer(void *info, const void *pointer) { ; -} +} static size_t opal_CFDataGetBytesAtPosition( void *info, @@ -405,7 +413,7 @@ static size_t opal_CFDataGetBytesAtPosition( size_t count) { size_t bytesToCopy = MIN(count, ([(NSData*)info length] - position)); - [(NSData*)info getBytes:buffer range: NSMakeRange(position, bytesToCopy)]; + [(NSData*)info getBytes: buffer range: NSMakeRange(position, bytesToCopy)]; return bytesToCopy; } @@ -414,12 +422,13 @@ static void opal_CFDataReleaseInfo(void *info) [(NSData*)info release]; } -static const CGDataProviderDirectCallbacks opal_CFDataCallbacks = { - 0, - opal_CFDataGetBytePointer, - opal_CFDataReleaseBytePointer, - opal_CFDataGetBytesAtPosition, - opal_CFDataReleaseInfo +static const CGDataProviderDirectCallbacks opal_CFDataCallbacks = +{ + 0, + opal_CFDataGetBytePointer, + opal_CFDataReleaseBytePointer, + opal_CFDataGetBytesAtPosition, + opal_CFDataReleaseInfo }; /* File callbacks */ @@ -433,7 +442,7 @@ static off_t opal_fileSkipForward(void *info, off_t count) { fseek((FILE*)info, count, SEEK_CUR); return count; -} +} static void opal_fileRewind(void *info) { @@ -445,12 +454,13 @@ static void opal_fileReleaseInfo(void *info) fclose((FILE*)info); } -static const CGDataProviderSequentialCallbacks opal_fileCallbacks = { - 0, - opal_fileGetBytes, - opal_fileSkipForward, - opal_fileRewind, - opal_fileReleaseInfo +static const CGDataProviderSequentialCallbacks opal_fileCallbacks = +{ + 0, + opal_fileGetBytes, + opal_fileSkipForward, + opal_fileRewind, + opal_fileReleaseInfo }; @@ -463,13 +473,13 @@ static void opal_fileReleaseInfo(void *info) CFDataRef CGDataProviderCopyData(CGDataProviderRef provider) { - return [(CGDataProvider*)provider copyData]; + return [(CGDataProvider*)provider copyData]; } CGDataProviderRef CGDataProviderCreateDirect( void *info, off_t size, - const CGDataProviderDirectCallbacks *callbacks) + const CGDataProviderDirectCallbacks *callbacks) { CGDataProviderDirect *provider = [[CGDataProviderDirect alloc] init]; provider->info = info; @@ -478,7 +488,7 @@ CGDataProviderRef CGDataProviderCreateDirect( provider->releaseBytePointerCallback = callbacks->releaseBytePointer; provider->getBytesAtPositionCallback = callbacks->getBytesAtPosition; provider->releaseInfoCallback = callbacks->releaseInfo; - + return provider; } @@ -497,7 +507,7 @@ CGDataProviderRef CGDataProviderCreateDirectAccess( provider->releaseBytePointerCallback = callbacks->releaseBytePointer; provider->getBytesAtOffsetCallback = callbacks->getBytes; provider->releaseInfoCallback = callbacks->releaseProvider; - + return provider; } @@ -511,7 +521,7 @@ CGDataProviderRef CGDataProviderCreateSequential( provider->skipForwardCallback = callbacks->skipForward; provider->rewindCallback = callbacks->rewind; provider->releaseInfoCallback = callbacks->releaseInfo; - + return provider; } @@ -529,7 +539,7 @@ CGDataProviderRef CGDataProviderCreate( provider->skipBytesCallback = callbacks->skipBytes; provider->rewindCallback = callbacks->rewind; provider->releaseInfoCallback = callbacks->releaseProvider; - + return provider; } @@ -543,13 +553,14 @@ CGDataProviderRef CGDataProviderCreateWithData( 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); + return CGDataProviderCreateDirect([(NSData*)data retain], [(NSData*)data + length], &opal_CFDataCallbacks); } CGDataProviderRef CGDataProviderCreateWithURL(CFURLRef url) @@ -561,9 +572,9 @@ CGDataProviderRef CGDataProviderCreateWithFilename(const char *filename) { FILE *info = fopen(filename, "rb"); if (NULL == info) - { - return nil; - } + { + return nil; + } return CGDataProviderCreateSequential(info, &opal_fileCallbacks); } diff --git a/Source/OpalGraphics/CGFont.m b/Source/OpalGraphics/CGFont.m index ac67927..1e56a67 100644 --- a/Source/OpalGraphics/CGFont.m +++ b/Source/OpalGraphics/CGFont.m @@ -13,12 +13,12 @@ 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 @@ -133,16 +133,16 @@ + (CGFontRef) createWithPlatformFont: (void *)platformFontReference } - (bool) getGlyphAdvances: (const CGGlyph[])glyphs - : (size_t)count - : (int[]) advances +: (size_t)count +: (int[]) advances { [self doesNotRecognizeSelector: _cmd]; return nil; } - (bool) getGlyphBBoxes: (const CGGlyph[])glyphs - : (size_t)count - : (CGRect[])bboxes +: (size_t)count +: (CGRect[])bboxes { [self doesNotRecognizeSelector: _cmd]; return nil; @@ -156,7 +156,7 @@ - (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName - (CGGlyph) glyphWithCharacter: (unichar)character { - [self doesNotRecognizeSelector: _cmd]; + [self doesNotRecognizeSelector: _cmd]; return 0; } @@ -228,7 +228,7 @@ CFDataRef CGFontCreatePostScriptSubset( size_t count, const CGGlyph encoding[256]) { - return [font createPostScriptSubset: name : format : glyphs : count : encoding]; + return [font createPostScriptSubset: name: format: glyphs: count: encoding]; } CGFontRef CGFontCreateWithDataProvider(CGDataProviderRef provider) @@ -279,7 +279,7 @@ bool CGFontGetGlyphAdvances( size_t count, int advances[]) { - return [font getGlyphAdvances: glyphs : count : advances]; + return [font getGlyphAdvances: glyphs: count: advances]; } bool CGFontGetGlyphBBoxes( @@ -288,7 +288,7 @@ bool CGFontGetGlyphBBoxes( size_t count, CGRect bboxes[]) { - return [font getGlyphBBoxes: glyphs : count : bboxes]; + return [font getGlyphBBoxes: glyphs: count: bboxes]; } CGGlyph CGFontGetGlyphWithGlyphName(CGFontRef font, CFStringRef glyphName) diff --git a/Source/OpalGraphics/CGFunction.m b/Source/OpalGraphics/CGFunction.m index 57f576e..afa355d 100644 --- a/Source/OpalGraphics/CGFunction.m +++ b/Source/OpalGraphics/CGFunction.m @@ -1,22 +1,22 @@ /** CGFunction - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -46,9 +46,9 @@ CGFunctionRef CGFunctionCreate( const CGFunctionCallbacks *callbacks) { CGFunctionRef func = [[CGFunction alloc] init]; - + //FIXME - + return func; } diff --git a/Source/OpalGraphics/CGGeometry.m b/Source/OpalGraphics/CGGeometry.m index 2b0bfa0..1e0e4e6 100644 --- a/Source/OpalGraphics/CGGeometry.m +++ b/Source/OpalGraphics/CGGeometry.m @@ -11,12 +11,12 @@ 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 @@ -88,7 +88,7 @@ CGRect CGRectIntersection(CGRect r1, CGRect 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) + 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); @@ -123,46 +123,59 @@ void CGRectDivide(CGRect rect, CGRect *slice, CGRect *remainder, 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; - } + 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) @@ -180,8 +193,10 @@ CGRect CGRectUnion(CGRect r1, CGRect r2) 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); + 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; } @@ -189,9 +204,10 @@ CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point) { // FIXME: implement return nil; -} +} -bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point) +bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, + CGPoint *point) { // FIXME: implement return false; diff --git a/Source/OpalGraphics/CGGradient-private.h b/Source/OpalGraphics/CGGradient-private.h index 7e9c44d..5723eb1 100644 --- a/Source/OpalGraphics/CGGradient-private.h +++ b/Source/OpalGraphics/CGGradient-private.h @@ -1,29 +1,29 @@ /** CGGradient - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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); diff --git a/Source/OpalGraphics/CGGradient.m b/Source/OpalGraphics/CGGradient.m index 48a8cc1..ff3c04f 100644 --- a/Source/OpalGraphics/CGGradient.m +++ b/Source/OpalGraphics/CGGradient.m @@ -1,22 +1,22 @@ /** CGGradient - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -26,7 +26,7 @@ #import #include "CoreGraphics/CGGradient.h" #include "CoreGraphics/CGColor.h" - + @interface CGGradient : NSObject { @public @@ -41,22 +41,22 @@ @interface CGGradient : NSObject @implementation CGGradient - (id) initWithComponents: (const CGFloat[])comps - locations: (const CGFloat[])locs - count: (size_t) cnt - colorspace: (CGColorSpaceRef)cspace + 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; + + return self; } - (void) dealloc { @@ -67,7 +67,7 @@ - (void) dealloc } - (id) copyWithZone: (NSZone*)zone { - return [self retain]; + return [self retain]; } @end @@ -84,7 +84,7 @@ CGColorSpaceRef OPGradientGetColorSpace(CGGradientRef g) } const CGFloat *OPGradientGetLocations(CGGradientRef g) { - return g->locations; + return g->locations; } size_t OPGradientGetCount(CGGradientRef g) { @@ -101,7 +101,8 @@ CGGradientRef CGGradientCreateWithColorComponents( const CGFloat locations[], size_t count) { - return [[CGGradient alloc] initWithComponents: components locations: locations count: count colorspace: cs]; + return [[CGGradient alloc] initWithComponents: components locations: locations + count: count colorspace: cs]; } CGGradientRef CGGradientCreateWithColors( @@ -113,10 +114,11 @@ CGGradientRef CGGradientCreateWithColors( size_t cs_numcomps = CGColorSpaceGetNumberOfComponents(cs) + 1; CGFloat components[count * cs_numcomps]; for (int i=0; i", msg); return; } - NSDebugLLog(@"Opal", @"%@: (%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])); + NSDebugLLog(@"Opal", @"%@: (%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])); } @implementation CGImage @@ -63,20 +64,20 @@ - (id) initWithWidth: (size_t)aWidth { self = [super init]; if (nil == self) - { - [super release]; - return nil; - } + { + [super release]; + return nil; + } size_t numComponents; if ((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaOnly) - { - numComponents = 0; - } + { + numComponents = 0; + } else - { - numComponents = CGColorSpaceGetNumberOfComponents(aColorspace); - } + { + numComponents = CGColorSpaceGetNumberOfComponents(aColorspace); + } const bool hasAlpha = ((aBitmapInfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedLast) || @@ -88,41 +89,42 @@ - (id) initWithWidth: (size_t)aWidth const size_t numComponentsIncludingAlpha = numComponents + (hasAlpha ? 1 : 0); if (aBitsPerComponent < 1 || aBitsPerComponent > 32) - { - NSLog(@"Unsupported bitsPerComponent: %d", aBitsPerComponent); - [self release]; - return nil; - } + { + 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; - } + { + 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"); + // 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; } - for(i = 0; i < 2 * numComponents; i++) + + if (aDecode && numComponents) { - self->decode[i] = aDecode[i]; + 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; @@ -157,7 +159,11 @@ - (void) dealloc - (NSString *)description { - return [NSString stringWithFormat: @"", self, (int)width, (int)height, (int)bitsPerComponent, (int)bitsPerPixel, (int)bytesPerRow, dp, (int)shouldInterpolate, crop.origin.x, crop.origin.y, crop.size.width, crop.size.height]; + return [NSString stringWithFormat: + @"", + self, (int)width, (int)height, (int)bitsPerComponent, (int)bitsPerPixel, + (int)bytesPerRow, dp, (int)shouldInterpolate, crop.origin.x, crop.origin.y, + crop.size.width, crop.size.height]; } @end @@ -207,12 +213,12 @@ CGImageRef CGImageMaskCreate( provider: provider decode: decode shouldInterpolate: shouldInterpolate - intent: 0]; // FIXME + intent: 0]; // FIXME if (!img) - { - return nil; - } + { + return nil; + } img->ismask = true; @@ -234,26 +240,26 @@ CGImageRef CGImageCreateCopyWithColorSpace( // FIXME: is this supposed to convert pixel data? if (image->ismask || - CGColorSpaceGetNumberOfComponents(image->cspace) - != CGColorSpaceGetNumberOfComponents(colorspace)) - { - return nil; - } + 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); - } + { + 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); - } + { + new->surf = cairo_surface_reference(image->surf); + } return new; } @@ -262,9 +268,9 @@ CGImageRef CGImageCreateWithImageInRect( 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); + 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 @@ -273,9 +279,9 @@ CGImageRef CGImageCreateWithImageInRect( new->crop = rect; if (image->surf) - { - new->surf = cairo_surface_reference(image->surf); - } + { + new->surf = cairo_surface_reference(image->surf); + } return new; } @@ -296,35 +302,36 @@ static CGImageRef createWithDataProvider( CFStringRef type) { NSDictionary *opts = [[NSDictionary alloc] initWithObjectsAndKeys: - type, kCGImageSourceTypeIdentifierHint, - nil]; + 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); + if (CGImageSourceGetCount(src) >= 1) + { + img = CGImageSourceCreateImageAtIndex(src, 0, opts); + } + else + { + NSLog(@"No images found"); + } } - else + else { - NSLog(@"No images found"); + NSLog(@"Unexpected type of image. expected %@, found %@", type, + CGImageSourceGetType(src)); } - } - 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??? - } + { + img->shouldInterpolate = shouldInterpolate; + img->intent = intent; + // FIXME: decode array??? + } return img; } @@ -340,7 +347,8 @@ CGImageRef CGImageCreateWithJPEGDataProvider( // 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"); + return createWithDataProvider(source, decode, shouldInterpolate, intent, + @"public.jpeg"); } CGImageRef CGImageCreateWithPNGDataProvider( @@ -349,7 +357,8 @@ CGImageRef CGImageCreateWithPNGDataProvider( bool shouldInterpolate, CGColorRenderingIntent intent) { - return createWithDataProvider(source, decode, shouldInterpolate, intent, @"public.png"); + return createWithDataProvider(source, decode, shouldInterpolate, intent, + @"public.png"); } CFTypeID CGImageGetTypeID() @@ -440,85 +449,92 @@ CGColorRenderingIntent CGImageGetRenderingIntent(CGImageRef image) * * */ -cairo_surface_t *opal_CGImageGetSurfaceForImage(CGImageRef img, cairo_surface_t *contextSurface) +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 = kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst; - 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, + if (NULL == img->surf) + { + cairo_surface_t *memSurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 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); - } + 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 = kCGBitmapByteOrder32Host | + kCGImageAlphaPremultipliedFirst; + 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 (NULL == image) + { + return CGRectMake(0, 0, 0, 0); + } - if (CGRectIsNull(image->crop)) { - return CGRectMake(0, 0, image->width, image->height); - } else { - return image->crop; - } + if (CGRectIsNull(image->crop)) + { + return CGRectMake(0, 0, image->width, image->height); + } + else + { + return image->crop; + } } diff --git a/Source/OpalGraphics/CGImageDestination.m b/Source/OpalGraphics/CGImageDestination.m index f80bd32..a18bf2e 100644 --- a/Source/OpalGraphics/CGImageDestination.m +++ b/Source/OpalGraphics/CGImageDestination.m @@ -4,22 +4,22 @@ Copyright (C) 2010 Free Software Foundation, Inc. Author: Eric Wasylishen - + 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 @@ -30,8 +30,10 @@ /* Constants */ -const CFStringRef kCGImageDestinationLossyCompressionQuality = @"kCGImageDestinationLossyCompressionQuality"; -const CFStringRef kCGImageDestinationBackgroundColor = @"kCGImageDestinationBackgroundColor"; +const CFStringRef kCGImageDestinationLossyCompressionQuality = + @"kCGImageDestinationLossyCompressionQuality"; +const CFStringRef kCGImageDestinationBackgroundColor = + @"kCGImageDestinationBackgroundColor"; static NSMutableArray *destinationClasses = nil; @@ -41,17 +43,18 @@ @implementation CGImageDestination + (void) registerDestinationClass: (Class)cls { if (nil == destinationClasses) - { - destinationClasses = [[NSMutableArray alloc] init]; - } + { + destinationClasses = [[NSMutableArray alloc] init]; + } if ([cls isSubclassOfClass: [CGImageDestination class]]) - { - [destinationClasses addObject: cls]; - } + { + [destinationClasses addObject: cls]; + } else - { - [NSException raise: NSInvalidArgumentException format: @"+[CGImageDestination registerDestinationClass:] called with invalid class"]; - } + { + [NSException raise: NSInvalidArgumentException format: + @"+[CGImageDestination registerDestinationClass:] called with invalid class"]; + } } + (NSArray*) destinationClasses { @@ -61,13 +64,13 @@ + (Class) destinationClassForType: (NSString*)type { NSUInteger cnt = [destinationClasses count]; for (NSUInteger i=0; i - + 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 @@ -30,13 +30,19 @@ /* Constants */ -const CFStringRef kCGImageSourceTypeIdentifierHint = @"kCGImageSourceTypeIdentifierHint"; -const CFStringRef kCGImageSourceShouldAllowFloat = @"kCGImageSourceShouldAllowFloat"; +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"; +const CFStringRef kCGImageSourceCreateThumbnailFromImageIfAbsent = + @"kCGImageSourceCreateThumbnailFromImageIfAbsent"; +const CFStringRef kCGImageSourceCreateThumbnailFromImageAlways = + @"kCGImageSourceCreateThumbnailFromImageAlways"; +const CFStringRef kCGImageSourceThumbnailMaxPixelSize = + @"kCGImageSourceThumbnailMaxPixelSize"; +const CFStringRef kCGImageSourceCreateThumbnailWithTransform = + @"kCGImageSourceCreateThumbnailWithTransform"; static NSMutableArray *sourceClasses = nil; @@ -46,17 +52,18 @@ @implementation CGImageSource + (void) registerSourceClass: (Class)cls { if (nil == sourceClasses) - { - sourceClasses = [[NSMutableArray alloc] init]; - } + { + sourceClasses = [[NSMutableArray alloc] init]; + } if ([cls isSubclassOfClass: [CGImageSource class]]) - { - [sourceClasses addObject: cls]; - } + { + [sourceClasses addObject: cls]; + } else - { - [NSException raise: NSInvalidArgumentException format: @"+[CGImageSource registerSourceClass:] called with invalid class"]; - } + { + [NSException raise: NSInvalidArgumentException format: + @"+[CGImageSource registerSourceClass:] called with invalid class"]; + } } + (NSArray*) sourceClasses { @@ -83,7 +90,8 @@ - (NSDictionary*)propertiesWithOptions: (NSDictionary*)options [self doesNotRecognizeSelector: _cmd]; return nil; } -- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: (size_t)index +- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: + (size_t)index { [self doesNotRecognizeSelector: _cmd]; return nil; @@ -98,7 +106,8 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)options [self doesNotRecognizeSelector: _cmd]; return nil; } -- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)options +- (CGImageRef)createThumbnailAtIndex: (size_t)index options: + (NSDictionary*)options { [self doesNotRecognizeSelector: _cmd]; return nil; @@ -118,17 +127,18 @@ - (NSString*)type [self doesNotRecognizeSelector: _cmd]; return nil; } -- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate +- (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 + * to create a real CGImageSource, then forwards messages to the real * image source. */ @interface CGImageSourceIncremental : CGImageSource @@ -161,7 +171,8 @@ - (NSDictionary*)propertiesWithOptions: (NSDictionary*)options { return [[self realSource] propertiesWithOptions: options]; } -- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: (size_t)index +- (NSDictionary*)propertiesWithOptions: (NSDictionary*)options atIndex: + (size_t)index { return [[self realSource] propertiesWithOptions: options atIndex: index]; } @@ -173,41 +184,43 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)options { return [[self realSource] createImageAtIndex: index options: options]; } -- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)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 kCGImageStatusReadingHeader; // FIXME ?? + } return [[self realSource] status]; } - (CGImageSourceStatus)statusAtIndex: (size_t)index { if (![self realSource]) - { - return kCGImageStatusReadingHeader; // FIXME ?? - } + { + return kCGImageStatusReadingHeader; // FIXME ?? + } return [[self realSource] statusAtIndex: index]; } - (NSString*)type { return [[self realSource] type]; } -- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate +- (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); - } + { + // See if there is enough data to create a real image source + real = CGImageSourceCreateWithDataProvider(provider, opts); + } else - { - [[self realSource] updateDataProvider: provider finalUpdate: finalUpdate]; - } + { + [[self realSource] updateDataProvider: provider finalUpdate: finalUpdate]; + } } @end @@ -239,35 +252,35 @@ CGImageSourceRef CGImageSourceCreateWithDataProvider( { const NSUInteger cnt = [sourceClasses count]; NSString *possibleType = [options valueForKey: - kCGImageSourceTypeIdentifierHint]; - + kCGImageSourceTypeIdentifierHint]; + if (possibleType) - { - for (NSUInteger i=0; iCGLayer - + C Interface to graphics drawing library - + Copyright (C) 2009 Free Software Foundation, Inc. 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 @@ -53,20 +53,21 @@ CGLayerRef CGLayerCreateWithContext( { 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_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->ctxt = opal_new_CGContext(layerSurface, CGSizeMake(ceil(fabs(w)), + ceil(fabs(h)))); layer->size = size; - + return layer; } @@ -101,7 +102,7 @@ void CGContextDrawLayerInRect( CGLayerRef layer) { opal_draw_surface_in_rect(destCtxt, rect, cairo_get_target(layer->ctxt->ct), - CGRectMake(0, 0, layer->size.width, layer->size.height)); + CGRectMake(0, 0, layer->size.width, layer->size.height)); } void CGContextDrawLayerAtPoint( @@ -110,7 +111,7 @@ void CGContextDrawLayerAtPoint( CGLayerRef layer) { CGContextDrawLayerInRect(destCtxt, - CGRectMake(point.x, point.y, layer->size.width, layer->size.height), - layer); + CGRectMake(point.x, point.y, layer->size.width, layer->size.height), + layer); } diff --git a/Source/OpalGraphics/CGPDFArray.m b/Source/OpalGraphics/CGPDFArray.m index e190d88..a3fa692 100644 --- a/Source/OpalGraphics/CGPDFArray.m +++ b/Source/OpalGraphics/CGPDFArray.m @@ -1,22 +1,22 @@ /** CGPDFArray - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -25,12 +25,14 @@ #import #include "CoreGraphics/CGPDFArray.h" -bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, CGPDFArrayRef *value) +bool CGPDFArrayGetArray(CGPDFArrayRef array, size_t index, + CGPDFArrayRef *value) { return false; } -bool CGPDFArrayGetBoolean(CGPDFArrayRef array, size_t index, CGPDFBoolean *value) +bool CGPDFArrayGetBoolean(CGPDFArrayRef array, size_t index, + CGPDFBoolean *value) { return false; } @@ -40,12 +42,14 @@ size_t CGPDFArrayGetCount(CGPDFArrayRef array) return 0; } -bool CGPDFArrayGetDictionary(CGPDFArrayRef array, size_t index, CGPDFDictionaryRef *value) +bool CGPDFArrayGetDictionary(CGPDFArrayRef array, size_t index, + CGPDFDictionaryRef *value) { return false; } -bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, CGPDFInteger *value) +bool CGPDFArrayGetInteger(CGPDFArrayRef array, size_t index, + CGPDFInteger *value) { return false; } @@ -65,17 +69,20 @@ bool CGPDFArrayGetNumber(CGPDFArrayRef array, size_t index, CGPDFReal *value) return false; } -bool CGPDFArrayGetObject(CGPDFArrayRef array, size_t index, CGPDFObjectRef *value) +bool CGPDFArrayGetObject(CGPDFArrayRef array, size_t index, + CGPDFObjectRef *value) { return false; } -bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, CGPDFStreamRef *value) +bool CGPDFArrayGetStream(CGPDFArrayRef array, size_t index, + CGPDFStreamRef *value) { return false; } -bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, CGPDFStringRef *value) +bool CGPDFArrayGetString(CGPDFArrayRef array, size_t index, + CGPDFStringRef *value) { return false; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFContentStream.m b/Source/OpalGraphics/CGPDFContentStream.m index f35dbb0..66ef590 100644 --- a/Source/OpalGraphics/CGPDFContentStream.m +++ b/Source/OpalGraphics/CGPDFContentStream.m @@ -1,22 +1,22 @@ /** CGPDFContentStream - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -27,7 +27,7 @@ CGPDFContentStreamRef CGPDFContentStreamCreateWithPage(CGPDFPageRef page) { - return nil; + return nil; } CGPDFContentStreamRef CGPDFContentStreamCreateWithStream( @@ -58,5 +58,5 @@ CGPDFContentStreamRef CGPDFContentStreamRetain(CGPDFContentStreamRef stream) void CGPDFContentStreamRelease(CGPDFContentStreamRef stream) { - + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFContext.m b/Source/OpalGraphics/CGPDFContext.m index 3c217ce..44ae62c 100644 --- a/Source/OpalGraphics/CGPDFContext.m +++ b/Source/OpalGraphics/CGPDFContext.m @@ -11,12 +11,12 @@ 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 @@ -46,7 +46,8 @@ const CFStringRef kCGPDFContextOutputIntents = @"kCGPDFContextOutputIntents"; const CFStringRef kCGPDFContextSubject = @"kCGPDFContextSubject"; const CFStringRef kCGPDFContextKeywords = @"kCGPDFContextKeywords"; -const CFStringRef kCGPDFContextEncryptionKeyLength = @"kCGPDFContextEncryptionKeyLength"; +const CFStringRef kCGPDFContextEncryptionKeyLength = + @"kCGPDFContextEncryptionKeyLength"; const CFStringRef kCGPDFContextMediaBox = @"kCGPDFContextMediaBox"; const CFStringRef kCGPDFContextCropBox = @"kCGPDFContextCropBox"; @@ -55,11 +56,13 @@ const CFStringRef kCGPDFContextArtBox = @"kCGPDFContextArtBox"; const CFStringRef kCGPDFXOutputIntentSubtype = @"kCGPDFXOutputIntentSubtype"; -const CFStringRef kCGPDFXOutputConditionIdentifier = @"kCGPDFXOutputConditionIdentifier"; +const CFStringRef kCGPDFXOutputConditionIdentifier = + @"kCGPDFXOutputConditionIdentifier"; const CFStringRef kCGPDFXOutputCondition = @"kCGPDFXOutputCondition"; const CFStringRef kCGPDFXRegistryName = @"kCGPDFXRegistryName"; const CFStringRef kCGPDFXInfo = @"kCGPDFXInfo"; -const CFStringRef kCGPDFXDestinationOutputProfile = @"kCGPDFXDestinationOutputProfile"; +const CFStringRef kCGPDFXDestinationOutputProfile = + @"kCGPDFXDestinationOutputProfile"; /* Functions */ @@ -80,12 +83,13 @@ 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; - } + if (cret) + { + NSLog(@"CGPDFContextClose status: %s", cairo_status_to_string(cret)); + return; + } } static cairo_status_t opal_CGPDFContextWriteFunction( @@ -110,22 +114,26 @@ CGContextRef CGPDFContextCreate( CFDictionaryRef auxiliaryInfo) { CGRect box; - if (mediaBox == NULL) { - box = CGRectMake(0, 0, 8.5 * 72, 11 * 72); - } else { - box = *mediaBox; - } - + 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); - + 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; } @@ -145,12 +153,13 @@ 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; - } + if (cret) + { + NSLog(@"CGPDFContextEndPage status: %s", cairo_status_to_string(cret)); + return; + } } void CGPDFContextSetDestinationForRect( diff --git a/Source/OpalGraphics/CGPDFDictionary.m b/Source/OpalGraphics/CGPDFDictionary.m index b738654..2a3dc8f 100644 --- a/Source/OpalGraphics/CGPDFDictionary.m +++ b/Source/OpalGraphics/CGPDFDictionary.m @@ -1,22 +1,22 @@ /** CGPDFDictionary - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -26,9 +26,10 @@ #include "CoreGraphics/CGPDFDictionary.h" -void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, CGPDFDictionaryApplierFunction function, void *info) +void CGPDFDictionaryApplyFunction(CGPDFDictionaryRef dict, + CGPDFDictionaryApplierFunction function, void *info) { - + } size_t CGPDFDictionaryGetCount(CGPDFDictionaryRef dict) @@ -36,47 +37,56 @@ size_t CGPDFDictionaryGetCount(CGPDFDictionaryRef dict) return 0; } -bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, CGPDFArrayRef *value) +bool CGPDFDictionaryGetArray(CGPDFDictionaryRef dict, const char *key, + CGPDFArrayRef *value) { return false; } -bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, CGPDFBoolean *value) +bool CGPDFDictionaryGetBoolean(CGPDFDictionaryRef dict, const char *key, + CGPDFBoolean *value) { return false; } -bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, CGPDFDictionaryRef *value) +bool CGPDFDictionaryGetDictionary(CGPDFDictionaryRef dict, const char *key, + CGPDFDictionaryRef *value) { return false; } -bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, CGPDFInteger *value) +bool CGPDFDictionaryGetInteger(CGPDFDictionaryRef dict, const char *key, + CGPDFInteger *value) { return false; } -bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, const char **value) +bool CGPDFDictionaryGetName(CGPDFDictionaryRef dict, const char *key, + const char **value) { return false; } -bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, CGPDFReal *value) +bool CGPDFDictionaryGetNumber(CGPDFDictionaryRef dict, const char *key, + CGPDFReal *value) { return false; } -bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, CGPDFObjectRef *value) +bool CGPDFDictionaryGetObject(CGPDFDictionaryRef dict, const char *key, + CGPDFObjectRef *value) { return false; } -bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, CGPDFStreamRef *value) +bool CGPDFDictionaryGetStream(CGPDFDictionaryRef dict, const char *key, + CGPDFStreamRef *value) { return false; } -bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, CGPDFStringRef *value) +bool CGPDFDictionaryGetString(CGPDFDictionaryRef dict, const char *key, + CGPDFStringRef *value) { return false; } diff --git a/Source/OpalGraphics/CGPDFDocument.m b/Source/OpalGraphics/CGPDFDocument.m index 0474700..fe55d0f 100644 --- a/Source/OpalGraphics/CGPDFDocument.m +++ b/Source/OpalGraphics/CGPDFDocument.m @@ -1,22 +1,22 @@ /** CGPDFDocument - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -42,7 +42,7 @@ CGPDFDocumentRef CGPDFDocumentRetain(CGPDFDocumentRef document) void CGPDFDocumentRelease(CGPDFDocumentRef document) { - + } int CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document) diff --git a/Source/OpalGraphics/CGPDFObject.m b/Source/OpalGraphics/CGPDFObject.m index 7fef900..9b71e07 100644 --- a/Source/OpalGraphics/CGPDFObject.m +++ b/Source/OpalGraphics/CGPDFObject.m @@ -1,22 +1,22 @@ /** CGPDFObject - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -30,7 +30,8 @@ CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object) return kCGPDFObjectTypeNull; } -bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, void *value) +bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, + void *value) { return false; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFOperatorTable.m b/Source/OpalGraphics/CGPDFOperatorTable.m index 8fc4205..14e963f 100644 --- a/Source/OpalGraphics/CGPDFOperatorTable.m +++ b/Source/OpalGraphics/CGPDFOperatorTable.m @@ -1,22 +1,22 @@ /** CGPDFOperatorTable - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -35,7 +35,7 @@ void CGPDFOperatorTableSetCallback( const char *name, CGPDFOperatorCallback callback) { - + } CGPDFOperatorTableRef CGPDFOperatorTableRetain(CGPDFOperatorTableRef table) @@ -45,5 +45,5 @@ CGPDFOperatorTableRef CGPDFOperatorTableRetain(CGPDFOperatorTableRef table) void CGPDFOperatorTableRelease(CGPDFOperatorTableRef table) { - + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFPage.m b/Source/OpalGraphics/CGPDFPage.m index 43ae15f..7361d84 100644 --- a/Source/OpalGraphics/CGPDFPage.m +++ b/Source/OpalGraphics/CGPDFPage.m @@ -1,22 +1,22 @@ /** CGPDFPage - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -67,10 +67,10 @@ CFTypeID CGPDFPageGetTypeID(void) CGPDFPageRef CGPDFPageRetain(CGPDFPageRef page) { - return nil; + return nil; } void CGPDFPageRelease(CGPDFPageRef page) { - + } diff --git a/Source/OpalGraphics/CGPDFScanner.m b/Source/OpalGraphics/CGPDFScanner.m index 3a38bc9..6f7220e 100644 --- a/Source/OpalGraphics/CGPDFScanner.m +++ b/Source/OpalGraphics/CGPDFScanner.m @@ -1,22 +1,22 @@ /** CGPDFScanner - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -53,7 +53,8 @@ bool CGPDFScannerPopBoolean(CGPDFScannerRef scanner, CGPDFBoolean *value) return false; } -bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, CGPDFDictionaryRef *value) +bool CGPDFScannerPopDictionary(CGPDFScannerRef scanner, + CGPDFDictionaryRef *value) { return false; } @@ -95,5 +96,5 @@ CGPDFScannerRef CGPDFScannerRetain(CGPDFScannerRef scanner) void CGPDFScannerRelease(CGPDFScannerRef scanner) { - + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFStream.m b/Source/OpalGraphics/CGPDFStream.m index 2f58794..95035d4 100644 --- a/Source/OpalGraphics/CGPDFStream.m +++ b/Source/OpalGraphics/CGPDFStream.m @@ -1,22 +1,22 @@ /** CGPDFStream - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 diff --git a/Source/OpalGraphics/CGPDFString.m b/Source/OpalGraphics/CGPDFString.m index 9781d72..d29cf3b 100644 --- a/Source/OpalGraphics/CGPDFString.m +++ b/Source/OpalGraphics/CGPDFString.m @@ -1,27 +1,27 @@ /** CGPDFString - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 #include "CoreGraphics/CGPDFString.h" diff --git a/Source/OpalGraphics/CGPSConverter.m b/Source/OpalGraphics/CGPSConverter.m index 04afac1..ac1a342 100644 --- a/Source/OpalGraphics/CGPSConverter.m +++ b/Source/OpalGraphics/CGPSConverter.m @@ -1,22 +1,22 @@ /** CGPSConverter - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -40,9 +40,9 @@ bool CGPSConverterConvert( CFDictionaryRef options) { //CGContextRef ctx = CGPDFContextCreate(consumer, NULL, NULL); - + // Read postscript from the data provider, and draw on ctx - + return true; } diff --git a/Source/OpalGraphics/CGPath.m b/Source/OpalGraphics/CGPath.m index c615377..9c862f0 100644 --- a/Source/OpalGraphics/CGPath.m +++ b/Source/OpalGraphics/CGPath.m @@ -79,83 +79,83 @@ CGRect CGPathGetPathBoundingBox(CGPathRef path) CGFloat maxY = 0.0; for (NSUInteger i=0; i 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; + } + } } - for (NSUInteger p=0; p 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; - } + { + return CGPointZero; + } NSUInteger count = [path count]; // FIXME: ugly loop for (NSUInteger i=(count-1); i>=0 && i (4 * M_PI)) - { - endAngle -= (2 * M_PI); - angleValue = (endAngle - startAngle); - } + { + 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); - } + { + // 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)); - } - } + { + // 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( @@ -331,13 +331,13 @@ void CGPathAddCurveToPoint( 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); - } - } + { + NSUInteger i = 0; + for (i = 0; i < 3; i++) + { + points[i] = CGPointApplyAffineTransform(points[i], *m); + } + } [(CGMutablePath*)path addElementWithType: kCGPathElementAddCurveToPoint points: (CGPoint*)&points]; } @@ -350,9 +350,9 @@ void CGPathAddLines( { CGPathMoveToPoint(path, m, points[0].x, points[0].y); for (NSUInteger i=1; iCGPattern - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -45,7 +45,7 @@ CGPatternRef CGPatternCreate( const CGPatternCallbacks *callbacks) { CGPatternRef pattern = nil; - + // FIXME return pattern; diff --git a/Source/OpalGraphics/CGShading.m b/Source/OpalGraphics/CGShading.m index 39d287e..d8f69aa 100644 --- a/Source/OpalGraphics/CGShading.m +++ b/Source/OpalGraphics/CGShading.m @@ -1,22 +1,22 @@ /** CGShading - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -27,7 +27,7 @@ @interface CGShading : NSObject { - + } @end @implementation CGShading @@ -59,7 +59,7 @@ CGShadingRef CGShadingCreateRadial( CFTypeID CGShadingGetTypeID() { - return (CFTypeID)[CGShading class]; + return (CFTypeID)[CGShading class]; } CGShadingRef CGShadingRetain(CGShadingRef shading) @@ -68,6 +68,6 @@ CGShadingRef CGShadingRetain(CGShadingRef shading) } void CGShadingRelease(CGShadingRef shading) -{ +{ [shading release]; } \ No newline at end of file diff --git a/Source/OpalGraphics/OPColorSpaceIndexed.h b/Source/OpalGraphics/OPColorSpaceIndexed.h index d9329d6..a0bcbd4 100644 --- a/Source/OpalGraphics/OPColorSpaceIndexed.h +++ b/Source/OpalGraphics/OPColorSpaceIndexed.h @@ -13,12 +13,12 @@ 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 diff --git a/Source/OpalGraphics/OPColorSpaceIndexed.m b/Source/OpalGraphics/OPColorSpaceIndexed.m index 00d115c..ab96a46 100644 --- a/Source/OpalGraphics/OPColorSpaceIndexed.m +++ b/Source/OpalGraphics/OPColorSpaceIndexed.m @@ -11,12 +11,12 @@ 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 @@ -38,10 +38,10 @@ - (id)initWithBaseSpace: (CGColorSpaceRef)aBaseSpace table = malloc([self tableSize]); if (NULL == table) - { - [self release]; - return nil; - } + { + [self release]; + return nil; + } memmove(table, aColorTable, [self tableSize]); return self; @@ -54,19 +54,19 @@ - (void) dealloc { free(table); CGColorSpaceRelease(base); - [super dealloc]; + [super dealloc]; } - (NSData*)ICCProfile { - return [base ICCProfile]; // FIXME: ??? + return [base ICCProfile]; // FIXME: ??? } - (NSString*)name { - return [base name]; // FIXME: ??? + return [base name]; // FIXME: ??? } - (CGColorSpaceRef) baseColorSpace { - return base; + return base; } - (size_t) numberOfComponents { @@ -82,27 +82,27 @@ - (size_t) colorTableCount } - (CGColorSpaceModel) model { - return [base 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])); - } + { + 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) colorTransformTo: (id)otherColor - sourceFormat: (OPImageFormat)sourceFormat - destinationFormat: (OPImageFormat)destFormat + sourceFormat: (OPImageFormat)sourceFormat + destinationFormat: (OPImageFormat)destFormat { - return [[[OPColorTransformIndexed alloc] init] autorelease]; + return [[[OPColorTransformIndexed alloc] init] autorelease]; } @end @@ -112,7 +112,7 @@ @implementation OPColorTransformIndexed - (void) transformPixelData: (const unsigned char *)input output: (unsigned char *)output { - // FIXME: + // FIXME: } @end diff --git a/Source/OpalGraphics/OPColorSpaceLCMS.h b/Source/OpalGraphics/OPColorSpaceLCMS.h index f8f5e83..1f5a844 100644 --- a/Source/OpalGraphics/OPColorSpaceLCMS.h +++ b/Source/OpalGraphics/OPColorSpaceLCMS.h @@ -11,12 +11,12 @@ 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 @@ -31,18 +31,18 @@ @interface OPColorSpaceLCMS : NSObject { @public - cmsHPROFILE profile; + cmsHPROFILE profile; NSData *data; } /** * Returns a generic RGB color space - */ + */ + (id)colorSpaceGenericRGB; /** * Returns a generic RGB color space with a gamma of 1.0 - */ + */ + (id)colorSpaceGenericRGBLinear; /** diff --git a/Source/OpalGraphics/OPColorSpaceLCMS.m b/Source/OpalGraphics/OPColorSpaceLCMS.m index 181acd8..ef4cf95 100644 --- a/Source/OpalGraphics/OPColorSpaceLCMS.m +++ b/Source/OpalGraphics/OPColorSpaceLCMS.m @@ -11,12 +11,12 @@ 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 @@ -41,30 +41,30 @@ @implementation OPColorSpaceLCMS /** * Returns a generic RGB color space - */ + */ + (id)colorSpaceGenericRGB { return [self colorSpaceSRGB]; } /** * Returns a generic RGB color space with a gamma of 1.0 - */ + */ + (id)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]; - } + { + // 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; } /** @@ -73,18 +73,18 @@ @implementation OPColorSpaceLCMS + (id)colorSpaceGenericCMYK { if (nil == colorSpaceGenericCMYK) - { - NSString *path = [[NSBundle bundleForLibrary: @"opal"] - pathForResource: @"coated_FOGRA39L_argl" - ofType: @"icc"]; - NSData *data = [NSData dataWithContentsOfFile: path]; - if (data == nil) - { - NSLog(@"Failed to load colour profile from file %@", path); - return nil; - } - colorSpaceGenericCMYK = [[OPColorSpaceLCMS alloc] initWithICCProfile: data]; - } + { + NSString *path = [[NSBundle bundleForLibrary: @"opal"] + pathForResource: @"coated_FOGRA39L_argl" + ofType: @"icc"]; + NSData *data = [NSData dataWithContentsOfFile: path]; + if (data == nil) + { + NSLog(@"Failed to load colour profile from file %@", path); + return nil; + } + colorSpaceGenericCMYK = [[OPColorSpaceLCMS alloc] initWithICCProfile: data]; + } return colorSpaceGenericCMYK; } /** @@ -93,18 +93,18 @@ @implementation OPColorSpaceLCMS + (id)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)]; - } + { + 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; } /** @@ -113,9 +113,10 @@ @implementation OPColorSpaceLCMS + (id)colorSpaceSRGB { if (nil == colorSpaceSRGB) - { - colorSpaceSRGB = [[OPColorSpaceLCMS alloc] initWithProfile: cmsCreate_sRGBProfile()]; - } + { + colorSpaceSRGB = [[OPColorSpaceLCMS alloc] initWithProfile: + cmsCreate_sRGBProfile()]; + } return colorSpaceSRGB; } /** @@ -131,13 +132,14 @@ @implementation OPColorSpaceLCMS + (id)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]; - } + { + 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; } @@ -170,7 +172,7 @@ - (NSString*)name static inline cmsCIExyY CIExyzToCIExyY(const CGFloat point[3]) { // LittleCMS docs say Y is always 1 - cmsCIExyY xyY = {point[0], point[1], 1.0}; + cmsCIExyY xyY = {point[0], point[1], 1.0}; return xyY; } @@ -207,9 +209,11 @@ - (id)initWithCalibratedRGBWithWhitePointCIExy: (const CGFloat*)white LPGAMMATABLE tables[3] = {cmsBuildGamma(256, gamma), cmsBuildGamma(256, gamma), - cmsBuildGamma(256, gamma)}; + cmsBuildGamma(256, gamma) + }; cmsCIExyY whitePoint = {white[0], white[1], 1.0}; - cmsCIExyYTRIPLE primaries = { + cmsCIExyYTRIPLE primaries = + { {red[0], red[1], 1.0}, {green[0], green[1], 1.0}, {blue[0], blue[1], 1.0} @@ -220,7 +224,7 @@ - (id)initWithCalibratedRGBWithWhitePointCIExy: (const CGFloat*)white cmsFreeGamma(tables[0]); cmsFreeGamma(tables[1]); cmsFreeGamma(tables[2]); - + return self; } - (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint @@ -234,7 +238,8 @@ - (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint LPGAMMATABLE tables[3] = {cmsBuildGamma(256, gamma[0]), cmsBuildGamma(256, gamma[1]), - cmsBuildGamma(256, gamma[2])}; + cmsBuildGamma(256, gamma[2]) + }; // FIXME: I'm not 100% sure this is the correct interpretation of matrix @@ -253,7 +258,7 @@ - (id)initWithCalibratedRGBWithWhitePoint: (const CGFloat*)whitePoint cmsFreeGamma(tables[0]); cmsFreeGamma(tables[1]); cmsFreeGamma(tables[2]); - + return self; } @@ -274,36 +279,38 @@ - (CGColorSpaceRef) initWithICCProfile: (CFDataRef)profileData { self = [super init]; self->data = [profileData retain]; - self->profile = cmsOpenProfileFromMem((LPVOID)[profileData bytes], [profileData length]); + self->profile = cmsOpenProfileFromMem((LPVOID)[profileData bytes], [profileData + length]); return self; } - (CGColorSpaceRef) initWithPlatformColorSpace: (void *)platformColorSpace { - [self release]; - return nil; + [self release]; + return nil; } -static CGColorSpaceModel CGColorSpaceModelForSignature(icColorSpaceSignature sig) +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; - } + { + 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)); + return CGColorSpaceModelForSignature(cmsGetColorSpace(profile)); } - (size_t) numberOfComponents @@ -312,27 +319,27 @@ - (size_t) numberOfComponents } - (id) colorTransformTo: (id)aColorSpace - sourceFormat: (OPImageFormat)aSourceFormat - destinationFormat: (OPImageFormat)aDestFormat - renderingIntent: (CGColorRenderingIntent)anIntent - pixelCount: (size_t)aPixelCount + 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]; + 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; - } + { + // FIXME: Maybe there is a simple way to compare the profiles? + return ((OPColorSpaceLCMS*)other)->profile == self->profile; + } return NO; } diff --git a/Source/OpalGraphics/OPColorTransformLCMS.h b/Source/OpalGraphics/OPColorTransformLCMS.h index b8cf5e0..8e53b84 100644 --- a/Source/OpalGraphics/OPColorTransformLCMS.h +++ b/Source/OpalGraphics/OPColorTransformLCMS.h @@ -11,12 +11,12 @@ 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 @@ -36,7 +36,7 @@ OPImageFormat sourceFormat, destFormat; CGColorRenderingIntent renderingIntent; size_t pixelCount; - unsigned char *tempBuffer1, *tempBuffer2; + unsigned char *tempBuffer1, *tempBuffer2; } - (id) initWithSourceSpace: (OPColorSpaceLCMS *)aSourceSpace diff --git a/Source/OpalGraphics/OPColorTransformLCMS.m b/Source/OpalGraphics/OPColorTransformLCMS.m index 18ace4c..356ee35 100644 --- a/Source/OpalGraphics/OPColorTransformLCMS.m +++ b/Source/OpalGraphics/OPColorTransformLCMS.m @@ -11,12 +11,12 @@ 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 @@ -36,82 +36,83 @@ @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; - } + { + 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; - } + { + 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) -{ + +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; - } - + { + 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) - { - cmsFormat |= SWAPFIRST_SH(1); - } - } + { + cmsFormat |= EXTRA_SH(1); + if (!opalFormat.isAlphaLast) + { + cmsFormat |= SWAPFIRST_SH(1); + } + } if (opalFormat.needs32Swap) - { - cmsFormat |= DOSWAP_SH(1); - } + { + cmsFormat |= DOSWAP_SH(1); + } cmsFormat |= COLORSPACE_SH( - LcmsPixelTypeForCGColorSpaceModel( - CGColorSpaceGetModel(colorSpace) - ) - ); + LcmsPixelTypeForCGColorSpaceModel( + CGColorSpaceGetModel(colorSpace) + ) + ); return cmsFormat; } @@ -128,7 +129,8 @@ static bool isAlphaLast(OPImageFormat opalFormat) } } -typedef struct { +typedef struct +{ cmsHTRANSFORM xform; OPColorSpaceLCMS *aSourceSpace; OPColorSpaceLCMS *aDestSpace; @@ -142,10 +144,10 @@ static bool isAlphaLast(OPImageFormat opalFormat) static int usedTransforms = 0; + (cmsHTRANSFORM) getTransformForSourceSpace: (OPColorSpaceLCMS *)aSourceSpace - destinationSpace: (OPColorSpaceLCMS *)aDestSpace - sourceFormat: (OPImageFormat)aSourceFormat - destinationFormat: (OPImageFormat)aDestFormat - renderingIntent: (CGColorRenderingIntent)anIntent + destinationSpace: (OPColorSpaceLCMS *)aDestSpace + sourceFormat: (OPImageFormat)aSourceFormat + destinationFormat: (OPImageFormat)aDestFormat + renderingIntent: (CGColorRenderingIntent)anIntent { const int lcmsIntent = LcmsIntentForCGColorRenderingIntent(anIntent); int lcmsSrcFormat = LcmsFormatForOPImageFormat(aSourceFormat, aSourceSpace); @@ -157,7 +159,7 @@ + (cmsHTRANSFORM) getTransformForSourceSpace: (OPColorSpaceLCMS *)aSourceSpace for (i = 0; i < usedTransforms; i++) { entry = transformCache[i]; - + if ((entry.anIntent == anIntent) && (entry.lcmsSrcFormat == lcmsSrcFormat) && (entry.lcmsDstFormat == lcmsDstFormat) @@ -171,11 +173,12 @@ + (cmsHTRANSFORM) getTransformForSourceSpace: (OPColorSpaceLCMS *)aSourceSpace if (usedTransforms == MAX_CACHE) { cmsDeleteTransform(transformCache[usedTransforms].xform); - memcpy(transformCache, transformCache + 1, sizeof(cacheEntry) * (MAX_CACHE - 1)); + memcpy(transformCache, transformCache + 1, + sizeof(cacheEntry) * (MAX_CACHE - 1)); usedTransforms--; } - xform = cmsCreateTransform(aSourceSpace->profile, lcmsSrcFormat, + xform = cmsCreateTransform(aSourceSpace->profile, lcmsSrcFormat, aDestSpace->profile, lcmsDstFormat, lcmsIntent, 0); // FIXME: check for success @@ -188,7 +191,7 @@ + (cmsHTRANSFORM) getTransformForSourceSpace: (OPColorSpaceLCMS *)aSourceSpace usedTransforms++; return xform; -} +} - (id) initWithSourceSpace: (OPColorSpaceLCMS *)aSourceSpace destinationSpace: (OPColorSpaceLCMS *)aDestSpace @@ -218,20 +221,20 @@ - (id) initWithSourceSpace: (OPColorSpaceLCMS *)aSourceSpace if (sourceFormat.compFormat == kOPComponentFormatFloat32bpc || sourceFormat.compFormat == kOPComponentFormat32bpc) - { - tempBuffer1 = malloc(2 * pixelCount); // Convert to 16-bit - } + { + 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); - } + { + // 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); - } + || destFormat.compFormat == kOPComponentFormat32bpc) + { + tempBuffer2 = malloc(OPPixelNumberOfBytes(destFormat) * pixelCount); + } return self; } @@ -247,13 +250,13 @@ - (void) dealloc [source release]; [dest release]; if (tempBuffer1) - { - free(tempBuffer1); - } + { + free(tempBuffer1); + } if (tempBuffer2) - { - free(tempBuffer2); - } + { + free(tempBuffer2); + } [super dealloc]; } @@ -262,14 +265,18 @@ - (void) transformPixelData: (const unsigned char *)input { 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 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 + const bool destIntermediateIs16bpc = (destFormat.compFormat == + kOPComponentFormatFloat32bpc || destFormat.compFormat == kOPComponentFormat32bpc || destFormat.compFormat == kOPComponentFormat16bpc); - const bool sourceIntermediateIs16bpc = (sourceFormat.compFormat == kOPComponentFormatFloat32bpc + const bool sourceIntermediateIs16bpc = (sourceFormat.compFormat == + kOPComponentFormatFloat32bpc || sourceFormat.compFormat == kOPComponentFormat32bpc || sourceFormat.compFormat == kOPComponentFormat16bpc); @@ -283,9 +290,10 @@ - (void) transformPixelData: (const unsigned char *)input { for (size_t j = 0; j < totalComponentsIn; j++) { - ((uint16_t*)tempBuffer1)[i*totalComponentsIn + j] = UINT16_MAX * ((float*)input)[i*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) + if ((float)((float*)input)[i*totalComponentsIn + j] > 1) { NSLog(@"%s: overflow", __PRETTY_FUNCTION__); } @@ -299,11 +307,12 @@ - (void) transformPixelData: (const unsigned char *)input { for (size_t j = 0; j < totalComponentsIn; j++) { - ((uint16_t*)tempBuffer1)[i*totalComponentsIn + j] = ((uint32_t*)input)[i*totalComponentsIn + j] >> 16; + ((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 @@ -315,33 +324,35 @@ - (void) transformPixelData: (const unsigned char *)input // 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; + 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; + 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 if (xform != NULL) @@ -351,83 +362,96 @@ - (void) transformPixelData: (const unsigned char *)input else { size_t destIntermediateBytesPerComponent = (destIntermediateIs16bpc ? 2 : 1); - size_t destIntermediateTotalComponentsPerPixel = (destFormat.colorComponents + (destFormat.hasAlpha ? 1 : 0)); - size_t destIntermediateBytesPerRow = pixelCount * destIntermediateTotalComponentsPerPixel * destIntermediateBytesPerComponent; + size_t destIntermediateTotalComponentsPerPixel = (destFormat.colorComponents + + (destFormat.hasAlpha ? 1 : 0)); + size_t destIntermediateBytesPerRow = pixelCount * + destIntermediateTotalComponentsPerPixel * destIntermediateBytesPerComponent; memcpy(tempOutput, input, destIntermediateBytesPerRow); } - + // copy alpha from source to dest if necessary - if (sourceFormat.hasAlpha && destFormat.hasAlpha) - { - const size_t sourceAlphaCompIndex = (isAlphaLast(sourceFormat) ? sourceFormat.colorComponents : 0); - const size_t destAlphaCompIndex = (isAlphaLast(destFormat) ? destFormat.colorComponents : 0); - - if (sourceIntermediateIs16bpc && destIntermediateIs16bpc) /* 16 bit -> 16 bit */ - for (size_t i=0; i 16 bit */ - { - for (size_t i=0; i 8 bit */ - { - for (size_t i=0; i> 16; - } - } - else /* 8 bit -> 8 bit */ - { - for (size_t i=0; i 16 bit */ + for (size_t i=0; i 16 bit */ + { + for (size_t i=0; i 8 bit */ + { + for (size_t i=0; i> 16; + } + } + else /* 8 bit -> 8 bit */ + { + for (size_t i=0; i %f", (int)((uint16_t*)tempBuffer2)[i*totalComponentsOut + j], (float)((float*)output)[i*totalComponentsOut + j]); + for (size_t i=0; i %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 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 @@ -57,7 +57,7 @@ void OPImageFormatLog(OPImageFormat fmt, NSString *msg); void OPImageConvert( unsigned char *dstData, - const unsigned char *srcData, + const unsigned char *srcData, size_t width, size_t height, size_t dstBitsPerComponent, @@ -68,6 +68,6 @@ void OPImageConvert( size_t srcBytesPerRow, CGBitmapInfo dstBitmapInfo, CGBitmapInfo srcBitmapInfo, - CGColorSpaceRef dstColorSpace, + CGColorSpaceRef dstColorSpace, CGColorSpaceRef srcColorSpace, CGColorRenderingIntent intent); diff --git a/Source/OpalGraphics/OPImageConversion.m b/Source/OpalGraphics/OPImageConversion.m index d804fc9..4ab21b3 100644 --- a/Source/OpalGraphics/OPImageConversion.m +++ b/Source/OpalGraphics/OPImageConversion.m @@ -6,17 +6,17 @@ Author: Eric Wasylishen 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 @@ -34,16 +34,16 @@ size_t OPComponentNumberOfBytes(OPComponentFormat fmt) { switch (fmt) - { - case kOPComponentFormat8bpc: - return 1; - case kOPComponentFormat16bpc: - return 2; - case kOPComponentFormat32bpc: - return 4; - case kOPComponentFormatFloat32bpc: - return 4; - } + { + case kOPComponentFormat8bpc: + return 1; + case kOPComponentFormat16bpc: + return 2; + case kOPComponentFormat32bpc: + return 4; + case kOPComponentFormatFloat32bpc: + return 4; + } return 0; } @@ -58,24 +58,26 @@ size_t OPPixelNumberOfBytes(OPImageFormat 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; - } - NSDebugLLog(@"Opal", @"%@: <%@, color components=%d, alpha?=%d, premul?=%d, alpha last?=%d>", - msg, compFormatString, fmt.colorComponents, fmt.hasAlpha, fmt.isAlphaPremultiplied, fmt.isAlphaLast); + 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; + } + NSDebugLLog(@"Opal", + @"%@: <%@, 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) @@ -83,120 +85,127 @@ 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]; - } + { + 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, +_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; - } + { + ((uint32_t*)base)[msb_off / 32] = val; + } else if (msb_off % 16 == 0 && bit_width == 16) - { - ((uint16_t*)base)[msb_off / 16] = val; - } + { + ((uint16_t*)base)[msb_off / 16] = val; + } else if (msb_off % 8 == 0 && bit_width == 8) - { - ((uint8_t*)base)[msb_off / 8] = val; - } + { + ((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; - } + { + 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(); - } + { + 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]; - } + { + return ((uint32_t*)base)[msb_off / 32]; + } else if (msb_off % 16 == 0 && bit_width == 16) - { - return ((uint16_t*)base)[msb_off / 16]; - } + { + return ((uint16_t*)base)[msb_off / 16]; + } else if (msb_off % 8 == 0 && bit_width == 8) - { - return ((uint8_t*)base)[msb_off / 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 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]; + 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(); - } + 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<>= shift; - value &= ((1<compFormat = kOPComponentFormat8bpc; - break; - case 16: - out->compFormat = kOPComponentFormat16bpc; - break; - case 32: - if (bitmapInfo & kCGBitmapFloatComponents) - { - out->compFormat = kOPComponentFormatFloat32bpc; - } - else - { - out->compFormat = kOPComponentFormat32bpc; - } - break; - default: - return false; - } - + { + case 8: + out->compFormat = kOPComponentFormat8bpc; + break; + case 16: + out->compFormat = kOPComponentFormat16bpc; + break; + case 32: + if (bitmapInfo & kCGBitmapFloatComponents) + { + out->compFormat = kOPComponentFormatFloat32bpc; + } + else + { + out->compFormat = kOPComponentFormat32bpc; + } + 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->hasAlpha = (alpha != kCGImageAlphaNone + && actualComponents > colorComponents); out->isAlphaPremultiplied = (alpha == kCGImageAlphaPremultipliedFirst || alpha == kCGImageAlphaPremultipliedLast); - out->isAlphaLast = (alpha == kCGImageAlphaPremultipliedLast || + out->isAlphaLast = (alpha == kCGImageAlphaPremultipliedLast || alpha == kCGImageAlphaLast); // LCMS use big endian out->needs32Swap = bitmapInfo & kCGBitmapByteOrder32Little; @@ -254,7 +264,7 @@ static bool OPImageFormatForCGFormat( void OPImageConvert( unsigned char *dstData, - const unsigned char *srcData, + const unsigned char *srcData, size_t width, size_t height, size_t dstBitsPerComponent, @@ -265,24 +275,26 @@ void OPImageConvert( size_t srcBytesPerRow, CGBitmapInfo dstBitmapInfo, CGBitmapInfo srcBitmapInfo, - CGColorSpaceRef dstColorSpace, + 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"); - } - + if (!OPImageFormatForCGFormat(srcBitsPerComponent, srcBitsPerPixel, + srcBitmapInfo, srcColorSpace, &srcFormat)) + { + NSLog(@"Input format not supported"); + } + if (!OPImageFormatForCGFormat(dstBitsPerComponent, dstBitsPerPixel, + dstBitmapInfo, dstColorSpace, &dstFormat)) + { + NSLog(@"Output format not supported"); + } + if ((dstBitsPerComponent == srcBitsPerComponent) && - (dstBitsPerPixel == srcBitsPerPixel) && + (dstBitsPerPixel == srcBitsPerPixel) && (dstBytesPerRow == srcBytesPerRow) && (dstBitmapInfo == srcBitmapInfo) && [dstColorSpace isEqual: srcColorSpace]) @@ -295,7 +307,7 @@ void OPImageConvert( OPImageFormatLog(srcFormat, @"OPImageConversion source"); OPImageFormatLog(dstFormat, @"OPImageConversion dest"); - + id xform = [srcColorSpace colorTransformTo: dstColorSpace sourceFormat: srcFormat destinationFormat: dstFormat @@ -303,7 +315,7 @@ void OPImageConvert( pixelCount: width]; unsigned char *tempInput = malloc(srcBytesPerRow); - + for (size_t row = 0; row < height; row++) { const unsigned char *input = srcData + (row * srcBytesPerRow); diff --git a/Source/OpalGraphics/OPLogging.h b/Source/OpalGraphics/OPLogging.h index 66e1f6d..01ddcdb 100644 --- a/Source/OpalGraphics/OPLogging.h +++ b/Source/OpalGraphics/OPLogging.h @@ -15,12 +15,12 @@ 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 diff --git a/Source/OpalGraphics/OPLogging.m b/Source/OpalGraphics/OPLogging.m index 30e5421..ea188e4 100644 --- a/Source/OpalGraphics/OPLogging.m +++ b/Source/OpalGraphics/OPLogging.m @@ -13,12 +13,12 @@ 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 diff --git a/Source/OpalGraphics/OPPath.h b/Source/OpalGraphics/OPPath.h index 3be4553..68b7f1d 100644 --- a/Source/OpalGraphics/OPPath.h +++ b/Source/OpalGraphics/OPPath.h @@ -40,9 +40,10 @@ typedef struct } - (id) initWithCGPath: (CGPathRef)path; - (NSUInteger) count; -- (CGPathElementType) elementTypeAtIndex: (NSUInteger)index points: (CGPoint*)outPoints; +- (CGPathElementType) elementTypeAtIndex: (NSUInteger)index points: + (CGPoint*)outPoints; - (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points; -- (BOOL) isEqual:(id)otherObj; +- (BOOL) isEqual: (id)otherObj; - (BOOL) isRect: (CGRect*)outRect; @end @@ -70,6 +71,6 @@ typedef struct */ NSUInteger _OPPathRequiredArcSegments(CGFloat angle, - CGFloat radius, - const CGAffineTransform *m); + CGFloat radius, + const CGAffineTransform *m); diff --git a/Source/OpalGraphics/OPPath.m b/Source/OpalGraphics/OPPath.m index 9b187f8..fd602ed 100644 --- a/Source/OpalGraphics/OPPath.m +++ b/Source/OpalGraphics/OPPath.m @@ -28,24 +28,24 @@ 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; - } + { + 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; } @@ -59,15 +59,15 @@ - (id) copyWithZone: (NSZone*)zone - (id) initWithCGPath: (CGPathRef)path { if (path) - { - [self release]; - return [path retain]; - } + { + [self release]; + return [path retain]; + } else - { - self = [super init]; - return self; - } + { + self = [super init]; + return self; + } } - (void)dealloc @@ -81,37 +81,38 @@ - (NSUInteger) count return _count; } -- (CGPathElementType) elementTypeAtIndex: (NSUInteger)index points: (CGPoint*)outPoints +- (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; + 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 +- (BOOL)isEqual: (id)otherObj { if (self == otherObj) - { - return YES; - } + { + return YES; + } if (![otherObj isKindOfClass: [CGPath class]]) - { - return NO; - } + { + return NO; + } CGPath *path2 = (CGPath*)otherObj; @@ -119,97 +120,100 @@ - (BOOL)isEqual:(id)otherObj NSUInteger count2 = [path2 count]; if (count1 != count2) - { - return NO; - } - - for (NSUInteger i=0; iorigin = _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; - } + { + 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"]; + [NSException raise: NSGenericException format: + @"Attempt to modify immutable CGPath"]; } @end @@ -220,32 +224,32 @@ @implementation CGMutablePath - (void) addElementWithType: (CGPathElementType)type points: (CGPoint[])points { if (_elementsArray) - { - if (_count + 1 > _capacity) { - _capacity += 32; - _elementsArray = realloc(_elementsArray, _capacity * sizeof(OPPathElement)); + if (_count + 1 > _capacity) + { + _capacity += 32; + _elementsArray = realloc(_elementsArray, _capacity * sizeof(OPPathElement)); + } } - } else - { - _capacity = 32; - _elementsArray = malloc(_capacity * sizeof(OPPathElement)); - } + { + _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; - } + { + 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++; } @@ -254,17 +258,17 @@ - (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; + _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)); } - memcpy(_elementsArray, path->_elementsArray, _count * sizeof(OPPathElement)); - } return self; } @@ -288,11 +292,12 @@ - (id) copyWithZone: (NSZone*)zone * simliar appearance for arcs drawn by cairo itself and those added to CGPaths. * The values apply for (M_PI / (index + 1)). */ -static CGFloat approximationErrorTable[] = { +static CGFloat approximationErrorTable[] = +{ 0.0185185185185185036127, 0.000272567143730179811158, 2.38647043651461047433e-05, - 4.2455377443222443279e-06 , + 4.2455377443222443279e-06, 1.11281001494389081528e-06, 3.72662000942734705475e-07, 1.47783685574284411325e-07, @@ -306,12 +311,12 @@ - (id) copyWithZone: (NSZone*)zone static inline CGFloat _OPPathArcAxisLengthForRadiusByApplyingTransform(CGFloat radius, - const CGAffineTransform *m) + const CGAffineTransform *m) { if (NULL == m) - { - return radius; - } + { + 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)); @@ -339,31 +344,34 @@ - (id) copyWithZone: (NSZone*)zone NSUInteger index = 0; for (index = 0; index < approximationErrorTableCount; index++) - { - if (approximationErrorTable[index] < tolerance) - { - return (M_PI / (index + 1)); - } - } + { + 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); + { + angle = (M_PI / index++); + error = _OPPathArcErrorForAngle(angle); + } + while (error > tolerance); return 0; } NSUInteger _OPPathRequiredArcSegments(CGFloat angle, - CGFloat radius, - const CGAffineTransform *m) + 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)); + CGFloat majorAxis = _OPPathArcAxisLengthForRadiusByApplyingTransform(radius, + m); + CGFloat maxAngle = _OPPathArcMaxAngleForTolerance((OPPathArcDefaultTolerance / + majorAxis)); return ceil((fabs(angle) / maxAngle)); } diff --git a/Source/OpalGraphics/OPPostScriptContext.m b/Source/OpalGraphics/OPPostScriptContext.m index 28e9911..8841b3a 100644 --- a/Source/OpalGraphics/OPPostScriptContext.m +++ b/Source/OpalGraphics/OPPostScriptContext.m @@ -11,12 +11,12 @@ 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 @@ -37,7 +37,8 @@ /* Constants */ const CFStringRef kOPPostScriptContextIsEPS = @"kOPPostScriptContextIsEPS"; -const CFStringRef kOPPostScriptContextLanguageLevel = @"kOPPostScriptContextLanguageLevel"; +const CFStringRef kOPPostScriptContextLanguageLevel = + @"kOPPostScriptContextLanguageLevel"; /* Functions */ @@ -50,13 +51,14 @@ 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; - } + if (cret) + { + NSLog(@"OPPostScriptContextClose status: %s", + cairo_status_to_string(cret)); + return; + } } cairo_status_t opal_OPPostScriptContextWriteFunction( @@ -68,20 +70,23 @@ cairo_status_t opal_OPPostScriptContextWriteFunction( return CAIRO_STATUS_SUCCESS; } -static void opal_setProperties(cairo_surface_t *surf, CFDictionaryRef auxiliaryInfo) +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); - } + { + 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; @@ -98,24 +103,28 @@ CGContextRef OPPostScriptContextCreate( CFDictionaryRef auxiliaryInfo) { CGRect box; - if (mediaBox == NULL) { - box = CGRectMake(0, 0, 8.5 * 72, 11 * 72); - } else { - box = *mediaBox; - } - + 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); + opal_OPPostScriptContextWriteFunction, + CGDataConsumerRetain(consumer), + box.size.width, + box.size.height); - cairo_surface_set_user_data(surf, &OpalDataConsumerKey, consumer, opal_SurfaceDestoryFunc); + cairo_surface_set_user_data(surf, &OpalDataConsumerKey, consumer, + opal_SurfaceDestoryFunc); opal_setProperties(surf, auxiliaryInfo); - + CGContextRef ctx = opal_new_CGContext(surf, box.size); return ctx; } @@ -135,16 +144,17 @@ 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; + { + 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; + } } - } } diff --git a/Source/OpalGraphics/OPPremultiplyAlpha.h b/Source/OpalGraphics/OPPremultiplyAlpha.h index 12c2eb8..a43c4d9 100644 --- a/Source/OpalGraphics/OPPremultiplyAlpha.h +++ b/Source/OpalGraphics/OPPremultiplyAlpha.h @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalGraphics/OPPremultiplyAlpha.m b/Source/OpalGraphics/OPPremultiplyAlpha.m index b884978..6e12dcb 100644 --- a/Source/OpalGraphics/OPPremultiplyAlpha.m +++ b/Source/OpalGraphics/OPPremultiplyAlpha.m @@ -11,12 +11,12 @@ 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 @@ -37,7 +37,7 @@ pixelPtr[i] *= alphaValue; \ } \ } - + #define _OPUnPremultiplyAlpha(isAlphaLast, compType, compMax, rowStart, comps, pixels) \ const size_t firstComp = (isAlphaLast ? 0 : 1); \ const size_t lastComp = (isAlphaLast ? (comps - 2) : (comps - 1)); \ @@ -59,7 +59,7 @@ } \ } \ } - + void OPPremultiplyAlpha( unsigned char *row, size_t pixels, @@ -81,46 +81,46 @@ void OPPremultiplyAlpha( switch (format.compFormat) - { - case kOPComponentFormat8bpc: - if (unPremultiply) - { - _OPUnPremultiplyAlpha(isAlphaLast, uint8_t, UINT8_MAX, row, comps, pixels); - } - else - { - _OPPremultiplyAlpha(isAlphaLast, uint8_t, UINT8_MAX, row, comps, pixels); - } - break; - case kOPComponentFormat16bpc: - if (unPremultiply) - { - _OPUnPremultiplyAlpha(isAlphaLast, uint16_t, UINT16_MAX, row, comps, pixels); - } - else - { - _OPPremultiplyAlpha(isAlphaLast, uint16_t, UINT16_MAX, row, comps, pixels); - } - break; - case kOPComponentFormat32bpc: - if (unPremultiply) - { - _OPUnPremultiplyAlpha(isAlphaLast, uint32_t, UINT32_MAX, row, comps, pixels); - } - else - { - _OPPremultiplyAlpha(isAlphaLast, uint32_t, UINT32_MAX, row, comps, pixels); - } - break; - case kOPComponentFormatFloat32bpc: - if (unPremultiply) - { - _OPUnPremultiplyAlpha(isAlphaLast, float, 1.0f, row, comps, pixels); - } - else - { - _OPPremultiplyAlpha(isAlphaLast, float, 1.0f, row, comps, pixels); - } - break; - } + { + case kOPComponentFormat8bpc: + if (unPremultiply) + { + _OPUnPremultiplyAlpha(isAlphaLast, uint8_t, UINT8_MAX, row, comps, pixels); + } + else + { + _OPPremultiplyAlpha(isAlphaLast, uint8_t, UINT8_MAX, row, comps, pixels); + } + break; + case kOPComponentFormat16bpc: + if (unPremultiply) + { + _OPUnPremultiplyAlpha(isAlphaLast, uint16_t, UINT16_MAX, row, comps, pixels); + } + else + { + _OPPremultiplyAlpha(isAlphaLast, uint16_t, UINT16_MAX, row, comps, pixels); + } + break; + case kOPComponentFormat32bpc: + if (unPremultiply) + { + _OPUnPremultiplyAlpha(isAlphaLast, uint32_t, UINT32_MAX, row, comps, pixels); + } + else + { + _OPPremultiplyAlpha(isAlphaLast, uint32_t, UINT32_MAX, row, comps, pixels); + } + break; + case kOPComponentFormatFloat32bpc: + if (unPremultiply) + { + _OPUnPremultiplyAlpha(isAlphaLast, float, 1.0f, row, comps, pixels); + } + else + { + _OPPremultiplyAlpha(isAlphaLast, float, 1.0f, row, comps, pixels); + } + break; + } } diff --git a/Source/OpalGraphics/OPSVGContext.m b/Source/OpalGraphics/OPSVGContext.m index accea5d..7375903 100644 --- a/Source/OpalGraphics/OPSVGContext.m +++ b/Source/OpalGraphics/OPSVGContext.m @@ -11,12 +11,12 @@ 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 @@ -49,13 +49,14 @@ void OPSVGContextClose(CGContextRef ctx) { cairo_status_t cret; cairo_surface_finish(cairo_get_target(ctx->ct)); - + cret = cairo_status(ctx->ct); - if (cret) { - NSLog(@"OPSVGContextClose status: %s", - cairo_status_to_string(cret)); - return; - } + if (cret) + { + NSLog(@"OPSVGContextClose status: %s", + cairo_status_to_string(cret)); + return; + } } cairo_status_t opal_OPSVGContextWriteFunction( @@ -67,16 +68,18 @@ cairo_status_t opal_OPSVGContextWriteFunction( return CAIRO_STATUS_SUCCESS; } -static void opal_setProperties(cairo_surface_t *surf, CFDictionaryRef auxiliaryInfo) +static void opal_setProperties(cairo_surface_t *surf, + CFDictionaryRef auxiliaryInfo) { if ([[auxiliaryInfo valueForKey: kOPSVGContextSVGVersion] isEqual: @"1.1"]) - { - cairo_svg_surface_restrict_to_version(surf, CAIRO_SVG_VERSION_1_1); - } - else if ([[auxiliaryInfo valueForKey: kOPSVGContextSVGVersion] isEqual: @"1.2"]) - { - cairo_svg_surface_restrict_to_version(surf, CAIRO_SVG_VERSION_1_2); - } + { + cairo_svg_surface_restrict_to_version(surf, CAIRO_SVG_VERSION_1_1); + } + else if ([[auxiliaryInfo valueForKey: kOPSVGContextSVGVersion] isEqual: + @"1.2"]) + { + cairo_svg_surface_restrict_to_version(surf, CAIRO_SVG_VERSION_1_2); + } } @@ -94,22 +97,26 @@ CGContextRef OPSVGContextCreate( CFDictionaryRef auxiliaryInfo) { CGRect box; - if (mediaBox == NULL) { - box = CGRectMake(0, 0, 8.5 * 72, 11 * 72); - } else { - box = *mediaBox; - } - + 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_svg_surface_create_for_stream( - opal_OPSVGContextWriteFunction, - CGDataConsumerRetain(consumer), - box.size.width, - box.size.height); - - cairo_surface_set_user_data(surf, &OpalDataConsumerKey, consumer, opal_SurfaceDestoryFunc); - + opal_OPSVGContextWriteFunction, + 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); @@ -131,12 +138,13 @@ void OPSVGContextEndPage(CGContextRef ctx) { cairo_status_t cret; cairo_show_page(ctx->ct); - + cret = cairo_status(ctx->ct); - if (cret) { - NSLog(@"OPSVGContextEndPage status: %s", - cairo_status_to_string(cret)); - return; - } + if (cret) + { + NSLog(@"OPSVGContextEndPage status: %s", + cairo_status_to_string(cret)); + return; + } } diff --git a/Source/OpalGraphics/cairo/CairoFont.h b/Source/OpalGraphics/cairo/CairoFont.h index a0a9d49..c0812d7 100644 --- a/Source/OpalGraphics/cairo/CairoFont.h +++ b/Source/OpalGraphics/cairo/CairoFont.h @@ -1,22 +1,22 @@ /** CairoFont - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -27,8 +27,8 @@ @interface CairoFont : CGFont { - @public - cairo_scaled_font_t *cairofont; +@public + cairo_scaled_font_t *cairofont; } @end diff --git a/Source/OpalGraphics/cairo/CairoFont.m b/Source/OpalGraphics/cairo/CairoFont.m index 91021d6..a412d0d 100644 --- a/Source/OpalGraphics/cairo/CairoFont.m +++ b/Source/OpalGraphics/cairo/CairoFont.m @@ -1,22 +1,22 @@ /** CairoFont - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 diff --git a/Source/OpalGraphics/cairo/CairoFontWin32.h b/Source/OpalGraphics/cairo/CairoFontWin32.h index 3865dc7..9500946 100644 --- a/Source/OpalGraphics/cairo/CairoFontWin32.h +++ b/Source/OpalGraphics/cairo/CairoFontWin32.h @@ -1,22 +1,22 @@ /** CairoFontWin32 - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 diff --git a/Source/OpalGraphics/cairo/CairoFontWin32.m b/Source/OpalGraphics/cairo/CairoFontWin32.m index c3a96a8..e963407 100644 --- a/Source/OpalGraphics/cairo/CairoFontWin32.m +++ b/Source/OpalGraphics/cairo/CairoFontWin32.m @@ -1,22 +1,22 @@ /** CairoFontWin32 - + C Interface to graphics drawing library - + Copyright (C) 2010 Free Software Foundation, Inc. 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 @@ -29,10 +29,11 @@ #import "StandardGlyphNames.h" typedef uint32_t Fixed; -typedef int16_t FWord; +typedef int16_t FWord; typedef uint16_t UFWORD; -struct post_table { +struct post_table +{ Fixed Version; Fixed italicAngle; FWord underlinePosition; @@ -48,7 +49,8 @@ //CHAR names[numberNewGlyphs]; }; -struct hhea_table{ +struct hhea_table +{ Fixed ver; FWord Ascender; FWord Descender; @@ -68,9 +70,10 @@ USHORT numberOfHMetrics; }; -typedef struct _longHorMetric { - USHORT advanceWidth; - SHORT lsb; +typedef struct _longHorMetric +{ + USHORT advanceWidth; + SHORT lsb; } longHorMetric; @@ -82,78 +85,81 @@ - (void) dealloc DeleteObject(hfont); [super dealloc]; } - + - (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph { HDC hdc = CreateCompatibleDC(NULL); SelectObject(hdc, hfont); - + // See http://www.microsoft.com/typography/otspec150/post.htm - + DWORD tableName = GSSwapBigI32ToHost('post'); DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); if (size == GDI_ERROR) - { - printf("CGFontCopyGlyphNameForGlyph: GDI error getting 'post' table"); - DeleteDC(hdc); - return nil; - } - + { + printf("CGFontCopyGlyphNameForGlyph: GDI error getting 'post' table"); + DeleteDC(hdc); + return nil; + } + struct post_table *data = malloc(size); - + if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontCopyGlyphNameForGlyph: Getting 'post' table contents failed"); - DeleteDC(hdc); - free(data); - return nil; - } - + { + printf("CGFontCopyGlyphNameForGlyph: Getting 'post' table contents failed"); + DeleteDC(hdc); + free(data); + return nil; + } + if (GSSwapBigI32ToHost(data->Version) != 0x00020000) - { - // FIXME: handle other versions. - printf("CGFontCopyGlyphNameForGlyph: 'post' table version != 2"); - DeleteDC(hdc); - free(data); - return nil; - } - + { + // FIXME: handle other versions. + printf("CGFontCopyGlyphNameForGlyph: 'post' table version != 2"); + DeleteDC(hdc); + free(data); + return nil; + } + USHORT glyphNameIndex = GSSwapBigI16ToHost((&(data->glyphNameIndex))[glyph]); - - if (glyphNameIndex < 258) - { - DeleteDC(hdc); - CFStringRef ret = [[NSString alloc] initWithUTF8String: StandardGlyphNames[glyphNameIndex]]; - free(data); - return ret; - } - else - { - glyphNameIndex -= 258; // Use this as an index into the list of pascal strings - } - - unsigned char *names = (unsigned char *)(&(data->glyphNameIndex) + GSSwapBigI16ToHost(data->numberOfGlyphs)); - int index = 0; - for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) - { - int count = ptr[0]; - ptr++; - - if (index == glyphNameIndex) + if (glyphNameIndex < 258) { DeleteDC(hdc); - CFStringRef ret = [[NSString alloc] initWithBytes: ptr length: count encoding: NSASCIIStringEncoding]; + CFStringRef ret = [[NSString alloc] initWithUTF8String: + StandardGlyphNames[glyphNameIndex]]; free(data); return ret; } - else + else + { + glyphNameIndex -= 258; // Use this as an index into the list of pascal strings + } + + unsigned char *names = (unsigned char *)(&(data->glyphNameIndex) + + GSSwapBigI16ToHost(data->numberOfGlyphs)); + + int index = 0; + for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) { - ptr += count; + int count = ptr[0]; + ptr++; + + if (index == glyphNameIndex) + { + DeleteDC(hdc); + CFStringRef ret = [[NSString alloc] initWithBytes: ptr length: count encoding: + NSASCIIStringEncoding]; + free(data); + return ret; + } + else + { + ptr += count; + } + index++; } - index++; - } - + DeleteDC(hdc); free(data); return nil; @@ -163,91 +169,94 @@ - (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName { HDC hdc = CreateCompatibleDC(NULL); SelectObject(hdc, hfont); - + // See http://www.microsoft.com/typography/otspec150/post.htm - + DWORD tableName = GSSwapBigI32ToHost('post'); DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); if (size == GDI_ERROR) - { - printf("CGFontGetGlyphWithGlyphName: GDI error getting 'post' table"); - DeleteDC(hdc); - return 0; - } - + { + printf("CGFontGetGlyphWithGlyphName: GDI error getting 'post' table"); + DeleteDC(hdc); + return 0; + } + struct post_table *data = malloc(size); - + if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontGetGlyphWithGlyphName: Getting 'post' table contents failed"); - DeleteDC(hdc); - free(data); - return 0; - } - + { + printf("CGFontGetGlyphWithGlyphName: Getting 'post' table contents failed"); + DeleteDC(hdc); + free(data); + return 0; + } + if (GSSwapBigI16ToHost(data->Version) != 2) - { - // FIXME: handle other versions. - printf("CGFontGetGlyphWithGlyphName: 'post' table version != 2"); - DeleteDC(hdc); - free(data); - return 0; - } - + { + // FIXME: handle other versions. + printf("CGFontGetGlyphWithGlyphName: 'post' table version != 2"); + DeleteDC(hdc); + free(data); + return 0; + } + const char *glyphNameCString = [glyphName UTF8String]; const int glyphNameCStringLen = strlen(glyphNameCString); - + for (int i=0; i<258; i++) - { - if (0 == strcmp(glyphNameCString, StandardGlyphNames[i])) { - for (CFIndex j=0; jnumberOfGlyphs; j++) - { - if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == i) + if (0 == strcmp(glyphNameCString, StandardGlyphNames[i])) { - DeleteDC(hdc); - free(data); - return (CGGlyph)j; + for (CFIndex j=0; jnumberOfGlyphs; j++) + { + if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == i) + { + DeleteDC(hdc); + free(data); + return (CGGlyph)j; + } + } + + printf("CGFontGetGlyphWithGlyphName: Warning, %s is a standard glyph name but it is not present in the font\n", + glyphNameCString); + break; } - } - - printf("CGFontGetGlyphWithGlyphName: Warning, %s is a standard glyph name but it is not present in the font\n", glyphNameCString); - break; } - } - - unsigned char *names = (unsigned char*)(&(data->glyphNameIndex) + self->numberOfGlyphs); - + + unsigned char *names = (unsigned char*)(&(data->glyphNameIndex) + + self->numberOfGlyphs); + int index = 0; for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) - { - int count = ptr[0]; - ptr++; - if (count == glyphNameCStringLen && 0 == memcmp(ptr, glyphNameCString, count)) - { - int glyphNameIndex = index + 258; - - // Search for the glyph with this glyphNameIndex - for (CFIndex j=0; jnumberOfGlyphs; j++) - { - if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == glyphNameIndex) + { + int count = ptr[0]; + ptr++; + if (count == glyphNameCStringLen && 0 == memcmp(ptr, glyphNameCString, count)) { - DeleteDC(hdc); - free(data); - return (CGGlyph)j; + int glyphNameIndex = index + 258; + + // Search for the glyph with this glyphNameIndex + for (CFIndex j=0; jnumberOfGlyphs; j++) + { + if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == glyphNameIndex) + { + DeleteDC(hdc); + free(data); + return (CGGlyph)j; + } + } + + printf("CGFontGetGlyphWithGlyphName: Warning, %s is in the font glyph name dictionary but it is not assigned to any glyph in the font\n", + glyphNameCString); + break; } - } - - printf("CGFontGetGlyphWithGlyphName: Warning, %s is in the font glyph name dictionary but it is not assigned to any glyph in the font\n", glyphNameCString); - break; - } - else - { - ptr += count; + else + { + ptr += count; + } + index++; } - index++; - } - + DeleteDC(hdc); free(data); return (CGGlyph)0; @@ -260,8 +269,8 @@ - (CGGlyph) glyphWithCharacter: (unichar)character } - (bool) getGlyphAdvances: (const CGGlyph[])glyphs - : (size_t)count - : (int[]) advances +: (size_t)count +: (int[]) advances { HDC hdc = CreateCompatibleDC(NULL); SelectObject(hdc, hfont); @@ -269,59 +278,59 @@ - (bool) getGlyphAdvances: (const CGGlyph[])glyphs DWORD tableName = GSSwapBigI32ToHost('hhea'); DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); if (size == GDI_ERROR) - { - printf("CGFontGetGlyphAdvances: GDI error getting 'hhea' table"); - DeleteDC(hdc); - return false; - } - + { + printf("CGFontGetGlyphAdvances: GDI error getting 'hhea' table"); + DeleteDC(hdc); + return false; + } + struct hhea_table *data = malloc(size); if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontGetGlyphAdvances: Error getting contents of 'hhea' table"); - DeleteDC(hdc); - free(data); - return false; - } - + { + printf("CGFontGetGlyphAdvances: Error getting contents of 'hhea' table"); + DeleteDC(hdc); + free(data); + return false; + } + UINT numHMetrics = GSSwapBigI16ToHost(data->numberOfHMetrics); - + DWORD tableName2 = GSSwapBigI32ToHost('hmtx'); DWORD size2 = GetFontData(hdc, tableName2, 0, NULL, 0); if (size2 == GDI_ERROR) - { - printf("CGFontGetGlyphAdvances: GDI error getting 'hmtx' table"); - DeleteDC(hdc); - free(data); - return false; - } - + { + printf("CGFontGetGlyphAdvances: GDI error getting 'hmtx' table"); + DeleteDC(hdc); + free(data); + return false; + } + longHorMetric *data2 = malloc(size2); if (size2 != GetFontData(hdc, tableName2, 0, data2, size2)) - { - printf("CGFontGetGlyphAdvances: Error getting contents of 'hmtx' table"); - DeleteDC(hdc); - free(data); - free(data2); - return false; - } - + { + printf("CGFontGetGlyphAdvances: Error getting contents of 'hmtx' table"); + DeleteDC(hdc); + free(data); + free(data2); + return false; + } + for (int i=0; i (numHMetrics - 1)) - indexToUse = numHMetrics - 1; - else - indexToUse = g; - advances[i] = GSSwapBigI16ToHost(data2[indexToUse].advanceWidth); - } - + { + CGGlyph g = glyphs[i]; + int indexToUse; + if (g > (numHMetrics - 1)) + indexToUse = numHMetrics - 1; + else + indexToUse = g; + advances[i] = GSSwapBigI16ToHost(data2[indexToUse].advanceWidth); + } + DeleteDC(hdc); free(data); - free(data2); + free(data2); return true; } @@ -359,22 +368,25 @@ + (CGFontRef) createWithFontName: (CFStringRef)name { CairoFontWin32 *font = [[CairoFontWin32 alloc] init]; cairo_font_face_t *unscaled; - + if (NULL == font) return nil; font->hfont = CreateFont(46, 28, 215, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - DEFAULT_PITCH | FF_ROMAN, - "Times New Roman"); + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + DEFAULT_PITCH | FF_ROMAN, + "Times New Roman"); - if (font->hfont) { - unscaled = cairo_win32_font_face_create_for_hfont(font->hfont); - } else { - [font release]; - return nil; - } + if (font->hfont) + { + unscaled = cairo_win32_font_face_create_for_hfont(font->hfont); + } + else + { + [font release]; + return nil; + } // Create a cairo_scaled_font which we just use to access the underlying // FT_Face @@ -385,66 +397,66 @@ + (CGFontRef) createWithFontName: (CFStringRef)name cairo_font_options_t *opts = cairo_font_options_create(); cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); - + font->cairofont = cairo_scaled_font_create(unscaled, &ident, &ident, opts); - + cairo_font_options_destroy(opts); - - - - + + + + // Get metrics - + HDC hdc = CreateCompatibleDC(NULL); SelectObject(hdc, font->hfont); - - + + UINT metricsSize = GetOutlineTextMetrics(hdc, 0, NULL); if (metricsSize != 0) - { - LPOUTLINETEXTMETRIC metricsData = malloc(metricsSize); - GetOutlineTextMetrics(hdc, metricsSize, metricsData); - - font->unitsPerEm = metricsData->otmEMSquare; - - // FIXME: get real values - font->fullName = @""; - font->postScriptName = @""; - font->ascent = 2000; - font->capHeight = 2000; - font->descent = 500; - font->fontBBox = CGRectMake(0,0,2000,2000); - font->italicAngle = 0; - font->leading = 500; - font->stemV = 500; - font->xHeight = 2000; - - free(metricsData); - } + { + LPOUTLINETEXTMETRIC metricsData = malloc(metricsSize); + GetOutlineTextMetrics(hdc, metricsSize, metricsData); + + font->unitsPerEm = metricsData->otmEMSquare; + + // FIXME: get real values + font->fullName = @""; + font->postScriptName = @""; + font->ascent = 2000; + font->capHeight = 2000; + font->descent = 500; + font->fontBBox = CGRectMake(0,0,2000,2000); + font->italicAngle = 0; + font->leading = 500; + font->stemV = 500; + font->xHeight = 2000; + + free(metricsData); + } else - { - printf("CGCreateFontWithName: Warning: couldn't get font metrics"); - } - + { + printf("CGCreateFontWithName: Warning: couldn't get font metrics"); + } + /* Get the number of glyphs from the 'post' table */ font->numberOfGlyphs = 0; DWORD tableName = GSSwapBigI32ToHost('post'); - DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); + DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); if (size != GDI_ERROR) - { - struct post_table *data = malloc(size); - if (size == GetFontData(hdc, tableName, 0, data, size)) { - font->numberOfGlyphs = GSSwapBigI16ToHost(data->numberOfGlyphs); + struct post_table *data = malloc(size); + if (size == GetFontData(hdc, tableName, 0, data, size)) + { + font->numberOfGlyphs = GSSwapBigI16ToHost(data->numberOfGlyphs); + } } - } if (font->numberOfGlyphs == 0) - { - printf("CGCreateFontWithName: Warning: font has 0 glyphs"); - } + { + printf("CGCreateFontWithName: Warning: font has 0 glyphs"); + } DeleteDC(hdc); diff --git a/Source/OpalGraphics/cairo/CairoFontX11.h b/Source/OpalGraphics/cairo/CairoFontX11.h index 1c8b1f2..6fa7054 100644 --- a/Source/OpalGraphics/cairo/CairoFontX11.h +++ b/Source/OpalGraphics/cairo/CairoFontX11.h @@ -11,12 +11,12 @@ 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 @@ -27,6 +27,6 @@ @interface CairoFontX11 : CairoFont { - + } @end diff --git a/Source/OpalGraphics/cairo/CairoFontX11.m b/Source/OpalGraphics/cairo/CairoFontX11.m index 88a7a7a..289e822 100644 --- a/Source/OpalGraphics/cairo/CairoFontX11.m +++ b/Source/OpalGraphics/cairo/CairoFontX11.m @@ -13,12 +13,12 @@ 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 @@ -59,13 +59,15 @@ static FT_ListRec pattern_cache; -typedef struct cache_entry { +typedef struct cache_entry +{ FT_ListNodeRec node; unsigned int hash; FcPattern *pat; } cache_entry; -typedef struct iter_state { +typedef struct iter_state +{ unsigned int hash; FcPattern *pat; int cnt; @@ -78,11 +80,12 @@ static FT_Error cache_iterator(FT_ListNode node, void *user) state->cnt++; if (!node) return 1; - if (entry->hash == state->hash) { - state->pat = entry->pat; - FT_List_Up(&pattern_cache, node); - return 2; - } + if (entry->hash == state->hash) + { + state->pat = entry->pat; + FT_List_Up(&pattern_cache, node); + return 2; + } return 0; } @@ -111,23 +114,25 @@ static unsigned int hash_string(const char *str) state.pat = opal_FcPatternCreateFromName(name); if (!state.pat) return NULL; - if (state.cnt >= CACHE_SIZE) { /* Remove last entry from the cache */ - FT_ListNode node; + if (state.cnt >= CACHE_SIZE) /* Remove last entry from the cache */ + { + FT_ListNode node; - node = pattern_cache.tail; - FT_List_Remove(&pattern_cache, node); - FcPatternDestroy(((cache_entry *)node)->pat); - free(node); - } + node = pattern_cache.tail; + FT_List_Remove(&pattern_cache, node); + FcPatternDestroy(((cache_entry *)node)->pat); + free(node); + } /* Add new entry to the cache */ { cache_entry *entry; entry = calloc(1, sizeof(*entry)); - if (!entry) { - NSLog(@"calloc failed"); - return state.pat; - } + if (!entry) + { + NSLog(@"calloc failed"); + return state.pat; + } entry->hash = state.hash; entry->pat = state.pat; FT_List_Insert(&pattern_cache, (FT_ListNode)entry); @@ -152,33 +157,38 @@ - (CFStringRef) copyFullName; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CFStringRef result = NULL; - - if (ft_face) { - const int FULL_NAME = 4; - FT_SfntName nameStruct; - if (0 == FT_Get_Sfnt_Name(ft_face, FULL_NAME, &nameStruct)) + + if (ft_face) { - if (nameStruct.platform_id == TT_PLATFORM_APPLE_UNICODE) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; - } - else if (nameStruct.platform_id == TT_PLATFORM_MACINTOSH && - nameStruct.encoding_id == TT_MAC_ID_ROMAN) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: nameStruct.string_len encoding: NSMacOSRomanStringEncoding]; - } - else if (nameStruct.platform_id == TT_PLATFORM_MICROSOFT && - nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; - } - } - - if (NULL != ft_face->family_name) { - result = [[NSString alloc] initWithUTF8String: ft_face->family_name]; + const int FULL_NAME = 4; + FT_SfntName nameStruct; + if (0 == FT_Get_Sfnt_Name(ft_face, FULL_NAME, &nameStruct)) + { + if (nameStruct.platform_id == TT_PLATFORM_APPLE_UNICODE) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; + } + else if (nameStruct.platform_id == TT_PLATFORM_MACINTOSH && + nameStruct.encoding_id == TT_MAC_ID_ROMAN) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSMacOSRomanStringEncoding]; + } + else if (nameStruct.platform_id == TT_PLATFORM_MICROSOFT && + nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; + } + } + + if (NULL != ft_face->family_name) + { + result = [[NSString alloc] initWithUTF8String: ft_face->family_name]; + } } - } - + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -187,13 +197,14 @@ - (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CFStringRef result = NULL; - - if (ft_face) { - char buffer[256]; - FT_Get_Glyph_Name(ft_face, glyph, buffer, 256); - result = [[NSString alloc] initWithUTF8String: buffer]; - } - + + if (ft_face) + { + char buffer[256]; + FT_Get_Glyph_Name(ft_face, glyph, buffer, 256); + result = [[NSString alloc] initWithUTF8String: buffer]; + } + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -202,15 +213,17 @@ - (CFStringRef) copyPostScriptName; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CFStringRef result = NULL; - - if (ft_face) { - const char *psname = FT_Get_Postscript_Name(ft_face); - if (NULL != psname) { - result = [[NSString alloc] initWithUTF8String: psname]; - } - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); + + if (ft_face) + { + const char *psname = FT_Get_Postscript_Name(ft_face); + if (NULL != psname) + { + result = [[NSString alloc] initWithUTF8String: psname]; + } + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -218,22 +231,26 @@ - (CFDataRef) copyTableForTag: (uint32_t)tag; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CFDataRef result = NULL; - - if (ft_face) { - FT_ULong length = 0; - void *buffer; - - if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, NULL, &length)) { - buffer = malloc(length); - if (buffer) { - if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, buffer, &length)) { - result = [[NSData alloc] initWithBytes: buffer length: length]; + + if (ft_face) + { + FT_ULong length = 0; + void *buffer; + + if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, NULL, &length)) + { + buffer = malloc(length); + if (buffer) + { + if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, buffer, &length)) + { + result = [[NSData alloc] initWithBytes: buffer length: length]; + } + free(buffer); + } } - free(buffer); - } } - } - + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -242,19 +259,20 @@ - (CFArrayRef) copyTableTags; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CFMutableArrayRef result = [[NSMutableArray alloc] init]; - - if (ft_face) { - unsigned int i = 0; - unsigned long tag, length; - while (FT_Err_Table_Missing != - FT_Sfnt_Table_Info(ft_face, i, &tag, &length)) + if (ft_face) { - // FIXME: see CGFontCopyTableTags reference, the CFArray should contain raw tags and not NSNumbers - [result addObject: [NSNumber numberWithInt: tag]]; - i++; + unsigned int i = 0; + unsigned long tag, length; + + while (FT_Err_Table_Missing != + FT_Sfnt_Table_Info(ft_face, i, &tag, &length)) + { + // FIXME: see CGFontCopyTableTags reference, the CFArray should contain raw tags and not NSNumbers + [result addObject: [NSNumber numberWithInt: tag]]; + i++; + } } - } cairo_ft_scaled_font_unlock_face(self->cairofont); return result; @@ -292,12 +310,13 @@ - (int) capHeight; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); int result = 0; - + TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); - if (NULL != os2table) { - result = os2table->sCapHeight; - } - + if (NULL != os2table) + { + result = os2table->sCapHeight; + } + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -316,11 +335,11 @@ - (CGRect) fontBBox; FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); FT_BBox bbox = ft_face->bbox; CGRect result = CGRectMake( - bbox.xMin, - bbox.yMin, - bbox.xMax - bbox.xMin, - bbox.yMax - bbox.yMin); - + bbox.xMin, + bbox.yMin, + bbox.xMax - bbox.xMin, + bbox.yMax - bbox.yMin); + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -329,10 +348,10 @@ - (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CGGlyph result = 0; - + const char *name = [glyphName UTF8String]; result = (CGGlyph)FT_Get_Name_Index(ft_face, (FT_String*)name); - + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -349,12 +368,14 @@ - (CGFloat) italicAngle; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); CGFloat result = 0; - - TT_Postscript *pstable = (TT_Postscript *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_post); - if (NULL != pstable) { - result = pstable->italicAngle; - } - + + TT_Postscript *pstable = (TT_Postscript *)FT_Get_Sfnt_Table(ft_face, + ft_sfnt_post); + if (NULL != pstable) + { + result = pstable->italicAngle; + } + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -362,10 +383,10 @@ - (CGFloat) italicAngle; - (int) leading; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - + // see http://www.typophile.com/node/13081 - int result = ft_face->height - ft_face->ascender + - ft_face->descender; + int result = ft_face->height - ft_face->ascender + + ft_face->descender; cairo_ft_scaled_font_unlock_face(self->cairofont); return result; @@ -374,9 +395,9 @@ - (int) leading; - (size_t) numberOfGlyphs; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - + int result = ft_face->num_glyphs; - + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -389,9 +410,9 @@ - (CGFloat) stemV; - (int) unitsPerEm; { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - + int result = ft_face->units_per_EM; - + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -400,12 +421,13 @@ - (int) xHeight { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); int result = 0; - + TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); - if (NULL != os2table) { - result = os2table->sxHeight; - } - + if (NULL != os2table) + { + result = os2table->sxHeight; + } + cairo_ft_scaled_font_unlock_face(self->cairofont); return result; } @@ -444,12 +466,15 @@ + (CGFontRef) createWithFcPattern: (FcPattern *)pat CairoFontX11 *font = [[CairoFontX11 alloc] init]; if (!font) return NULL; - if(pat) { - unscaled = cairo_ft_font_face_create_for_pattern(pat); - } else { - CGFontRelease(font); - return NULL; - } + if (pat) + { + unscaled = cairo_ft_font_face_create_for_pattern(pat); + } + else + { + CGFontRelease(font); + return NULL; + } // Create a cairo_scaled_font which we just use to access the underlying // FT_Face @@ -460,10 +485,10 @@ + (CGFontRef) createWithFcPattern: (FcPattern *)pat cairo_font_options_t *opts = cairo_font_options_create(); cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); - + font->cairofont = cairo_scaled_font_create(unscaled, - &ident, &ident, opts); - + &ident, &ident, opts); + cairo_font_options_destroy(opts); font->fullName = [font copyFullName]; @@ -489,31 +514,32 @@ + (CGFontRef) createWithPlatformFont: (void *)platformFontReference; //FIXME: Not threadsafe - (bool) getGlyphAdvances: (const CGGlyph[])glyphs - : (size_t)count - : (int[]) advances +: (size_t)count +: (int[]) advances { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); for (size_t i=0; iglyph->metrics.horiAdvance; - } + { + FT_Load_Glyph(ft_face, glyphs[i], FT_LOAD_NO_SCALE); + advances[i] = ft_face->glyph->metrics.horiAdvance; + } cairo_ft_scaled_font_unlock_face(self->cairofont); return true; } //FIXME: Not threadsafe - (bool) getGlyphBBoxes: (const CGGlyph[])glyphs - : (size_t)count - : (CGRect[])bboxes + : (size_t)count + : (CGRect[])bboxes { FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); for (size_t i=0; iglyph->metrics; - bboxes[i] = CGRectMake(m.horiBearingX, m.horiBearingY - m.height, m.width, m.height); - } + { + FT_Load_Glyph(ft_face, glyphs[i], FT_LOAD_NO_SCALE); + FT_Glyph_Metrics m = ft_face->glyph->metrics; + bboxes[i] = CGRectMake(m.horiBearingX, m.horiBearingY - m.height, m.width, + m.height); + } cairo_ft_scaled_font_unlock_face(self->cairofont); return true; } @@ -544,25 +570,27 @@ - (bool) getGlyphBBoxes: (const CGGlyph[])glyphs /* Try to parse a Postscript font name and make a corresponding pattern */ /* Consider everything up to the first dash to be the family name */ traits = strchr(family, '-'); - if (traits) { - *traits = '\0'; - traits++; - } + if (traits) + { + *traits = '\0'; + traits++; + } success = FcPatternAddString(pat, FC_FAMILY, (FcChar8 *)family); if (!success) goto error; - if (traits) { - /* FIXME: The following is incomplete and may also be wrong */ - /* Fontconfig assumes Medium Roman Regular so don't care about theese */ - if (strstr(traits, "Bold")) - success |= FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); - if (strstr(traits, "Italic")) - success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_ITALIC); - if (strstr(traits, "Oblique")) - success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_OBLIQUE); - if (strstr(traits, "Condensed")) - success |= FcPatternAddInteger(pat, FC_WIDTH, FC_WIDTH_CONDENSED); - if (!success) goto error; - } + if (traits) + { + /* FIXME: The following is incomplete and may also be wrong */ + /* Fontconfig assumes Medium Roman Regular so don't care about theese */ + if (strstr(traits, "Bold")) + success |= FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); + if (strstr(traits, "Italic")) + success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_ITALIC); + if (strstr(traits, "Oblique")) + success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_OBLIQUE); + if (strstr(traits, "Condensed")) + success |= FcPatternAddInteger(pat, FC_WIDTH, FC_WIDTH_CONDENSED); + if (!success) goto error; + } success = FcConfigSubstitute(NULL, pat, FcMatchPattern); if (!success) goto error; diff --git a/Source/OpalGraphics/cairo/StandardGlyphNames.h b/Source/OpalGraphics/cairo/StandardGlyphNames.h index f515988..c541e8b 100644 --- a/Source/OpalGraphics/cairo/StandardGlyphNames.h +++ b/Source/OpalGraphics/cairo/StandardGlyphNames.h @@ -11,12 +11,12 @@ 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 @@ -24,5 +24,5 @@ /** * Standatd glyph names 0-257 - */ + */ const char * const StandardGlyphNames[258]; \ No newline at end of file diff --git a/Source/OpalGraphics/cairo/StandardGlyphNames.m b/Source/OpalGraphics/cairo/StandardGlyphNames.m index fef60bd..bedea86 100644 --- a/Source/OpalGraphics/cairo/StandardGlyphNames.m +++ b/Source/OpalGraphics/cairo/StandardGlyphNames.m @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalGraphics/image/OPImageCodecJPEG.m b/Source/OpalGraphics/image/OPImageCodecJPEG.m index b76e004..d17e9bb 100644 --- a/Source/OpalGraphics/image/OPImageCodecJPEG.m +++ b/Source/OpalGraphics/image/OPImageCodecJPEG.m @@ -5,10 +5,10 @@ Copyright (C) 2010 Free Software Foundation, Inc. Written by: Eric Wasylishen - Date: July 2010 + Date: July 2010 Written by: Stefan Kleine Stegemann Date: Nov 2003 - + This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or @@ -23,10 +23,10 @@ You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. - If not, see or write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ +*/ // Opal Includes @@ -65,7 +65,7 @@ /* ----------------------------------------------------------- The following functions are for interacting with the - jpeg library + jpeg library ----------------------------------------------------------- */ /* A custom error manager for the jpeg library @@ -86,7 +86,7 @@ * libjpegs default error handling would exit * after printing the error. */ static void gs_jpeg_error_exit(j_common_ptr cinfo) -{ +{ gs_jpeg_error_mgr_ptr myerr = (gs_jpeg_error_mgr_ptr)cinfo->err; (*cinfo->err->output_message)(cinfo); [NSException raise: @"JPEGException" format: @"%@", myerr->message]; @@ -106,7 +106,8 @@ static void gs_jpeg_output_message(j_common_ptr cinfo) } /* Initialize our error manager */ -static void gs_jpeg_error_mgr_create(j_common_ptr cinfo, gs_jpeg_error_mgr_ptr errMgr) +static void gs_jpeg_error_mgr_create(j_common_ptr cinfo, + gs_jpeg_error_mgr_ptr errMgr) { cinfo->err = jpeg_std_error(&errMgr->parent); errMgr->parent.error_exit = gs_jpeg_error_exit; @@ -133,20 +134,21 @@ static void gs_jpeg_error_mgr_create(j_common_ptr cinfo, gs_jpeg_error_mgr_ptr e static void gs_init_source(j_decompress_ptr cinfo) { - /* nothing to do here */ + /* nothing to do here */ } static boolean gs_fill_input_buffer(j_decompress_ptr cinfo) { gs_jpeg_source_ptr src = (gs_jpeg_source_ptr)cinfo->src; - src->parent.bytes_in_buffer = OPDataProviderGetBytes(src->dp, src->buffer, OPAL_BUFFER_SIZE); + src->parent.bytes_in_buffer = OPDataProviderGetBytes(src->dp, src->buffer, + OPAL_BUFFER_SIZE); src->parent.next_input_byte = src->buffer; - + if (src->parent.bytes_in_buffer == 0) - { - ERREXIT(cinfo, JERR_INPUT_EMPTY); - } + { + ERREXIT(cinfo, JERR_INPUT_EMPTY); + } return TRUE; } @@ -166,10 +168,11 @@ static void gs_term_source(j_decompress_ptr cinfo) * caller is responsible for providing and releasing the * data. After decompression is done, gs_jpeg_memory_src_destroy * has to be called. */ -static void gs_jpeg_memory_src_create(j_decompress_ptr cinfo, CGDataProviderRef dp) +static void gs_jpeg_memory_src_create(j_decompress_ptr cinfo, + CGDataProviderRef dp) { gs_jpeg_source_ptr src; - + cinfo->src = (struct jpeg_source_mgr *)malloc(sizeof(gs_jpeg_source_mgr)); src = (gs_jpeg_source_ptr)cinfo->src; @@ -191,10 +194,10 @@ static void gs_jpeg_memory_src_create(j_decompress_ptr cinfo, CGDataProviderRef static void gs_jpeg_memory_src_destroy(j_decompress_ptr cinfo) { gs_jpeg_source_ptr src = (gs_jpeg_source_ptr)cinfo->src; - - CGDataProviderRelease(src->dp); + + CGDataProviderRelease(src->dp); free(src->buffer); - + free(src); cinfo->src = NULL; } @@ -223,7 +226,7 @@ static void gs_jpeg_memory_src_destroy(j_decompress_ptr cinfo) static void gs_init_destination (j_compress_ptr cinfo) { gs_jpeg_dest_ptr dest = (gs_jpeg_dest_ptr) cinfo->dest; - + dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = OPAL_BUFFER_SIZE; } @@ -262,23 +265,25 @@ static boolean gs_empty_output_buffer (j_compress_ptr cinfo) static void gs_term_destination (j_compress_ptr cinfo) { gs_jpeg_dest_ptr dest = (gs_jpeg_dest_ptr) cinfo->dest; - - OPDataConsumerPutBytes(dest->dc, dest->buffer, OPAL_BUFFER_SIZE - dest->pub.free_in_buffer); + + OPDataConsumerPutBytes(dest->dc, dest->buffer, + OPAL_BUFFER_SIZE - dest->pub.free_in_buffer); } -static void gs_jpeg_CGDataConsumer_dest_create (j_compress_ptr cinfo, CGDataConsumerRef dc) +static void gs_jpeg_CGDataConsumer_dest_create (j_compress_ptr cinfo, + CGDataConsumerRef dc) { gs_jpeg_dest_ptr dest; cinfo->dest = (struct jpeg_destination_mgr*) - malloc (sizeof (gs_jpeg_destination_mgr)); + malloc (sizeof (gs_jpeg_destination_mgr)); dest = (gs_jpeg_dest_ptr) cinfo->dest; dest->pub.init_destination = gs_init_destination; dest->pub.empty_output_buffer = gs_empty_output_buffer; dest->pub.term_destination = gs_term_destination; - + dest->dc = CGDataConsumerRetain(dc); dest->buffer = malloc(OPAL_BUFFER_SIZE); } @@ -316,13 +321,13 @@ + (void)load + (NSArray *)typeIdentifiers { - return [NSArray arrayWithObject: @"public.jpeg"]; + return [NSArray arrayWithObject: @"public.jpeg"]; } - (id)initWithProvider: (CGDataProviderRef)provider { self = [super init]; - + dp = CGDataProviderRetain(provider); OPDataProviderRewind(dp); @@ -351,7 +356,7 @@ - (id)initWithProvider: (CGDataProviderRef)provider NS_VALUERETURN(nil, id); } NS_ENDHANDLER - + gs_jpeg_memory_src_destroy(&cinfo); jpeg_destroy_decompress(&cinfo); @@ -363,15 +368,16 @@ - (void)dealloc CGDataProviderRelease(dp); [super dealloc]; } - + - (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts { return [NSDictionary dictionary]; } -- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: (size_t)index +- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: + (size_t)index { - return [NSDictionary dictionary]; + return [NSDictionary dictionary]; } - (size_t)count @@ -384,13 +390,13 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts struct jpeg_decompress_struct cinfo; struct gs_jpeg_error_mgr jerrMgr; CGImageRef img = NULL;; - + if (!(self = [super init])) return NULL; memset((void*)&cinfo, 0, sizeof(struct jpeg_decompress_struct)); gs_jpeg_error_mgr_create((j_common_ptr)&cinfo, &jerrMgr); - + NS_DURING { /* jpeg-decompression */ @@ -398,55 +404,55 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts JSAMPARRAY sclbuffer = NULL; unsigned char *imgbuffer = NULL; BOOL isProgressive; - + jpeg_create_decompress(&cinfo); - + /* Establish our own data source manager */ OPDataProviderRewind(dp); gs_jpeg_memory_src_create(&cinfo, dp); - + jpeg_read_header(&cinfo, TRUE); - + /* we use RGB as target color space; others are not yet supported */ cinfo.out_color_space = JCS_RGB; - + /* decompress */ jpeg_start_decompress(&cinfo); - + /* process the decompressed data */ const JDIMENSION samplesPerRow = cinfo.output_width * cinfo.output_components; const JDIMENSION rowSize = samplesPerRow * sizeof(unsigned char); NSAssert(sizeof(JSAMPLE) == sizeof(unsigned char), - @"unexpected sample size"); - + @"unexpected sample size"); + sclbuffer = cinfo.mem->alloc_sarray((j_common_ptr)&cinfo, JPOOL_IMAGE, samplesPerRow, cinfo.rec_outbuf_height); /* sclbuffer is freed when cinfo is destroyed */ - + imgbuffer = malloc(cinfo.output_height * rowSize); if (!imgbuffer) { NSLog(@"NSBitmapImageRep+JPEG: failed to allocated image buffer"); return NULL; } - + i = 0; while (cinfo.output_scanline < cinfo.output_height) { sclcount = jpeg_read_scanlines(&cinfo, sclbuffer, cinfo.rec_outbuf_height); - + for (j = 0; j < sclcount; j++) { - // copy a row to the image buffer - memcpy((imgbuffer + (i * rowSize)), - *(sclbuffer + (j * rowSize)), - rowSize); - i++; + // copy a row to the image buffer + memcpy((imgbuffer + (i * rowSize)), + *(sclbuffer + (j * rowSize)), + rowSize); + i++; } } - + isProgressive = cinfo.progressive_mode; /* done */ @@ -454,28 +460,30 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts // Create the CGImage - NSData *imgData = [[NSData alloc] initWithBytesNoCopy:imgbuffer length:cinfo.output_height * rowSize freeWhenDone:YES]; - CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)imgData); + NSData *imgData = [[NSData alloc] initWithBytesNoCopy: imgbuffer length: + cinfo.output_height * rowSize freeWhenDone: YES]; + CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData(( + CFDataRef)imgData); [imgData release]; - + CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - + img = CGImageCreate( - cinfo.output_width, - cinfo.output_height, - BITS_IN_JSAMPLE, - cinfo.output_components * BITS_IN_JSAMPLE, - rowSize, - cs, - kCGBitmapByteOrderDefault | kCGImageAlphaNone, - imgDataProvider, - NULL, - true, - kCGRenderingIntentDefault); + cinfo.output_width, + cinfo.output_height, + BITS_IN_JSAMPLE, + cinfo.output_components * BITS_IN_JSAMPLE, + rowSize, + cs, + kCGBitmapByteOrderDefault | kCGImageAlphaNone, + imgDataProvider, + NULL, + true, + kCGRenderingIntentDefault); CGColorSpaceRelease(cs); CGDataProviderRelease(imgDataProvider); - } + } NS_HANDLER { gs_jpeg_memory_src_destroy(&cinfo); @@ -487,17 +495,18 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts gs_jpeg_memory_src_destroy(&cinfo); jpeg_destroy_decompress(&cinfo); - + if (jerrMgr.parent.num_warnings) { NSLog(@"NSBitmapImageRep+JPEG: %ld warnings during jpeg decompression, " - @"image may be corrupted", jerrMgr.parent.num_warnings); + @"image may be corrupted", jerrMgr.parent.num_warnings); } - + return img; } -- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)opts +- (CGImageRef)createThumbnailAtIndex: (size_t)index options: + (NSDictionary*)opts { return NULL; } @@ -517,7 +526,8 @@ - (NSString*)type return @"public.jpeg"; } -- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate +- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: + (bool)finalUpdate { ; } @@ -554,15 +564,15 @@ - (id) initWithDataConsumer: (CGDataConsumerRef)consumer options: (CFDictionaryRef)options { self = [super init]; - + if (![(NSString*)type isEqual: @"public.jpeg"] || count != 1) - { - [self release]; - return nil; - } - + { + [self release]; + return nil; + } + dc = [consumer retain]; - + return self; } @@ -571,7 +581,7 @@ - (void)dealloc CGDataConsumerRelease(dc); [props release]; CGImageRelease(img); - [super dealloc]; + [super dealloc]; } - (void) setProperties: (CFDictionaryRef)properties @@ -592,69 +602,72 @@ - (bool) finalize memset((void*)&cinfo, 0, sizeof(struct jpeg_compress_struct)); gs_jpeg_error_mgr_create((j_common_ptr)&cinfo, &jerrMgr); - + NS_DURING { // initialize libjpeg for compression - + jpeg_create_compress(&cinfo); - - // specify the destination for the compressed data.. - + + // specify the destination for the compressed data.. + gs_jpeg_CGDataConsumer_dest_create(&cinfo, dc); - - int quality = 90; + + int quality = 90; const int row_stride = CGImageGetBytesPerRow(img); - + // set parameters - + cinfo.image_width = CGImageGetWidth(img); cinfo.image_height = CGImageGetHeight(img); - - cinfo.input_components = CGColorSpaceGetNumberOfComponents(CGImageGetColorSpace(img)); - + + cinfo.input_components = CGColorSpaceGetNumberOfComponents( + CGImageGetColorSpace(img)); + switch (CGColorSpaceGetModel(CGImageGetColorSpace(img))) - { - case kCGColorSpaceModelMonochrome: - cinfo.in_color_space = JCS_GRAYSCALE; - break; - case kCGColorSpaceModelCMYK: - cinfo.in_color_space = JCS_CMYK; - break; - case kCGColorSpaceModelRGB: - cinfo.in_color_space = JCS_RGB; - break; - case kCGColorSpaceModelUnknown: - cinfo.in_color_space = JCS_UNKNOWN; - NSLog(@"JPEG image rep: Using unknown color space with unpredictable results"); - break; - default: - NSLog(@"JPEG image rep: Unknown color space"); - return false; - } - + { + case kCGColorSpaceModelMonochrome: + cinfo.in_color_space = JCS_GRAYSCALE; + break; + case kCGColorSpaceModelCMYK: + cinfo.in_color_space = JCS_CMYK; + break; + case kCGColorSpaceModelRGB: + cinfo.in_color_space = JCS_RGB; + break; + case kCGColorSpaceModelUnknown: + cinfo.in_color_space = JCS_UNKNOWN; + NSLog(@"JPEG image rep: Using unknown color space with unpredictable results"); + break; + default: + NSLog(@"JPEG image rep: Unknown color space"); + return false; + } + jpeg_set_defaults (&cinfo); - + // set quality - - NSNumber *qualityNumber = [(NSDictionary*)props objectForKey: (NSString*)kCGImageDestinationLossyCompressionQuality]; + + NSNumber *qualityNumber = [(NSDictionary*)props objectForKey: + (NSString*)kCGImageDestinationLossyCompressionQuality]; if (qualityNumber != nil) - { - quality = (int) (((1-[qualityNumber floatValue]) / 255.0) * 100.0); - } - + { + quality = (int) (((1-[qualityNumber floatValue]) / 255.0) * 100.0); + } + // set progressive mode - NSNumber *progressiveNumber = [(NSDictionary*)props objectForKey: @"NSImageProgressive"]; + NSNumber *progressiveNumber = [(NSDictionary*)props objectForKey: + @"NSImageProgressive"]; if (progressiveNumber != nil) - { - cinfo.progressive_mode = [progressiveNumber boolValue]; - } - + { + cinfo.progressive_mode = [progressiveNumber boolValue]; + } + // compress the image - + jpeg_set_quality (&cinfo, quality, TRUE); jpeg_start_compress (&cinfo, TRUE); - + /* if (isRGB && [self hasAlpha]) // strip alpha channel before encoding { @@ -687,27 +700,27 @@ - (bool) finalize CGDataProviderRef dp = CGImageGetDataProvider(img); OPDataProviderRewind(dp); while (cinfo.next_scanline < cinfo.image_height) - { - // FIXME: strip alpha - OPDataProviderGetBytes(dp, rowdata, row_stride); - jpeg_write_scanlines(&cinfo, row_pointer, 1); - } + { + // FIXME: strip alpha + OPDataProviderGetBytes(dp, rowdata, row_stride); + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } free(rowdata); - + jpeg_finish_compress(&cinfo); - + gs_jpeg_memory_dest_destroy (&cinfo); - + jpeg_destroy_compress(&cinfo); } NS_HANDLER { - gs_jpeg_memory_dest_destroy(&cinfo); - jpeg_destroy_compress(&cinfo); - NS_VALUERETURN(false, bool); + gs_jpeg_memory_dest_destroy(&cinfo); + jpeg_destroy_compress(&cinfo); + NS_VALUERETURN(false, bool); } NS_ENDHANDLER - + return true; } diff --git a/Source/OpalGraphics/image/OPImageCodecPNG.m b/Source/OpalGraphics/image/OPImageCodecPNG.m index ef32a1a..975824a 100644 --- a/Source/OpalGraphics/image/OPImageCodecPNG.m +++ b/Source/OpalGraphics/image/OPImageCodecPNG.m @@ -6,10 +6,10 @@ Copyright (C) 2010 Free Software Foundation, Inc. Written by: Eric Wasylishen - Date: July 2010 + Date: July 2010 Written by: Alexander Malmberg Date: 2003-12-07 - + This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or @@ -24,8 +24,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. - If not, see or write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ @@ -66,13 +66,14 @@ static void opal_png_error_fn(png_structp png_ptr, png_const_charp error_msg) [NSException raise: @"PNGException" format: @"%s", error_msg]; } -static void opal_png_warning_fn(png_structp png_ptr, png_const_charp warning_msg) +static void opal_png_warning_fn(png_structp png_ptr, + png_const_charp warning_msg) { - NSLog(@"PNG Warning: '%s'", warning_msg); + NSLog(@"PNG Warning: '%s'", warning_msg); } static void opal_png_reader_func(png_structp png_struct, png_bytep data, - png_size_t length) + png_size_t length) { CGDataProviderRef dp = (CGDataProviderRef)png_get_io_ptr(png_struct); @@ -84,7 +85,7 @@ static void opal_png_reader_func(png_structp png_struct, png_bytep data, } static void opal_png_writer_func(png_structp png_struct, png_bytep data, - png_size_t length) + png_size_t length) { CGDataConsumerRef dc = (CGDataConsumerRef)png_get_io_ptr(png_struct); OPDataConsumerPutBytes(dc, data, length); @@ -131,7 +132,7 @@ - (id)initWithProvider: (CGDataProviderRef)provider; [self release]; return nil; } - + OPDataProviderRewind(dp); return self; @@ -148,9 +149,10 @@ - (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts return [NSDictionary dictionary]; } -- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: (size_t)index +- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: + (size_t)index { - return [NSDictionary dictionary]; + return [NSDictionary dictionary]; } - (size_t)count @@ -163,16 +165,17 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts CGImageRef img = NULL; png_structp png_struct; png_infop png_info, png_end_info; - + NS_DURING { - png_struct = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, opal_png_error_fn, opal_png_warning_fn); + png_struct = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, + opal_png_error_fn, opal_png_warning_fn); if (!png_struct) { RELEASE(self); return NULL; } - + png_info = png_create_info_struct(png_struct); if (!png_info) { @@ -180,7 +183,7 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts RELEASE(self); return NULL; } - + png_end_info = png_create_info_struct(png_struct); if (!png_end_info) { @@ -190,83 +193,85 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts } png_set_read_fn(png_struct, dp, opal_png_reader_func); - + png_read_info(png_struct, png_info); - + int width = png_get_image_width(png_struct, png_info); int height = png_get_image_height(png_struct, png_info); int bytes_per_row = png_get_rowbytes(png_struct, png_info); int type = png_get_color_type(png_struct, png_info); int channels = png_get_channels(png_struct, png_info); // includes alpha int depth = png_get_bit_depth(png_struct, png_info); - + BOOL alpha = NO; CGColorSpaceRef cs = NULL; - + switch (type) - { - case PNG_COLOR_TYPE_GRAY_ALPHA: - alpha = YES; - case PNG_COLOR_TYPE_GRAY: - cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray); - break; - - case PNG_COLOR_TYPE_RGB_ALPHA: - alpha = YES; - case PNG_COLOR_TYPE_RGB: - cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - break; - - case PNG_COLOR_TYPE_PALETTE: - png_set_palette_to_rgb(png_struct); - if (png_get_valid(png_struct, png_info, PNG_INFO_tRNS)) - { + { + case PNG_COLOR_TYPE_GRAY_ALPHA: alpha = YES; - png_set_tRNS_to_alpha(png_struct); - } - cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - break; + case PNG_COLOR_TYPE_GRAY: + cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray); + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + alpha = YES; + case PNG_COLOR_TYPE_RGB: + cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + break; + + case PNG_COLOR_TYPE_PALETTE: + png_set_palette_to_rgb(png_struct); + if (png_get_valid(png_struct, png_info, PNG_INFO_tRNS)) + { + alpha = YES; + png_set_tRNS_to_alpha(png_struct); + } + cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + break; + + default: + NSLog(@"NSBitmapImageRep+PNG: unknown color type %i", type); + RELEASE(self); + return NULL; + } - default: - NSLog(@"NSBitmapImageRep+PNG: unknown color type %i", type); - RELEASE(self); - return NULL; - } - // FIXME: Handle colorspaces properly // FIXME: Handle color rendering intent // FIXME: Handle gamma // FIXME: Handle resolution // Create the CGImage - - NSMutableData *imgData = [[NSMutableData alloc] initWithLength: height * bytes_per_row]; + + NSMutableData *imgData = [[NSMutableData alloc] initWithLength: height * + bytes_per_row]; { unsigned char *row_pointers[height]; unsigned char *buf = [imgData mutableBytes]; for (int i = 0; i < height; i++) - { - row_pointers[i] = buf + (i * bytes_per_row); - } + { + row_pointers[i] = buf + (i * bytes_per_row); + } png_read_image(png_struct, row_pointers); - } - CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)imgData); + } + CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData(( + CFDataRef)imgData); [imgData release]; - + img = CGImageCreate( - width, - height, - depth, - channels * depth, - bytes_per_row, - cs, - kCGBitmapByteOrderDefault | (alpha ? kCGImageAlphaLast : kCGImageAlphaNone), - imgDataProvider, - NULL, - true, - kCGRenderingIntentDefault); - - DumpPixel([imgData bytes], @"read from png: (expecting R G B A)"); + width, + height, + depth, + channels * depth, + bytes_per_row, + cs, + kCGBitmapByteOrderDefault | (alpha ? kCGImageAlphaLast : kCGImageAlphaNone), + imgDataProvider, + NULL, + true, + kCGRenderingIntentDefault); + + DumpPixel([imgData bytes], @"read from png: (expecting R G B A)"); CGColorSpaceRelease(cs); CGDataProviderRelease(imgDataProvider); @@ -278,13 +283,14 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts NS_VALUERETURN(nil, CGImageRef); } NS_ENDHANDLER - + png_destroy_read_struct(&png_struct, &png_info, &png_end_info); - + return img; } -- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)opts +- (CGImageRef)createThumbnailAtIndex: (size_t)index options: + (NSDictionary*)opts { return nil; } @@ -304,7 +310,8 @@ - (NSString*)type return @"public.png"; } -- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate +- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: + (bool)finalUpdate { ; } @@ -338,15 +345,15 @@ - (id) initWithDataConsumer: (CGDataConsumerRef)consumer options: (CFDictionaryRef)opts { self = [super init]; - + if (![type isEqualToString: @"public.png"] || count != 1) - { - [self release]; - return nil; - } - + { + [self release]; + return nil; + } + dc = [consumer retain]; - + return self; } @@ -355,7 +362,7 @@ - (void)dealloc CGDataConsumerRelease(dc); [props release]; CGImageRelease(img); - [super dealloc]; + [super dealloc]; } - (void) setProperties: (CFDictionaryRef)properties @@ -375,20 +382,21 @@ - (bool) finalize png_infop png_info; // make the PNG structures - png_struct = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, opal_png_error_fn, opal_png_warning_fn); + png_struct = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, + opal_png_error_fn, opal_png_warning_fn); if (!png_struct) - { - return false; - } + { + return false; + } png_info = png_create_info_struct(png_struct); if (!png_info) - { - png_destroy_write_struct(&png_struct, NULL); - return false; - } + { + png_destroy_write_struct(&png_struct, NULL); + return false; + } - NS_DURING + NS_DURING { const int srcWidth = CGImageGetWidth(img); const int srcHeight = CGImageGetHeight(img); @@ -399,11 +407,13 @@ - (bool) finalize const CGColorSpaceRef srcColorSpace = CGImageGetColorSpace(img); const CGColorRenderingIntent srcIntent = CGImageGetRenderingIntent(img); - const size_t dstBitmapInfo = kCGBitmapByteOrderDefault /* unpacked */ | kCGImageAlphaLast; + const size_t dstBitmapInfo = kCGBitmapByteOrderDefault /* unpacked */ | + kCGImageAlphaLast; const size_t dstBitsPerComponent = 8; const size_t dstBitsPerPixel = 32; const size_t dstBytesPerRow = 4 * srcWidth; - const CGColorSpaceRef dstColorSpace = [CGColorSpaceCreateDeviceRGB() autorelease]; + const CGColorSpaceRef dstColorSpace = [CGColorSpaceCreateDeviceRGB() + autorelease]; // init structures #if PNG_LIBPNG_VER < 10500 @@ -413,38 +423,38 @@ - (bool) finalize #endif png_set_write_fn(png_struct, dc, opal_png_writer_func, NULL); png_set_IHDR(png_struct, png_info, srcWidth, srcHeight, 8, - PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); // with the default libpng settings, it expects unpacked, unpremultiplied RGBA png_write_info(png_struct, png_info); - + unsigned char *srcData = malloc(srcBytesPerRow); unsigned char *dstData = malloc(dstBytesPerRow); CGDataProviderRef dp = CGImageGetDataProvider(img); OPDataProviderRewind(dp); - for (int j=0; j [data length] && !mutable) - { - pos = [data length]; - } + { + pos = [data length]; + } return pos; } - (size_t)size @@ -127,13 +128,13 @@ - (size_t)size - (void)map: (tdata_t*)bytes size: (toff_t*)size { if (mutable) - { - *bytes = [(NSMutableData*)data mutableBytes]; - } + { + *bytes = [(NSMutableData*)data mutableBytes]; + } else - { - *bytes = (tdata_t*)[data bytes]; - } + { + *bytes = (tdata_t*)[data bytes]; + } *size = [data length]; } @@ -198,10 +199,10 @@ - (id)initWithProvider: (CGDataProviderRef)provider; // Will be released by libtiff via OPTIFFCloseProc OPTIFFHandle *handle = [[OPTIFFHandle alloc] initWithDataProvider: provider]; - tiff = TIFFClientOpen("OPTIFFWithDataProvider", "r", handle, - OPTIFFReadProc, OPTIFFWriteProc, OPTIFFSeekProc, - OPTIFFCloseProc, OPTIFFSizeProc, OPTIFFMapProc, - OPTIFFUnmapProc); + tiff = TIFFClientOpen("OPTIFFWithDataProvider", "r", handle, + OPTIFFReadProc, OPTIFFWriteProc, OPTIFFSeekProc, + OPTIFFCloseProc, OPTIFFSizeProc, OPTIFFMapProc, + OPTIFFUnmapProc); if (tiff == NULL) { @@ -226,22 +227,23 @@ - (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts return [NSDictionary dictionary]; } -- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: (size_t)index +- (NSDictionary*)propertiesWithOptions: (NSDictionary*)opts atIndex: + (size_t)index { - return [NSDictionary dictionary]; + return [NSDictionary dictionary]; } - (size_t)count { size_t dirs = 0; if (1 == TIFFSetDirectory(tiff, 0)) - { - do { - dirs++; + do + { + dirs++; + } + while (1 == TIFFReadDirectory(tiff)); } - while (1 == TIFFReadDirectory(tiff)); - } return dirs; } @@ -249,37 +251,39 @@ - (CGImageRef)createImageAtIndex: (size_t)index options: (NSDictionary*)opts { CGImageRef img = NULL; - TIFFSetDirectory(tiff, index); - + TIFFSetDirectory(tiff, index); + uint32_t width; uint32_t height; - TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width); - TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height); + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width); + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height); - NSMutableData *imgData = [[NSMutableData alloc] initWithLength: height * width * 4]; - - if (1 == TIFFReadRGBAImageOriented(tiff, width, height, [imgData mutableBytes], - ORIENTATION_TOPLEFT, 0)) - { - CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData(imgData); - CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); + NSMutableData *imgData = [[NSMutableData alloc] initWithLength: height * width + * 4]; - img = CGImageCreate(width, height, 8, 32, 4 * width, cs, - kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, imgDataProvider, - NULL, true, kCGRenderingIntentDefault); + if (1 == TIFFReadRGBAImageOriented(tiff, width, height, [imgData mutableBytes], + ORIENTATION_TOPLEFT, 0)) + { + CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData(imgData); + CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); - DumpPixel([imgData bytes], @"read from TIFF: (expecting R G B A)"); + img = CGImageCreate(width, height, 8, 32, 4 * width, cs, + kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, imgDataProvider, + NULL, true, kCGRenderingIntentDefault); - CGColorSpaceRelease(cs); - CGDataProviderRelease(imgDataProvider); - } + DumpPixel([imgData bytes], @"read from TIFF: (expecting R G B A)"); - [imgData release]; + CGColorSpaceRelease(cs); + CGDataProviderRelease(imgDataProvider); + } + + [imgData release]; return img; } -- (CGImageRef)createThumbnailAtIndex: (size_t)index options: (NSDictionary*)opts +- (CGImageRef)createThumbnailAtIndex: (size_t)index options: + (NSDictionary*)opts { return nil; } @@ -299,7 +303,8 @@ - (NSString*)type return @"public.tiff"; } -- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: (bool)finalUpdate +- (void)updateDataProvider: (CGDataProviderRef)provider finalUpdate: + (bool)finalUpdate { ; } @@ -333,21 +338,21 @@ - (id) initWithDataConsumer: (CGDataConsumerRef)consumer options: (CFDictionaryRef)opts { self = [super init]; - + if ([type isEqualToString: @"public.tiff"] || count != 1) - { - [self release]; - return nil; - } - + { + [self release]; + return nil; + } + // Will be released by libtiff via OPTIFFCloseProc OPTIFFHandle *handle = [[OPTIFFHandle alloc] initWithDataConsumer: consumer]; - tiff = TIFFClientOpen("OPTIFFWithDataConsumer", "w", handle, - OPTIFFReadProc, OPTIFFWriteProc, OPTIFFSeekProc, - OPTIFFCloseProc, OPTIFFSizeProc, OPTIFFMapProc, - OPTIFFUnmapProc); - + tiff = TIFFClientOpen("OPTIFFWithDataConsumer", "w", handle, + OPTIFFReadProc, OPTIFFWriteProc, OPTIFFSeekProc, + OPTIFFCloseProc, OPTIFFSizeProc, OPTIFFMapProc, + OPTIFFUnmapProc); + return self; } @@ -357,7 +362,7 @@ - (void)dealloc TIFFClose(tiff); [props release]; CGImageRelease(img); - [super dealloc]; + [super dealloc]; } - (void) setProperties: (CFDictionaryRef)properties diff --git a/Source/OpalGraphics/internal/CGFontInternal.h b/Source/OpalGraphics/internal/CGFontInternal.h index 71a267c..e34174b 100644 --- a/Source/OpalGraphics/internal/CGFontInternal.h +++ b/Source/OpalGraphics/internal/CGFontInternal.h @@ -13,12 +13,12 @@ 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 @@ -87,12 +87,12 @@ typedef void FcPattern; - (bool) getGlyphAdvances: (const CGGlyph[])glyphs - : (size_t)count - : (int[]) advances; +: (size_t)count +: (int[]) advances; - (bool) getGlyphBBoxes: (const CGGlyph[])glyphs - : (size_t)count - : (CGRect[])bboxes; +: (size_t)count +: (CGRect[])bboxes; - (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; - (CGGlyph) glyphWithCharacter: (unichar)character; diff --git a/Source/OpalGraphics/opal-win32.m b/Source/OpalGraphics/opal-win32.m index 72384cd..f879d2c 100644 --- a/Source/OpalGraphics/opal-win32.m +++ b/Source/OpalGraphics/opal-win32.m @@ -6,19 +6,19 @@ Author: Eric Wasylishen Date: 2010 - + This file is part of GNUstep This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. @@ -41,7 +41,8 @@ CGContextRef opal_Win32ContextCreate(HDC hdc) GetClipBox(hdc, &r); - ctx = opal_new_CGContext(target, CGSizeMake(r.right - r.left, r.bottom - r.top)); + ctx = opal_new_CGContext(target, CGSizeMake(r.right - r.left, + r.bottom - r.top)); cairo_surface_destroy(target); diff --git a/Source/OpalGraphics/opal-x11.m b/Source/OpalGraphics/opal-x11.m index 2452cdc..91c67e4 100644 --- a/Source/OpalGraphics/opal-x11.m +++ b/Source/OpalGraphics/opal-x11.m @@ -6,19 +6,19 @@ Author: BALATON Zoltan Date: 2006 - + This file is part of GNUstep This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. @@ -33,7 +33,7 @@ /* Internal cairo API, declare it here to avoid dependencies of cairoint.h */ extern void _cairo_surface_set_device_scale(cairo_surface_t *surface, - double sx, double sy); + double sx, double sy); /* Keys we use to attach additional data to Xlib surfaces */ static cairo_user_data_key_t XWindow; @@ -57,20 +57,23 @@ - (id) initWithDisplay: (Display *) d int ret; ret = XGetWindowAttributes(d, w, &wa); - if (!ret) { - NSLog(@"XGetWindowAttributes returned %d", ret); - return nil; - } + if (!ret) + { + NSLog(@"XGetWindowAttributes returned %d", ret); + return nil; + } target = cairo_xlib_surface_create(d, w, wa.visual, wa.width, wa.height); /* May not need this but left here for reference */ ret = cairo_surface_set_user_data(target, &XWindow, (void *)w, NULL); - if (ret) { - NSLog(@"cairo_surface_set_user_data %s", cairo_status_to_string(CAIRO_STATUS_NO_MEMORY)); - cairo_surface_destroy(target); - return nil; - } + if (ret) + { + NSLog(@"cairo_surface_set_user_data %s", + cairo_status_to_string(CAIRO_STATUS_NO_MEMORY)); + cairo_surface_destroy(target); + return nil; + } /* Flip coordinate system */ //cairo_surface_set_device_offset(target, 0, wa.height); @@ -79,8 +82,8 @@ - (id) initWithDisplay: (Display *) d * in cairo and then the ScaleCTM call below and the hacks in GetCTM in * CGContext should be removed in favour of the following line: */ /* _cairo_surface_set_device_scale(target, 1.0, -1.0); */ - - // NOTE: It doesn't looks like cairo will support using both device_scale and + + // NOTE: It doesn't looks like cairo will support using both device_scale and // device_offset any time soon, so I moved the translation part of the // flip to the transformation matrix, to be consistent. // - Eric @@ -96,7 +99,8 @@ - (id) initWithDisplay: (Display *) d - (void) setSize: (CGSize) size { [super setSize: size]; - cairo_xlib_surface_set_size(cairo_get_target(self->ct), size.width, size.height); + cairo_xlib_surface_set_size(cairo_get_target(self->ct), size.width, + size.height); } - (void) flushSurface @@ -107,7 +111,7 @@ - (void) flushSurface CGContextRef OPX11ContextCreate(Display *display, Drawable drawable) { - return [[OPX11Context alloc] initWithDisplay: display + return [[OPX11Context alloc] initWithDisplay: display drawable: drawable]; } diff --git a/Source/OpalText/CTFont.m b/Source/OpalText/CTFont.m index fe45dd3..67de50e 100644 --- a/Source/OpalText/CTFont.m +++ b/Source/OpalText/CTFont.m @@ -11,12 +11,12 @@ 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 @@ -48,20 +48,31 @@ const CFStringRef kCTFontSampleTextNameKey = @"kCTFontSampleTextNameKey"; const CFStringRef kCTFontPostScriptCIDNameKey = @"kCTFontPostScriptCIDNameKey"; -const CFStringRef kCTFontVariationAxisIdentifierKey = @"kCTFontVariationAxisIdentifierKey"; -const CFStringRef kCTFontVariationAxisMinimumValueKey = @"kCTFontVariationAxisMinimumValueKey"; -const CFStringRef kCTFontVariationAxisMaximumValueKey = @"kCTFontVariationAxisMaximumValueKey"; -const CFStringRef kCTFontVariationAxisDefaultValueKey = @"kCTFontVariationAxisDefaultValueKey"; +const CFStringRef kCTFontVariationAxisIdentifierKey = + @"kCTFontVariationAxisIdentifierKey"; +const CFStringRef kCTFontVariationAxisMinimumValueKey = + @"kCTFontVariationAxisMinimumValueKey"; +const CFStringRef kCTFontVariationAxisMaximumValueKey = + @"kCTFontVariationAxisMaximumValueKey"; +const CFStringRef kCTFontVariationAxisDefaultValueKey = + @"kCTFontVariationAxisDefaultValueKey"; const CFStringRef kCTFontVariationAxisNameKey = @"kCTFontVariationAxisNameKey"; -const CFStringRef kCTFontFeatureTypeIdentifierKey = @"kCTFontFeatureTypeIdentifierKey"; +const CFStringRef kCTFontFeatureTypeIdentifierKey = + @"kCTFontFeatureTypeIdentifierKey"; const CFStringRef kCTFontFeatureTypeNameKey = @"kCTFontFeatureTypeNameKey"; -const CFStringRef kCTFontFeatureTypeExclusiveKey = @"kCTFontFeatureTypeExclusiveKey"; -const CFStringRef kCTFontFeatureTypeSelectorsKey = @"kCTFontFeatureTypeSelectorsKey"; -const CFStringRef kCTFontFeatureSelectorIdentifierKey = @"kCTFontFeatureSelectorIdentifierKey"; -const CFStringRef kCTFontFeatureSelectorNameKey = @"kCTFontFeatureSelectorNameKey"; -const CFStringRef kCTFontFeatureSelectorDefaultKey = @"kCTFontFeatureSelectorDefaultKey"; -const CFStringRef kCTFontFeatureSelectorSettingKey = @"kCTFontFeatureSelectorSettingKey"; +const CFStringRef kCTFontFeatureTypeExclusiveKey = + @"kCTFontFeatureTypeExclusiveKey"; +const CFStringRef kCTFontFeatureTypeSelectorsKey = + @"kCTFontFeatureTypeSelectorsKey"; +const CFStringRef kCTFontFeatureSelectorIdentifierKey = + @"kCTFontFeatureSelectorIdentifierKey"; +const CFStringRef kCTFontFeatureSelectorNameKey = + @"kCTFontFeatureSelectorNameKey"; +const CFStringRef kCTFontFeatureSelectorDefaultKey = + @"kCTFontFeatureSelectorDefaultKey"; +const CFStringRef kCTFontFeatureSelectorSettingKey = + @"kCTFontFeatureSelectorSettingKey"; /* Classes */ @@ -76,15 +87,18 @@ CTFontRef CTFontCreateForString( CFRange range) { NSRange nsrange = NSMakeRange(range.location, range.length); - NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:[str substringWithRange: nsrange]]; + NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString: [str + substringWithRange: nsrange]]; NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: - set, kCTFontCharacterSetAttribute, - nil]; + set, kCTFontCharacterSetAttribute, + nil]; - OPFontDescriptor *descriptor = [OPFontDescriptor fontDescriptorWithFontAttributes: attrs]; + OPFontDescriptor *descriptor = [OPFontDescriptor + fontDescriptorWithFontAttributes: attrs]; - return CTFontCreateCopyWithAttributes(base, CTFontGetSize(base), NULL, descriptor); + return CTFontCreateCopyWithAttributes(base, CTFontGetSize(base), NULL, + descriptor); } CTFontRef CTFontCreateWithFontDescriptor( @@ -92,7 +106,8 @@ CTFontRef CTFontCreateWithFontDescriptor( CGFloat size, const CGAffineTransform *matrixPtr) { - return CTFontCreateWithFontDescriptorAndOptions(descriptor, size, matrixPtr, kCTFontOptionsDefault); + return CTFontCreateWithFontDescriptorAndOptions(descriptor, size, matrixPtr, + kCTFontOptionsDefault); } CTFontRef CTFontCreateWithFontDescriptorAndOptions( @@ -104,26 +119,28 @@ CTFontRef CTFontCreateWithFontDescriptorAndOptions( NSDictionary *addedAttributes; if (size == 0.0) - { - size = 12.0; - } + { + size = 12.0; + } if (matrixPtr) - { - addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble: size], kCTFontSizeAttribute, - [NSData dataWithBytes: matrixPtr length: sizeof(CGAffineTransform)], kCTFontMatrixAttribute, - nil]; - } + { + addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble: size], kCTFontSizeAttribute, + [NSData dataWithBytes: matrixPtr length: sizeof(CGAffineTransform)], + kCTFontMatrixAttribute, + nil]; + } else - { - addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble: size], kCTFontSizeAttribute, - nil]; - } + { + addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble: size], kCTFontSizeAttribute, + nil]; + } - return [[OPFont fontWithDescriptor: [descriptor fontDescriptorByAddingAttributes: addedAttributes] - options: opts] retain]; + return [[OPFont fontWithDescriptor: [descriptor + fontDescriptorByAddingAttributes: addedAttributes] + options: opts] retain]; } CTFontRef CTFontCreateWithGraphicsFont( @@ -135,26 +152,28 @@ CTFontRef CTFontCreateWithGraphicsFont( NSDictionary *addedAttributes; if (size == 0.0) - { - size = 12.0; - } + { + size = 12.0; + } if (matrixPtr) - { - addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble: size], kCTFontSizeAttribute, - [NSData dataWithBytes: matrixPtr length: sizeof(CGAffineTransform)], kCTFontMatrixAttribute, - nil]; - } + { + addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble: size], kCTFontSizeAttribute, + [NSData dataWithBytes: matrixPtr length: sizeof(CGAffineTransform)], + kCTFontMatrixAttribute, + nil]; + } else - { - addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithDouble: size], kCTFontSizeAttribute, - nil]; - } + { + addedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble: size], kCTFontSizeAttribute, + nil]; + } return [[OPFont fontWithGraphicsFont: cgFont - additionalDescriptor: [descriptor fontDescriptorByAddingAttributes: addedAttributes]] retain]; + additionalDescriptor: [descriptor fontDescriptorByAddingAttributes: + addedAttributes]] retain]; } CTFontRef CTFontCreateWithName( @@ -162,7 +181,8 @@ CTFontRef CTFontCreateWithName( CGFloat size, const CGAffineTransform *matrixPtr) { - return CTFontCreateWithNameAndOptions(name, size, matrixPtr, kCTFontOptionsDefault); + return CTFontCreateWithNameAndOptions(name, size, matrixPtr, + kCTFontOptionsDefault); } CTFontRef CTFontCreateWithNameAndOptions( @@ -172,12 +192,14 @@ CTFontRef CTFontCreateWithNameAndOptions( CTFontOptions opts) { NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: - name, kCTFontNameAttribute, - nil]; + name, kCTFontNameAttribute, + nil]; - OPFontDescriptor *descriptor = [OPFontDescriptor fontDescriptorWithFontAttributes: attrs]; + OPFontDescriptor *descriptor = [OPFontDescriptor + fontDescriptorWithFontAttributes: attrs]; - return CTFontCreateWithFontDescriptorAndOptions(descriptor, size, matrixPtr, opts); + return CTFontCreateWithFontDescriptorAndOptions(descriptor, size, matrixPtr, + opts); } CTFontRef CTFontCreateWithPlatformFont( @@ -203,22 +225,24 @@ CTFontRef CTFontCreateUIFontForLanguage( CGFloat size, CFStringRef language) { - if ([[OPFont class] respondsToSelector:@selector(UIFontWithType:size:forLangage:)]) - { - return [[OPFont UIFontWithType: type size: size forLanguage: language] retain]; - } + if ([[OPFont class] respondsToSelector: @selector(UIFontWithType: size: + forLangage:)]) + { + return [[OPFont UIFontWithType: type size: size forLanguage: language] retain]; + } else - { - NSLog(@"Warning, Opal delegate CTFontCreateUIFontForLanguage to GNUstep gui"); - - NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: - [NSArray arrayWithObject: language], kCTFontLanguagesAttribute, - nil]; + { + NSLog(@"Warning, Opal delegate CTFontCreateUIFontForLanguage to GNUstep gui"); + + NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: + [NSArray arrayWithObject: language], kCTFontLanguagesAttribute, + nil]; - OPFontDescriptor *descriptor = [OPFontDescriptor fontDescriptorWithFontAttributes: attrs]; + OPFontDescriptor *descriptor = [OPFontDescriptor + fontDescriptorWithFontAttributes: attrs]; - return CTFontCreateWithFontDescriptor(descriptor, size, NULL); - } + return CTFontCreateWithFontDescriptor(descriptor, size, NULL); + } } /* Copying & Conversion */ @@ -249,7 +273,8 @@ CTFontRef CTFontCreateCopyWithFamily( CFStringRef family) { //FIXME: should return nil if the result doesn't have the desired family - return CTFontCreateWithFontDescriptor([[font fontDescriptor] fontDescriptorWithFamily: family], size, matrixPtr); + return CTFontCreateWithFontDescriptor([[font fontDescriptor] + fontDescriptorWithFamily: family], size, matrixPtr); } void *CTFontGetPlatformFont( @@ -485,7 +510,8 @@ CFCharacterSetRef CTFontCopyCharacterSet(CTFontRef font) CFArrayRef CTFontCopySupportedLanguages(CTFontRef font) { - return [[[font fontDescriptor] objectForKey: kCTFontLanguagesAttribute] retain]; + return [[[font fontDescriptor] objectForKey: kCTFontLanguagesAttribute] + retain]; } /* Name */ @@ -508,7 +534,7 @@ CFStringRef CTFontCopyLocalizedName( CFStringRef *language) { return [[font localizedNameForKey: key - language: language] retain]; + language: language] retain]; } CFStringRef CTFontCopyPostScriptName(CTFontRef font) diff --git a/Source/OpalText/CTFontCollection.m b/Source/OpalText/CTFontCollection.m index f3c5b2a..a900725 100644 --- a/Source/OpalText/CTFontCollection.m +++ b/Source/OpalText/CTFontCollection.m @@ -11,12 +11,12 @@ 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 @@ -26,7 +26,8 @@ /* Constants */ -const CFStringRef kCTFontCollectionRemoveDuplicatesOption = @"kCTFontCollectionRemoveDuplicatesOption"; +const CFStringRef kCTFontCollectionRemoveDuplicatesOption = + @"kCTFontCollectionRemoveDuplicatesOption"; /* Classes */ @@ -39,13 +40,14 @@ @interface CTFontCollection : NSObject } - (id)initWithAvailableFontsWithOptions: (NSDictionary*)opts; -- (id)initWithFontDescriptors: (NSArray*)descriptors +- (id)initWithFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts; - (CTFontCollection*)collectionByAddingFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts; - (NSArray*)fontDescriptors; -- (NSArray*)fontDescriptorsSortedWithCallback: (CTFontCollectionSortDescriptorsCallback)cb +- (NSArray*)fontDescriptorsSortedWithCallback: + (CTFontCollectionSortDescriptorsCallback)cb info: (void*)info; @end @@ -59,32 +61,35 @@ - (id)initWithAvailableFontsWithOptions: (NSDictionary*)opts return [self initWithFontDescriptors: allDescriptors options: opts]; } -- (id)initWithFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts +- (id)initWithFontDescriptors: (NSArray*)descriptors options: + (NSDictionary*)opts { self = [super init]; if (nil == self) - { - return nil; - } + { + return nil; + } if ([[opts objectForKey: kCTFontCollectionRemoveDuplicatesOption] boolValue]) - { - // FIXME: relies on CTFontDescriptors behaving properly in sets (-hash/-isEqual:) - _descriptors = [[[NSSet setWithArray: descriptors] allObjects] retain]; - } + { + // FIXME: relies on CTFontDescriptors behaving properly in sets (-hash/-isEqual:) + _descriptors = [[[NSSet setWithArray: descriptors] allObjects] retain]; + } else - { - _descriptors = [descriptors copy]; - } + { + _descriptors = [descriptors copy]; + } return self; } - (CTFontCollection*)collectionByAddingFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts { - NSArray *newDescriptors = [_descriptors arrayByAddingObjectsFromArray: descriptors]; - CTFontCollection *collection = [[CTFontCollection alloc] initWithFontDescriptors: newDescriptors - options: opts]; + NSArray *newDescriptors = [_descriptors arrayByAddingObjectsFromArray: + descriptors]; + CTFontCollection *collection = [[CTFontCollection alloc] + initWithFontDescriptors: newDescriptors + options: opts]; return [collection autorelease]; } @@ -93,10 +98,12 @@ - (NSArray*)fontDescriptors return _descriptors; } -- (NSArray*)fontDescriptorsSortedWithCallback: (CTFontCollectionSortDescriptorsCallback)cb +- (NSArray*)fontDescriptorsSortedWithCallback: + (CTFontCollectionSortDescriptorsCallback)cb info: (void*)info { - return [_descriptors sortedArrayUsingFunction: (NSComparisonResult (*)(id, id, void*))cb + return [_descriptors sortedArrayUsingFunction: (NSComparisonResult (*)(id, id, + void*))cb context: info]; } @@ -110,15 +117,18 @@ CTFontCollectionRef CTFontCollectionCreateCopyWithFontDescriptors( CFArrayRef descriptors, CFDictionaryRef opts) { - return [[base collectionByAddingFontDescriptors: descriptors options: opts] retain]; + return [[base collectionByAddingFontDescriptors: descriptors options: opts] + retain]; } -CTFontCollectionRef CTFontCollectionCreateFromAvailableFonts(CFDictionaryRef opts) +CTFontCollectionRef CTFontCollectionCreateFromAvailableFonts( + CFDictionaryRef opts) { return [[CTFontCollection alloc] initWithAvailableFontsWithOptions: opts]; } -CFArrayRef CTFontCollectionCreateMatchingFontDescriptors(CTFontCollectionRef collection) +CFArrayRef CTFontCollectionCreateMatchingFontDescriptors( + CTFontCollectionRef collection) { return [[collection fontDescriptors] retain]; } @@ -135,7 +145,8 @@ CTFontCollectionRef CTFontCollectionCreateWithFontDescriptors( CFArrayRef descriptors, CFDictionaryRef opts) { - return [[CTFontCollection alloc] initWithFontDescriptors: descriptors options: opts]; + return [[CTFontCollection alloc] initWithFontDescriptors: descriptors options: + opts]; } CFTypeID CTFontCollectionGetTypeID() diff --git a/Source/OpalText/CTFontDescriptor.m b/Source/OpalText/CTFontDescriptor.m index 983265c..3877f8c 100644 --- a/Source/OpalText/CTFontDescriptor.m +++ b/Source/OpalText/CTFontDescriptor.m @@ -11,12 +11,12 @@ 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 @@ -42,17 +42,23 @@ const CFStringRef kCTFontSizeAttribute = @"kCTFontSizeAttribute"; const CFStringRef kCTFontMatrixAttribute = @"kCTFontMatrixAttribute"; const CFStringRef kCTFontCascadeListAttribute = @"kCTFontCascadeListAttribute"; -const CFStringRef kCTFontCharacterSetAttribute = @"kCTFontCharacterSetAttribute"; +const CFStringRef kCTFontCharacterSetAttribute = + @"kCTFontCharacterSetAttribute"; const CFStringRef kCTFontLanguagesAttribute = @"kCTFontLanguagesAttribute"; -const CFStringRef kCTFontBaselineAdjustAttribute = @"kCTFontBaselineAdjustAttribute"; -const CFStringRef kCTFontMacintoshEncodingsAttribute = @"kCTFontMacintoshEncodingsAttribute"; +const CFStringRef kCTFontBaselineAdjustAttribute = + @"kCTFontBaselineAdjustAttribute"; +const CFStringRef kCTFontMacintoshEncodingsAttribute = + @"kCTFontMacintoshEncodingsAttribute"; const CFStringRef kCTFontFeaturesAttribute = @"kCTFontFeaturesAttribute"; -const CFStringRef kCTFontFeatureSettingsAttribute = @"kCTFontFeatureSettingsAttribute"; -const CFStringRef kCTFontFixedAdvanceAttribute = @"kCTFontFixedAdvanceAttribute"; +const CFStringRef kCTFontFeatureSettingsAttribute = + @"kCTFontFeatureSettingsAttribute"; +const CFStringRef kCTFontFixedAdvanceAttribute = + @"kCTFontFixedAdvanceAttribute"; const CFStringRef kCTFontOrientationAttribute = @"kCTFontOrientationAttribute"; const CFStringRef kCTFontEnabledAttribute = @"kCTFontEnabledAttribute"; const CFStringRef kCTFontFormatAttribute = @"kCTFontFormatAttribute"; -const CFStringRef kCTFontRegistrationScopeAttribute = @"kCTFontRegistrationScopeAttribute"; +const CFStringRef kCTFontRegistrationScopeAttribute = + @"kCTFontRegistrationScopeAttribute"; const CFStringRef kCTFontPriorityAttribute = @"kCTFontPriorityAttribute"; @@ -65,11 +71,13 @@ CTFontDescriptorRef CTFontDescriptorCreateWithNameAndSize( return [[OPFontDescriptor fontDescriptorWithName: name size: size] retain]; } -CTFontDescriptorRef CTFontDescriptorCreateWithAttributes(CFDictionaryRef attributes) +CTFontDescriptorRef CTFontDescriptorCreateWithAttributes( + CFDictionaryRef attributes) { - return [[OPFontDescriptor fontDescriptorWithFontAttributes: attributes] retain]; + return [[OPFontDescriptor fontDescriptorWithFontAttributes: attributes] + retain]; } - + CTFontDescriptorRef CTFontDescriptorCreateCopyWithAttributes( CTFontDescriptorRef original, CFDictionaryRef attributes) @@ -82,17 +90,18 @@ CTFontDescriptorRef CTFontDescriptorCreateCopyWithVariation( CFNumberRef variationIdentifier, CGFloat variationValue) { - NSMutableDictionary *newVariation = [[original objectForKey: kCTFontVariationAttribute] mutableCopy]; + NSMutableDictionary *newVariation = [[original objectForKey: + kCTFontVariationAttribute] mutableCopy]; if (nil == newVariation) - { - newVariation = [[NSMutableDictionary alloc] init]; - } + { + newVariation = [[NSMutableDictionary alloc] init]; + } [newVariation setObject: [NSNumber numberWithDouble: variationValue] forKey: variationIdentifier]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: - newVariation, kCTFontVariationAttribute, - nil]; + newVariation, kCTFontVariationAttribute, + nil]; [newVariation release]; @@ -104,20 +113,21 @@ CTFontDescriptorRef CTFontDescriptorCreateCopyWithFeature( CFNumberRef featureTypeIdentifier, CFNumberRef featureSelectorIdentifier) { - NSMutableArray *newFeatureSettings = [[original objectForKey: kCTFontFeatureSettingsAttribute] mutableCopy]; + NSMutableArray *newFeatureSettings = [[original objectForKey: + kCTFontFeatureSettingsAttribute] mutableCopy]; if (nil == newFeatureSettings) - { - newFeatureSettings = [[NSMutableArray alloc] init]; - } + { + newFeatureSettings = [[NSMutableArray alloc] init]; + } [newFeatureSettings addObject: - [NSDictionary dictionaryWithObjectsAndKeys: - featureTypeIdentifier, kCTFontFeatureTypeIdentifierKey, - featureSelectorIdentifier, kCTFontFeatureSelectorIdentifierKey, - nil]]; + [NSDictionary dictionaryWithObjectsAndKeys: + featureTypeIdentifier, kCTFontFeatureTypeIdentifierKey, + featureSelectorIdentifier, kCTFontFeatureSelectorIdentifierKey, + nil]]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: - newFeatureSettings, kCTFontFeatureSettingsAttribute, - nil]; + newFeatureSettings, kCTFontFeatureSettingsAttribute, + nil]; [newFeatureSettings release]; @@ -128,14 +138,16 @@ CFArrayRef CTFontDescriptorCreateMatchingFontDescriptors( CTFontDescriptorRef descriptor, CFSetRef mandatoryAttributes) { - return [[descriptor matchingFontDescriptorsWithMandatoryKeys: mandatoryAttributes] retain]; + return [[descriptor matchingFontDescriptorsWithMandatoryKeys: + mandatoryAttributes] retain]; } CTFontDescriptorRef CTFontDescriptorCreateMatchingFontDescriptor( CTFontDescriptorRef descriptor, CFSetRef mandatoryAttributes) { - return [[descriptor matchingFontDescriptorWithMandatoryKeys: mandatoryAttributes] retain]; + return [[descriptor matchingFontDescriptorWithMandatoryKeys: + mandatoryAttributes] retain]; } CFDictionaryRef CTFontDescriptorCopyAttributes(CTFontDescriptorRef descriptor) @@ -157,18 +169,19 @@ CFTypeRef CTFontDescriptorCopyLocalizedAttribute( { NSArray *preferredLanguages = [NSLocale preferredLanguages]; if ([preferredLanguages count] > 0) - { - NSString *preferredLanguage = [preferredLanguages objectAtIndex: 0]; - id localizedValue = [descriptor localizedObjectForKey: attribute language: preferredLanguage]; - if (localizedValue) { - if (language) - { - *language = preferredLanguage; - } - return [localizedValue retain]; + NSString *preferredLanguage = [preferredLanguages objectAtIndex: 0]; + id localizedValue = [descriptor localizedObjectForKey: attribute language: + preferredLanguage]; + if (localizedValue) + { + if (language) + { + *language = preferredLanguage; + } + return [localizedValue retain]; + } } - } return CTFontDescriptorCopyAttribute(descriptor, attribute); } diff --git a/Source/OpalText/CTFontTraits.m b/Source/OpalText/CTFontTraits.m index 67a24dc..996a4f1 100644 --- a/Source/OpalText/CTFontTraits.m +++ b/Source/OpalText/CTFontTraits.m @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalText/CTFrame-private.h b/Source/OpalText/CTFrame-private.h index 072ee4b..c1d75ca 100644 --- a/Source/OpalText/CTFrame-private.h +++ b/Source/OpalText/CTFrame-private.h @@ -1,22 +1,22 @@ /** CTFrame - + C Interface to text layout library - + Copyright (C) 2011 Free Software Foundation, Inc. - + Author: Eric Wasylishen Date: Mar 2011 - + 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 @@ -30,10 +30,10 @@ */ @interface CTFrame : NSObject { - CGPathRef _path; - NSMutableArray *_lines; - NSRange _stringRange; - NSRange _visibleStringRange; + CGPathRef _path; + NSMutableArray *_lines; + NSRange _stringRange; + NSRange _visibleStringRange; NSDictionary *_attributes; } diff --git a/Source/OpalText/CTFrame.m b/Source/OpalText/CTFrame.m index 8487ee4..e31e7b6 100644 --- a/Source/OpalText/CTFrame.m +++ b/Source/OpalText/CTFrame.m @@ -11,12 +11,12 @@ 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 @@ -27,7 +27,8 @@ /* Constants */ -const CFStringRef kCTFrameProgressionAttributeName = @"kCTFrameProgressionAttributeName"; +const CFStringRef kCTFrameProgressionAttributeName = + @"kCTFrameProgressionAttributeName"; /* Classes */ @@ -38,12 +39,12 @@ - (id) initWithPath: (CGPathRef)aPath attributes: (NSDictionary*)attribs { if ((self = [super init])) - { - _path = [aPath retain]; - _lines = [[NSMutableArray alloc] init]; - _attributes = [attribs copy]; - _stringRange = aRange; - } + { + _path = [aPath retain]; + _lines = [[NSMutableArray alloc] init]; + _attributes = [attribs copy]; + _stringRange = aRange; + } return self; } @@ -72,7 +73,7 @@ - (NSArray*)lines - (NSRange)stringRange { - return _stringRange; + return _stringRange; } - (NSRange)visibleStringRange @@ -95,11 +96,11 @@ - (void)drawOnContext: (CGContextRef)ctx // FIXME: see CTFrameProgression docs comment about rotating 90 degrees NSUInteger linesCount = [_lines count]; for (NSUInteger i=0; iCTLine - + C Interface to text layout library - + Copyright (C) 2011 Free Software Foundation, Inc. - + Author: Eric Wasylishen Date: Mar 2011 - + 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 diff --git a/Source/OpalText/CTLine.m b/Source/OpalText/CTLine.m index 30b89f5..e7868c3 100644 --- a/Source/OpalText/CTLine.m +++ b/Source/OpalText/CTLine.m @@ -11,12 +11,12 @@ 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 @@ -31,9 +31,9 @@ @implementation CTLine - (id)initWithRuns: (NSArray*)runs { if ((self = [super init])) - { - _runs = [runs retain]; - } + { + _runs = [runs retain]; + } return self; } @@ -46,10 +46,10 @@ - (void)drawOnContext: (CGContextRef)ctx { const NSUInteger runsCount = [_runs count]; for (NSUInteger i=0; iCTRun - + C Interface to text layout library - + Copyright (C) 2011 Free Software Foundation, Inc. - + Author: Eric Wasylishen Date: Mar 2011 - + 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 diff --git a/Source/OpalText/CTRun.m b/Source/OpalText/CTRun.m index 2f30170..e6071f2 100644 --- a/Source/OpalText/CTRun.m +++ b/Source/OpalText/CTRun.m @@ -11,12 +11,12 @@ 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 @@ -73,14 +73,14 @@ - (CFRange)stringRange return _stringRange; } - (double)typographicBoundsForRange: (CFRange)range - ascent: (CGFloat*)ascent - descent: (CGFloat*)descent - leading: (CGFloat*)leading + ascent: (CGFloat*)ascent + descent: (CGFloat*)descent + leading: (CGFloat*)leading { return 0; } - (CGRect)imageBoundsForRange: (CFRange)range - withContext: (CGContextRef)context + withContext: (CGContextRef)context { return CGRectMake(0,0,0,0); } @@ -93,24 +93,25 @@ - (CGAffineTransform)matrix - (void)drawRange: (CFRange)range onContext: (CGContextRef)ctx { if (range.length == 0) - { - range.length = _count; - } + { + range.length = _count; + } if (range.location > _count || (range.location + range.length) > _count) - { - NSLog(@"CTRunDraw range out of bounds"); - return; - } + { + NSLog(@"CTRunDraw range out of bounds"); + return; + } - CGContextShowGlyphsAtPositions(ctx, _glyphs + range.location, _positions, range.length); + CGContextShowGlyphsAtPositions(ctx, _glyphs + range.location, _positions, + range.length); } @end /* Functions */ - + CFIndex CTRunGetGlyphCount(CTRunRef run) { return [run glyphCount]; @@ -132,9 +133,9 @@ CTRunStatus CTRunGetStatus(CTRunRef run) } void CTRunGetGlyphs( - CTRunRef run, - CFRange range, - CGGlyph buffer[]) + CTRunRef run, + CFRange range, + CGGlyph buffer[]) { memcpy(buffer, [run glyphs] + range.location, sizeof(CGGlyph) * range.length); } @@ -145,11 +146,12 @@ void CTRunGetGlyphs( } void CTRunGetPositions( - CTRunRef run, - CFRange range, - CGPoint buffer[]) + CTRunRef run, + CFRange range, + CGPoint buffer[]) { - memcpy(buffer, [run positions] + range.location, sizeof(CGPoint) * range.length); + memcpy(buffer, [run positions] + range.location, + sizeof(CGPoint) * range.length); } const CGSize* CTRunGetAdvancesPtr(CTRunRef run) @@ -158,11 +160,11 @@ void CTRunGetPositions( } void CTRunGetAdvances( - CTRunRef run, - CFRange range, - CGSize buffer[]) + CTRunRef run, + CFRange range, + CGSize buffer[]) { - memcpy(buffer, [run advances] + range.location, sizeof(CGSize) * range.length); + memcpy(buffer, [run advances] + range.location, sizeof(CGSize) * range.length); } const CFIndex *CTRunGetStringIndicesPtr(CTRunRef run) @@ -171,11 +173,12 @@ void CTRunGetAdvances( } void CTRunGetStringIndices( - CTRunRef run, - CFRange range, - CFIndex buffer[]) + CTRunRef run, + CFRange range, + CFIndex buffer[]) { - memcpy(buffer, [run stringIndices] + range.location, sizeof(CFIndex) * range.length); + memcpy(buffer, [run stringIndices] + range.location, + sizeof(CFIndex) * range.length); } CFRange CTRunGetStringRange(CTRunRef run) @@ -184,25 +187,25 @@ CFRange CTRunGetStringRange(CTRunRef run) } double CTRunGetTypographicBounds( - CTRunRef run, - CFRange range, - CGFloat *ascent, - CGFloat *descent, - CGFloat *leading) + CTRunRef run, + CFRange range, + CGFloat *ascent, + CGFloat *descent, + CGFloat *leading) { return [run typographicBoundsForRange: range - ascent: ascent - descent: descent - leading: leading]; + ascent: ascent + descent: descent + leading: leading]; } CGRect CTRunGetImageBounds( - CTRunRef run, - CGContextRef context, - CFRange range) + CTRunRef run, + CGContextRef context, + CFRange range) { return [run imageBoundsForRange: range - withContext: context]; + withContext: context]; } CGAffineTransform CTRunGetTextMatrix(CTRunRef run) @@ -211,9 +214,9 @@ CGAffineTransform CTRunGetTextMatrix(CTRunRef run) } void CTRunDraw( - CTRunRef run, - CGContextRef ctx, - CFRange range) + CTRunRef run, + CGContextRef ctx, + CFRange range) { [run drawRange: range onContext: ctx]; } diff --git a/Source/OpalText/CTStringAttributes.m b/Source/OpalText/CTStringAttributes.m index d6301b5..498f2df 100644 --- a/Source/OpalText/CTStringAttributes.m +++ b/Source/OpalText/CTStringAttributes.m @@ -11,12 +11,12 @@ 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 @@ -27,17 +27,24 @@ /* Constants */ const CFStringRef kCTFontAttributeName = @"kCTFontAttributeName"; -const CFStringRef kCTForegroundColorFromContextAttributeName = @"kCTForegroundColorFromContextAttributeName"; +const CFStringRef kCTForegroundColorFromContextAttributeName = + @"kCTForegroundColorFromContextAttributeName"; const CFStringRef kCTKernAttributeName = @"kCTKernAttributeName"; const CFStringRef kCTLigatureAttributeName = @"kCTLigatureAttributeName"; -const CFStringRef kCTForegroundColorAttributeName = @"kCTForegroundColorAttributeName"; -const CFStringRef kCTParagraphStyleAttributeName = @"kCTParagraphStyleAttributeName"; +const CFStringRef kCTForegroundColorAttributeName = + @"kCTForegroundColorAttributeName"; +const CFStringRef kCTParagraphStyleAttributeName = + @"kCTParagraphStyleAttributeName"; const CFStringRef kCTStrokeWidthAttributeName = @"kCTStrokeWidthAttributeName"; const CFStringRef kCTStrokeColorAttributeName = @"kCTStrokeColorAttributeName"; -const CFStringRef kCTUnderlineStyleAttributeName = @"kCTUnderlineStyleAttributeName"; +const CFStringRef kCTUnderlineStyleAttributeName = + @"kCTUnderlineStyleAttributeName"; const CFStringRef kCTSuperscriptAttributeName = @"kCTSuperscriptAttributeName"; -const CFStringRef kCTUnderlineColorAttributeName = @"kCTUnderlineColorAttributeName"; -const CFStringRef kCTVerticalFormsAttributeName = @"kCTVerticalFormsAttributeName"; +const CFStringRef kCTUnderlineColorAttributeName = + @"kCTUnderlineColorAttributeName"; +const CFStringRef kCTVerticalFormsAttributeName = + @"kCTVerticalFormsAttributeName"; const CFStringRef kCTGlyphInfoAttributeName = @"kCTGlyphInfoAttributeName"; -const CFStringRef kCTCharacterShapeAttributeName = @"kCTCharacterShapeAttributeName"; +const CFStringRef kCTCharacterShapeAttributeName = + @"kCTCharacterShapeAttributeName"; diff --git a/Source/OpalText/CTTextTab.m b/Source/OpalText/CTTextTab.m index a62781a..a500502 100644 --- a/Source/OpalText/CTTextTab.m +++ b/Source/OpalText/CTTextTab.m @@ -11,12 +11,12 @@ 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 @@ -26,7 +26,8 @@ /* Constants */ -const CFStringRef kCTTabColumnTerminatorsAttributeName = @"kCTTabColumnTerminatorsAttributeName"; +const CFStringRef kCTTabColumnTerminatorsAttributeName = + @"kCTTabColumnTerminatorsAttributeName"; /* Classes */ @@ -56,9 +57,9 @@ - (id)initWithAlignment: (CTTextAlignment)alignment { self = [super init]; if (nil == self) - { - return nil; - } + { + return nil; + } return self; } @@ -81,9 +82,9 @@ - (NSDictionary*)options /* Functions */ CTTextTabRef CTTextTabCreate( - CTTextAlignment alignment, - double location, - CFDictionaryRef options) + CTTextAlignment alignment, + double location, + CFDictionaryRef options) { return [[CTTextTab alloc] initWithAlignment: alignment location: location diff --git a/Source/OpalText/CTTypesetter.m b/Source/OpalText/CTTypesetter.m index eb9d047..548edda 100644 --- a/Source/OpalText/CTTypesetter.m +++ b/Source/OpalText/CTTypesetter.m @@ -11,12 +11,12 @@ 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 @@ -30,8 +30,10 @@ /* Constants */ -const CFStringRef kCTTypesetterOptionDisableBidiProcessing = @"kCTTypesetterOptionDisableBidiProcessing"; -const CFStringRef kCTTypesetterOptionForcedEmbeddingLevel = @"kCTTypesetterOptionForcedEmbeddingLevel"; +const CFStringRef kCTTypesetterOptionDisableBidiProcessing = + @"kCTTypesetterOptionDisableBidiProcessing"; +const CFStringRef kCTTypesetterOptionForcedEmbeddingLevel = + @"kCTTypesetterOptionForcedEmbeddingLevel"; /* Classes */ @@ -61,10 +63,10 @@ - (id)initWithAttributedString: (NSAttributedString*)string options: (NSDictionary*)options { if ((self = [super init])) - { - _as = [string retain]; - _options = [options retain]; - } + { + _as = [string retain]; + _options = [options retain]; + } return self; } @@ -81,11 +83,11 @@ - (CTLineRef)createLineWithRange: (CFRange)range // - divide the attributed string into runs with the same attributes. // - run the bidirectional algorithm if needed // - call the shaper on each run - + NSArray *runs = [NSMutableArray array]; - + CTLineRef line = [[CTLine alloc] initWithRuns: runs]; - + return line; } - (CFIndex)suggestClusterBreakAtIndex: (CFIndex)start @@ -103,15 +105,16 @@ - (CFIndex)suggestLineBreakAtIndex: (CFIndex)start /* Functions */ -CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef string) +CTTypesetterRef CTTypesetterCreateWithAttributedString(CFAttributedStringRef + string) { return [[CTTypesetter alloc] initWithAttributedString: string options: nil]; } CTTypesetterRef CTTypesetterCreateWithAttributedStringAndOptions( - CFAttributedStringRef string, - CFDictionaryRef opts) + CFAttributedStringRef string, + CFDictionaryRef opts) { return [[CTTypesetter alloc] initWithAttributedString: string options: opts]; @@ -123,17 +126,17 @@ CTLineRef CTTypesetterCreateLine(CTTypesetterRef ts, CFRange range) } CFIndex CTTypesetterSuggestClusterBreak( - CTTypesetterRef ts, - CFIndex start, - double width) + CTTypesetterRef ts, + CFIndex start, + double width) { return [ts suggestClusterBreakAtIndex: start width: width]; } CFIndex CTTypesetterSuggestLineBreak( - CTTypesetterRef ts, - CFIndex start, - double width) + CTTypesetterRef ts, + CFIndex start, + double width) { return [ts suggestLineBreakAtIndex: start width: width]; } diff --git a/Source/OpalText/Fontconfig/OPFontconfigFont.m b/Source/OpalText/Fontconfig/OPFontconfigFont.m index c562994..c9df26d 100644 --- a/Source/OpalText/Fontconfig/OPFontconfigFont.m +++ b/Source/OpalText/Fontconfig/OPFontconfigFont.m @@ -7,7 +7,7 @@ Author: Ovidiu Predescu Date: February 1997 A completely rewritten version of the original source by Scott Christley. - + This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or @@ -22,10 +22,10 @@ You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. - If not, see or write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ +*/ #import #import @@ -155,7 +155,7 @@ - (NSStringEncoding) mostCompatibleStringEncoding // // CTFont private // -+ (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor ++ (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor options: (CTFontOptions)options { } @@ -228,7 +228,7 @@ - (NSString*) nameForGlyph: (CGGlyph)graphicsGlyph } + (CTFontRef) fontWithData: (NSData*)fontData size: (CGFloat)size - matrix: (const CGFloat*)fontMatrix + matrix: (const CGFloat*)fontMatrix additionalDescriptor: (OPFontDescriptor*)descriptor { } diff --git a/Source/OpalText/Fontconfig/OPFontconfigFontCollection.m b/Source/OpalText/Fontconfig/OPFontconfigFontCollection.m index a064456..216cb3e 100644 --- a/Source/OpalText/Fontconfig/OPFontconfigFontCollection.m +++ b/Source/OpalText/Fontconfig/OPFontconfigFontCollection.m @@ -7,12 +7,14 @@ @interface CTFontCollection : NSObject } - (id)initWithAvailableFontsWithOptions: (NSDictionary*)opts; -- (id)initWithFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts; +- (id)initWithFontDescriptors: (NSArray*)descriptors options: + (NSDictionary*)opts; - (CTFontCollection*)collectionByAddingFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts; - (NSArray*)fontDescriptors; -- (NSArray*)fontDescriptorsSortedWithCallback: (CTFontCollectionSortDescriptorsCallback)cb +- (NSArray*)fontDescriptorsSortedWithCallback: + (CTFontCollectionSortDescriptorsCallback)cb info: (void*)info; @end @@ -26,21 +28,21 @@ - (id)initWithAvailableFonts // Request all of the attributes we are interested in FcObjectSet *os = FcObjectSetBuild( - FC_FILE, - FC_FAMILY, - FC_FULLNAME, - FC_STYLE, - FC_SLANT, - FC_WEIGHT, - FC_WIDTH, - FC_SPACING, - FC_SIZE, - FC_MATRIX, - FC_CHARSET, - FC_LANG, - FC_VERTICAL_LAYOUT, - FC_OUTLINE, - NULL); + FC_FILE, + FC_FAMILY, + FC_FULLNAME, + FC_STYLE, + FC_SLANT, + FC_WEIGHT, + FC_WIDTH, + FC_SPACING, + FC_SIZE, + FC_MATRIX, + FC_CHARSET, + FC_LANG, + FC_VERTICAL_LAYOUT, + FC_OUTLINE, + NULL); FcFontSet *fs = FcFontList(NULL, pat, os); FcPatternDestroy(pat); @@ -49,38 +51,42 @@ - (id)initWithAvailableFonts } -- (id)initWithFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts +- (id)initWithFontDescriptors: (NSArray*)descriptors options: + (NSDictionary*)opts { self = [super init]; if (nil == self) - { - return nil; - } + { + return nil; + } if ([[opts objectForKey: kCTFontCollectionRemoveDuplicatesOption] boolValue]) - { - // FIXME: relies on CTFontDescriptors behaving properly in sets (-hash/-isEqual:) - _descriptors = [[[NSSet setWithArray: descriptors] allObjects] retain]; - } + { + // FIXME: relies on CTFontDescriptors behaving properly in sets (-hash/-isEqual:) + _descriptors = [[[NSSet setWithArray: descriptors] allObjects] retain]; + } else - { - _descriptors = [descriptors copy]; - } + { + _descriptors = [descriptors copy]; + } return self; } - (CTFontCollection*)collectionByAddingFontDescriptors: (NSArray*)descriptors options: (NSDictionary*)opts { - NSArray *newDescriptors = [_descriptors arrayByAddingObjectsFromArray: descriptors]; - CTFontCollection *collection = [[CTFontCollection alloc] initWithFontDescriptors: newDescriptors - options: opts]; + NSArray *newDescriptors = [_descriptors arrayByAddingObjectsFromArray: + descriptors]; + CTFontCollection *collection = [[CTFontCollection alloc] + initWithFontDescriptors: newDescriptors + options: opts]; return [collection autorelease]; } - (NSArray*)fontDescriptors { return _descriptors; } -- (NSArray*)fontDescriptorsSortedWithCallback: (CTFontCollectionSortDescriptorsCallback)cb +- (NSArray*)fontDescriptorsSortedWithCallback: + (CTFontCollectionSortDescriptorsCallback)cb info: (void*)info { return [_descriptors sortedArrayUsingFunction: cb context: info]; diff --git a/Source/OpalText/Fontconfig/OPFontconfigFontDescriptor.m b/Source/OpalText/Fontconfig/OPFontconfigFontDescriptor.m index ebb654d..75cd273 100644 --- a/Source/OpalText/Fontconfig/OPFontconfigFontDescriptor.m +++ b/Source/OpalText/Fontconfig/OPFontconfigFontDescriptor.m @@ -50,13 +50,13 @@ - (void)addURL: (NSURL*)url { NSString *path = [url path]; if ([url isFileURL] && path != nil) - { - FcPatternAddString(_pat, FC_FILE, (const FcChar8 *)[path UTF8String]); - } + { + FcPatternAddString(_pat, FC_FILE, (const FcChar8 *)[path UTF8String]); + } else - { - NSLog(@"Warning, URL %@ is invalid", url); - } + { + NSLog(@"Warning, URL %@ is invalid", url); + } } - (void)addName: (NSString*)name @@ -98,138 +98,143 @@ - (void)addStyleName: (NSString*)style - (void)addTraits: (NSDictionary*)traits { if ([traits objectForKey: kCTFontSymbolicTrait]) - { - CTFontSymbolicTraits symTraits = [[traits objectForKey: kCTFontSymbolicTrait] intValue]; - - if (symTraits & kCTFontItalicTrait) - { - // NOTE: May be overridden by kCTFontSlantTrait - FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ITALIC); - } - if (symTraits & kCTFontBoldTrait) - { - // NOTE: May be overridden by kCTFontWeightTrait - FcPatternAddInteger(_pat, FC_WEIGHT, FC_WEIGHT_BOLD); - } - if (symTraits & kCTFontExpandedTrait) - { - // NOTE: May be overridden by kCTFontWidthTrait - FcPatternAddInteger(_pat, FC_WIDTH, FC_WIDTH_EXPANDED); - } - if (symTraits & kCTFontCondensedTrait) - { - // NOTE: May be overridden by kCTFontWidthTrait - FcPatternAddInteger(_pat, FC_WIDTH, FC_WIDTH_CONDENSED); - } - if (symTraits & kCTFontMonoSpaceTrait) { - // If you run "fc-match :spacing=100", you get "DejaVu Sans" even though you would - // expect to get "DejaVu Sans Mono". So, we also add "monospace" as a weak family - // name to fix the problem. - FcPatternAddInteger(_pat, FC_SPACING, FC_MONO); + CTFontSymbolicTraits symTraits = [[traits objectForKey: kCTFontSymbolicTrait] + intValue]; - FcValue value; - value.type = FcTypeString; - value.u.s = (FcChar8*)"monospace"; - FcPatternAddWeak(_pat, FC_FAMILY, value, FcTrue); - } - if (symTraits & kCTFontVerticalTrait) - { - // FIXME: What is this supposed to mean? - } - if (symTraits & kCTFontUIOptimizedTrait) - { - // NOTE: Fontconfig can't express this - } + if (symTraits & kCTFontItalicTrait) + { + // NOTE: May be overridden by kCTFontSlantTrait + FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ITALIC); + } + if (symTraits & kCTFontBoldTrait) + { + // NOTE: May be overridden by kCTFontWeightTrait + FcPatternAddInteger(_pat, FC_WEIGHT, FC_WEIGHT_BOLD); + } + if (symTraits & kCTFontExpandedTrait) + { + // NOTE: May be overridden by kCTFontWidthTrait + FcPatternAddInteger(_pat, FC_WIDTH, FC_WIDTH_EXPANDED); + } + if (symTraits & kCTFontCondensedTrait) + { + // NOTE: May be overridden by kCTFontWidthTrait + FcPatternAddInteger(_pat, FC_WIDTH, FC_WIDTH_CONDENSED); + } + if (symTraits & kCTFontMonoSpaceTrait) + { + // If you run "fc-match :spacing=100", you get "DejaVu Sans" even though you would + // expect to get "DejaVu Sans Mono". So, we also add "monospace" as a weak family + // name to fix the problem. + FcPatternAddInteger(_pat, FC_SPACING, FC_MONO); + + FcValue value; + value.type = FcTypeString; + value.u.s = (FcChar8*)"monospace"; + FcPatternAddWeak(_pat, FC_FAMILY, value, FcTrue); + } + if (symTraits & kCTFontVerticalTrait) + { + // FIXME: What is this supposed to mean? + } + if (symTraits & kCTFontUIOptimizedTrait) + { + // NOTE: Fontconfig can't express this + } - CTFontStylisticClass class = symTraits & kCTFontClassMaskTrait; - char *addWeakFamilyName = NULL; - switch (class) - { - default: - case kCTFontUnknownClass: - case kCTFontOrnamentalsClass: - case kCTFontScriptsClass: - case kCTFontSymbolicClass: - // FIXME: Is there some way to convey these to Fontconfig? - break; - case kCTFontOldStyleSerifsClass: - case kCTFontTransitionalSerifsClass: - case kCTFontModernSerifsClass: - case kCTFontClarendonSerifsClass: - case kCTFontSlabSerifsClass: - case kCTFontFreeformSerifsClass: - addWeakFamilyName = "serif"; - break; - case kCTFontSansSerifClass: - addWeakFamilyName = "sans"; - break; - } - if (addWeakFamilyName) - { - FcValue value; - value.type = FcTypeString; - value.u.s = (const FcChar8 *)addWeakFamilyName; - FcPatternAddWeak(_pat, FC_FAMILY, value, FcTrue); + CTFontStylisticClass class = symTraits & kCTFontClassMaskTrait; + char *addWeakFamilyName = NULL; + switch (class) + { + default: + case kCTFontUnknownClass: + case kCTFontOrnamentalsClass: + case kCTFontScriptsClass: + case kCTFontSymbolicClass: + // FIXME: Is there some way to convey these to Fontconfig? + break; + case kCTFontOldStyleSerifsClass: + case kCTFontTransitionalSerifsClass: + case kCTFontModernSerifsClass: + case kCTFontClarendonSerifsClass: + case kCTFontSlabSerifsClass: + case kCTFontFreeformSerifsClass: + addWeakFamilyName = "serif"; + break; + case kCTFontSansSerifClass: + addWeakFamilyName = "sans"; + break; + } + if (addWeakFamilyName) + { + FcValue value; + value.type = FcTypeString; + value.u.s = (const FcChar8 *)addWeakFamilyName; + FcPatternAddWeak(_pat, FC_FAMILY, value, FcTrue); + } } - } if ([traits objectForKey: kCTFontWeightTrait]) - { - /** - * Scale: -1 is thinnest, 0 is normal, 1 is heaviest - */ - double weight = [[traits objectForKey: kCTFontWeightTrait] doubleValue]; - weight = MAX(-1, MIN(1, weight)); - int fcWeight; - if (weight <= 0) - { - fcWeight = FC_WEIGHT_THIN + ((weight + 1.0) * (FC_WEIGHT_NORMAL - FC_WEIGHT_THIN)); - } - else { - fcWeight = FC_WEIGHT_NORMAL + (weight * (FC_WEIGHT_ULTRABLACK - FC_WEIGHT_NORMAL)); + /** + * Scale: -1 is thinnest, 0 is normal, 1 is heaviest + */ + double weight = [[traits objectForKey: kCTFontWeightTrait] doubleValue]; + weight = MAX(-1, MIN(1, weight)); + int fcWeight; + if (weight <= 0) + { + fcWeight = FC_WEIGHT_THIN + ((weight + 1.0) * (FC_WEIGHT_NORMAL - + FC_WEIGHT_THIN)); + } + else + { + fcWeight = FC_WEIGHT_NORMAL + (weight * (FC_WEIGHT_ULTRABLACK - + FC_WEIGHT_NORMAL)); + } + FcPatternAddInteger(_pat, FC_WEIGHT, fcWeight); } - FcPatternAddInteger(_pat, FC_WEIGHT, fcWeight); - } if ([traits objectForKey: kCTFontWidthTrait]) - { - /** - * Scale: -1 is most condensed, 0 is normal, 1 is most spread apart - */ - double width = [[traits objectForKey: kCTFontWidthTrait] doubleValue]; - width = MAX(-1, MIN(1, width)); - int fcWidth; - if (width <= 0) - { - fcWidth = FC_WIDTH_ULTRACONDENSED + ((width + 1.0) * (FC_WIDTH_NORMAL - FC_WIDTH_ULTRACONDENSED)); - } - else { - fcWidth = FC_WIDTH_NORMAL + (width * (FC_WIDTH_ULTRAEXPANDED - FC_WIDTH_NORMAL)); + /** + * Scale: -1 is most condensed, 0 is normal, 1 is most spread apart + */ + double width = [[traits objectForKey: kCTFontWidthTrait] doubleValue]; + width = MAX(-1, MIN(1, width)); + int fcWidth; + if (width <= 0) + { + fcWidth = FC_WIDTH_ULTRACONDENSED + ((width + 1.0) * (FC_WIDTH_NORMAL - + FC_WIDTH_ULTRACONDENSED)); + } + else + { + fcWidth = FC_WIDTH_NORMAL + (width * (FC_WIDTH_ULTRAEXPANDED - + FC_WIDTH_NORMAL)); + } + FcPatternAddInteger(_pat, FC_WIDTH, fcWidth); } - FcPatternAddInteger(_pat, FC_WIDTH, fcWidth); - } if ([traits objectForKey: kCTFontSlantTrait]) - { - /** - * Scale: -1 is 30 degree counterclockwise slant, 0 is no slant, 1 - * is 30 degree clockwise slant - */ - double slant = [[traits objectForKey: kCTFontSlantTrait] doubleValue]; - - // NOTE: Fontconfig can't express this as a scale - if (slant > 0) { - FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ITALIC); - } - else - { - FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ROMAN); + /** + * Scale: -1 is 30 degree counterclockwise slant, 0 is no slant, 1 + * is 30 degree clockwise slant + */ + double slant = [[traits objectForKey: kCTFontSlantTrait] doubleValue]; + + // NOTE: Fontconfig can't express this as a scale + if (slant > 0) + { + FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ITALIC); + } + else + { + FcPatternAddInteger(_pat, FC_SLANT, FC_SLANT_ROMAN); + } } - } } - (void)addSize: (NSNumber*)size @@ -245,18 +250,19 @@ - (void)addCharacterSet: (NSCharacterSet*)characterSet FcCharSet *fcSet = FcCharSetCreate(); for (uint32_t plane=0; plane<=16; plane++) - { - if ([characterSet hasMemberInPlane: plane]) { - for (uint32_t codePoint = plane<<16; codePoint <= 0xffff + (plane<<16); codePoint++) - { - if ([characterSet longCharacterIsMember: codePoint]) - { - FcCharSetAddChar(fcSet, codePoint); - } - } + if ([characterSet hasMemberInPlane: plane]) + { + for (uint32_t codePoint = plane<<16; codePoint <= 0xffff + (plane<<16); + codePoint++) + { + if ([characterSet longCharacterIsMember: codePoint]) + { + FcCharSetAddChar(fcSet, codePoint); + } + } + } } - } FcPatternAddCharSet(_pat, FC_CHARSET, fcSet); FcCharSetDestroy(fcSet); @@ -268,9 +274,10 @@ - (void)addLanguages: (NSArray*)languages NSUInteger languagesCount = [languages count]; for (NSUInteger i=0; i= FC_WEIGHT_BOLD) { - symTraits |= kCTFontBoldTrait; - } + if (value >= FC_WEIGHT_BOLD) + { + symTraits |= kCTFontBoldTrait; + } - double weight; - if (value <= FC_WEIGHT_NORMAL) - { - weight = ((value - FC_WEIGHT_THIN) / (double)(FC_WEIGHT_NORMAL - FC_WEIGHT_THIN)) - 1.0; - } - else - { - weight = (value - FC_WEIGHT_NORMAL) / (double)(FC_WEIGHT_ULTRABLACK - FC_WEIGHT_NORMAL); - } + double weight; + if (value <= FC_WEIGHT_NORMAL) + { + weight = ((value - FC_WEIGHT_THIN) / (double)(FC_WEIGHT_NORMAL - + FC_WEIGHT_THIN)) - 1.0; + } + else + { + weight = (value - FC_WEIGHT_NORMAL) / (double)(FC_WEIGHT_ULTRABLACK - + FC_WEIGHT_NORMAL); + } - [traits setObject: [NSNumber numberWithDouble: weight] - forKey: kCTFontWeightTrait]; - } - if (FcResultMatch == FcPatternGetInteger(pat, FC_WIDTH, 0, &value)) - { - if (value >= FC_WIDTH_EXPANDED) - { - symTraits |= kCTFontExpandedTrait; + [traits setObject: [NSNumber numberWithDouble: weight] + forKey: kCTFontWeightTrait]; } - if (value <= FC_WIDTH_CONDENSED) + if (FcResultMatch == FcPatternGetInteger(pat, FC_WIDTH, 0, &value)) { - symTraits |= kCTFontCondensedTrait; - } + if (value >= FC_WIDTH_EXPANDED) + { + symTraits |= kCTFontExpandedTrait; + } + if (value <= FC_WIDTH_CONDENSED) + { + symTraits |= kCTFontCondensedTrait; + } - double width; - if (value <= FC_WIDTH_NORMAL) - { - width = ((value - FC_WIDTH_ULTRACONDENSED) / (double)(FC_WIDTH_NORMAL - FC_WIDTH_ULTRACONDENSED)) - 1.0; - } - else - { - width = (value - FC_WIDTH_NORMAL) / (double)(FC_WIDTH_ULTRAEXPANDED - FC_WIDTH_NORMAL); - } + double width; + if (value <= FC_WIDTH_NORMAL) + { + width = ((value - FC_WIDTH_ULTRACONDENSED) / (double)(FC_WIDTH_NORMAL - + FC_WIDTH_ULTRACONDENSED)) - 1.0; + } + else + { + width = (value - FC_WIDTH_NORMAL) / (double)(FC_WIDTH_ULTRAEXPANDED - + FC_WIDTH_NORMAL); + } - [traits setObject: [NSNumber numberWithDouble: width] - forKey: kCTFontWidthTrait]; - } + [traits setObject: [NSNumber numberWithDouble: width] + forKey: kCTFontWidthTrait]; + } if (FcResultMatch == FcPatternGetInteger(pat, FC_SPACING, 0, &value)) - { - if (value == FC_MONO) { - symTraits |= kCTFontMonoSpaceTrait; + if (value == FC_MONO) + { + symTraits |= kCTFontMonoSpaceTrait; + } } - } if (symTraits != 0) - { - [traits setObject: [NSNumber numberWithUnsignedInt: symTraits] - forKey: kCTFontSymbolicTrait]; - } + { + [traits setObject: [NSNumber numberWithUnsignedInt: symTraits] + forKey: kCTFontSymbolicTrait]; + } return traits; } @@ -490,17 +505,17 @@ - (NSArray*)readLanguagesFromPattern: (FcPattern*)pat FcLangSet *fcLangSet; if (FcResultMatch == FcPatternGetLangSet(pat, FC_LANG, 0, &fcLangSet)) - { - // FIXME: Not totally clear wheter we have to destroy this - FcStrSet *stringSet = FcLangSetGetLangs(fcLangSet); - FcStrList *setIterator = FcStrListCreate(stringSet); - FcChar8 *str; - while (NULL != (str = FcStrListNext(setIterator))) { - [langs addObject: [NSString stringWithUTF8String: (const char *)str]]; + // FIXME: Not totally clear wheter we have to destroy this + FcStrSet *stringSet = FcLangSetGetLangs(fcLangSet); + FcStrList *setIterator = FcStrListCreate(stringSet); + FcChar8 *str; + while (NULL != (str = FcStrListNext(setIterator))) + { + [langs addObject: [NSString stringWithUTF8String: (const char *)str]]; + } + FcStrListDone(setIterator); } - FcStrListDone(setIterator); - } return langs; } @@ -509,16 +524,16 @@ - (NSNumber*)readOrientationFromPattern: (FcPattern*)pat { int value; if (FcResultMatch == FcPatternGetBool(pat, FC_VERTICAL_LAYOUT, 0, &value)) - { - if (value == FcTrue) - { - return [NSNumber numberWithInt: kCTFontVerticalOrientation]; - } - else { - return [NSNumber numberWithInt: kCTFontHorizontalOrientation]; + if (value == FcTrue) + { + return [NSNumber numberWithInt: kCTFontVerticalOrientation]; + } + else + { + return [NSNumber numberWithInt: kCTFontHorizontalOrientation]; + } } - } return nil; } @@ -526,12 +541,12 @@ - (NSNumber*)readFormatFromPattern: (FcPattern*)pat { int value; if (FcResultMatch == FcPatternGetBool(pat, FC_OUTLINE, 0, &value)) - { - if (value == FcFalse) { - return [NSNumber numberWithInt: kCTFontFormatBitmap]; + if (value == FcFalse) + { + return [NSNumber numberWithInt: kCTFontFormatBitmap]; + } } - } return nil; } @@ -540,23 +555,25 @@ - (NSNumber*)readFormatFromPattern: (FcPattern*)pat //------------- // Private -- (void)handleKey: (NSString*)key selector: (SEL)selector valueClass: (Class)valueClass +- (void)handleKey: (NSString*)key selector: (SEL)selector valueClass: + (Class)valueClass { id value = [[self fontAttributes] objectForKey: key]; if (value) - { - if ([value isKindOfClass: valueClass]) - { - if ([self respondsToSelector: selector]) - { - [self performSelector: selector withObject: value]; - } - } - else { - NSLog(@"OPFontDescriptor: Ignoring invalid value %@ for attribute %@", value, key); + if ([value isKindOfClass: valueClass]) + { + if ([self respondsToSelector: selector]) + { + [self performSelector: selector withObject: value]; + } + } + else + { + NSLog(@"OPFontDescriptor: Ignoring invalid value %@ for attribute %@", value, + key); + } } - } } /** @@ -565,17 +582,28 @@ - (void)handleKey: (NSString*)key selector: (SEL)selector valueClass: (Class)val */ - (void)handleAddValues { - [self handleKey: kCTFontURLAttribute selector: @selector(addURL:) valueClass: [NSURL class]]; - [self handleKey: kCTFontNameAttribute selector: @selector(addName:) valueClass: [NSString class]]; - [self handleKey: kCTFontDisplayNameAttribute selector: @selector(addDisplayName:) valueClass: [NSString class]]; - [self handleKey: kCTFontFamilyNameAttribute selector: @selector(addFamilyName:) valueClass: [NSString class]]; - [self handleKey: kCTFontStyleNameAttribute selector: @selector(addStyleName:) valueClass: [NSString class]]; - [self handleKey: kCTFontTraitsAttribute selector: @selector(addTraits:) valueClass: [NSDictionary class]]; - [self handleKey: kCTFontSizeAttribute selector: @selector(addSize:) valueClass: [NSNumber class]]; - [self handleKey: kCTFontCharacterSetAttribute selector: @selector(addCharacterSet:) valueClass: [NSCharacterSet class]]; - [self handleKey: kCTFontLanguagesAttribute selector: @selector(addLanguages:) valueClass: [NSArray class]]; - [self handleKey: kCTFontOrientationAttribute selector: @selector(addOrientation:) valueClass: [NSNumber class]]; - [self handleKey: kCTFontFormatAttribute selector: @selector(addFormat:) valueClass: [NSNumber class]]; + [self handleKey: kCTFontURLAttribute selector: @selector( + addURL:) valueClass: [NSURL class]]; + [self handleKey: kCTFontNameAttribute selector: @selector( + addName:) valueClass: [NSString class]]; + [self handleKey: kCTFontDisplayNameAttribute selector: @selector( + addDisplayName:) valueClass: [NSString class]]; + [self handleKey: kCTFontFamilyNameAttribute selector: @selector( + addFamilyName:) valueClass: [NSString class]]; + [self handleKey: kCTFontStyleNameAttribute selector: @selector( + addStyleName:) valueClass: [NSString class]]; + [self handleKey: kCTFontTraitsAttribute selector: @selector( + addTraits:) valueClass: [NSDictionary class]]; + [self handleKey: kCTFontSizeAttribute selector: @selector( + addSize:) valueClass: [NSNumber class]]; + [self handleKey: kCTFontCharacterSetAttribute selector: @selector( + addCharacterSet:) valueClass: [NSCharacterSet class]]; + [self handleKey: kCTFontLanguagesAttribute selector: @selector( + addLanguages:) valueClass: [NSArray class]]; + [self handleKey: kCTFontOrientationAttribute selector: @selector( + addOrientation:) valueClass: [NSNumber class]]; + [self handleKey: kCTFontFormatAttribute selector: @selector( + addFormat:) valueClass: [NSNumber class]]; } @@ -583,9 +611,9 @@ - (id) initWithFontAttributes: (NSDictionary *)attributes { self = [super initWithFontAttributes: attributes]; if (nil == self) - { - return nil; - } + { + return nil; + } _pat = FcPatternCreate(); @@ -607,9 +635,9 @@ - (id) initWithImmutableMatchedPattern: (FcPattern*)pat { self = [super initWithFontAttributes: nil]; if (nil == self) - { - return nil; - } + { + return nil; + } FcPatternReference(pat); _pat = pat; @@ -623,57 +651,58 @@ - (id) initWithImmutableMatchedPattern: (FcPattern*)pat - (void)dealloc { if (_pat) - { - FcPatternDestroy(_pat); - } + { + FcPatternDestroy(_pat); + } if (_matchedPat) - { - FcPatternDestroy(_matchedPat); - } + { + FcPatternDestroy(_matchedPat); + } [super dealloc]; } - (NSString*)description { - return [NSString stringWithFormat: @"", - [self objectForKey: kCTFontNameAttribute], - [self objectForKey: kCTFontURLAttribute]]; + return [NSString stringWithFormat: + @"", + [self objectForKey: kCTFontNameAttribute], + [self objectForKey: kCTFontURLAttribute]]; } - (void)matchPattern { if (!_matchedPat) - { - FcPattern *patCopy = FcPatternDuplicate(_pat); + { + FcPattern *patCopy = FcPatternDuplicate(_pat); - //NSLog(@"1. before substituting: "); - //FcPatternPrint(patCopy); + //NSLog(@"1. before substituting: "); + //FcPatternPrint(patCopy); - FcConfigSubstitute(NULL, patCopy, FcMatchPattern); + FcConfigSubstitute(NULL, patCopy, FcMatchPattern); - //NSLog(@"2. after configSubstitute: "); - //FcPatternPrint(patCopy); + //NSLog(@"2. after configSubstitute: "); + //FcPatternPrint(patCopy); - FcDefaultSubstitute(patCopy); + FcDefaultSubstitute(patCopy); - //NSLog(@"3. after DefaultSubstitute : "); - //FcPatternPrint(patCopy); + //NSLog(@"3. after DefaultSubstitute : "); + //FcPatternPrint(patCopy); - // FIXME: FcFontMatch doesn't write in the result variable if the match was successful, this is a strange policy - FcResult result = FcResultMatch; - _matchedPat = FcFontMatch(NULL, patCopy, &result); - if (result != FcResultMatch) - { - NSLog(@"Warning, FcFontMatch failed with code: %d", result); - } - else - { - FcPatternReference(_matchedPat); - //NSLog(@"FcFontMatch succeeded, attributes: "); - //FcPatternPrint(_matchedPat); + // FIXME: FcFontMatch doesn't write in the result variable if the match was successful, this is a strange policy + FcResult result = FcResultMatch; + _matchedPat = FcFontMatch(NULL, patCopy, &result); + if (result != FcResultMatch) + { + NSLog(@"Warning, FcFontMatch failed with code: %d", result); + } + else + { + FcPatternReference(_matchedPat); + //NSLog(@"FcFontMatch succeeded, attributes: "); + //FcPatternPrint(_matchedPat); + } + FcPatternDestroy(patCopy); } - FcPatternDestroy(patCopy); - } } /** @@ -689,53 +718,54 @@ - (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)mandatoryKeys FcResult result = FcResultMatch; FcFontSet *fontSet = FcFontSort(NULL, _matchedPat, FcFalse, NULL, &result); if (result == FcResultMatch) - { - for (int i=0; infont; i++) - { - FcPattern *pat = FcPatternDuplicate(fontSet->fonts[i]); - - OPFontDescriptor *candidate = [[OPFontconfigFontDescriptor alloc] initWithImmutableMatchedPattern: pat]; - BOOL acceptable = YES; - if (mandatoryKeys) - { - NSEnumerator *enumerator = [mandatoryKeys objectEnumerator]; - NSString *mandatoryKey; - while (nil != (mandatoryKey = [enumerator nextObject])) - { - id selfValue = [self objectForKey: mandatoryKey]; - id candidateValue = [candidate objectForKey: mandatoryKey]; - - if ((selfValue != nil || candidateValue != nil) - && ![selfValue isEqual: candidateValue]) - { - // Hack: only requre kCTFontTraitsAttribute to have the same kCTFontSymbolicTrait - if ([mandatoryKey isEqualToString: kCTFontTraitsAttribute]) + { + for (int i=0; infont; i++) + { + FcPattern *pat = FcPatternDuplicate(fontSet->fonts[i]); + + OPFontDescriptor *candidate = [[OPFontconfigFontDescriptor alloc] + initWithImmutableMatchedPattern: pat]; + BOOL acceptable = YES; + if (mandatoryKeys) { - if ([[selfValue objectForKey: kCTFontSymbolicTrait] intValue] - == [[candidateValue objectForKey: kCTFontSymbolicTrait] intValue]) - { - continue; // Good enough match - } + NSEnumerator *enumerator = [mandatoryKeys objectEnumerator]; + NSString *mandatoryKey; + while (nil != (mandatoryKey = [enumerator nextObject])) + { + id selfValue = [self objectForKey: mandatoryKey]; + id candidateValue = [candidate objectForKey: mandatoryKey]; + + if ((selfValue != nil || candidateValue != nil) + && ![selfValue isEqual: candidateValue]) + { + // Hack: only requre kCTFontTraitsAttribute to have the same kCTFontSymbolicTrait + if ([mandatoryKey isEqualToString: kCTFontTraitsAttribute]) + { + if ([[selfValue objectForKey: kCTFontSymbolicTrait] intValue] + == [[candidateValue objectForKey: kCTFontSymbolicTrait] intValue]) + { + continue; // Good enough match + } + } + // Otherwise, reject. + acceptable = NO; + break; + } + } } - // Otherwise, reject. - acceptable = NO; - break; - } - } - } - if (acceptable) - { - [matching addObject: candidate]; - } - [candidate release]; + if (acceptable) + { + [matching addObject: candidate]; + } + [candidate release]; - FcPatternDestroy(pat); + FcPatternDestroy(pat); + } } - } else - { - NSLog(@"ERROR! FcFontSort failed"); - } + { + NSLog(@"ERROR! FcFontSort failed"); + } FcFontSetDestroy(fontSet); @@ -752,37 +782,44 @@ - (NSValue*)selValue: (SEL)selector - (id) objectFromPlatformFontPatternForKey: (NSString *)attribute { if (!ReadSelectors) - { - ReadSelectors = [[NSDictionary alloc] initWithObjectsAndKeys: - [self selValue: @selector(readURLFromPattern:)], kCTFontURLAttribute, - [self selValue: @selector(readNameFromPattern:)], kCTFontNameAttribute, - [self selValue: @selector(readDisplayNameFromPattern:)], kCTFontDisplayNameAttribute, - [self selValue: @selector(readFamilyNameFromPattern:)], kCTFontFamilyNameAttribute, - [self selValue: @selector(readStyleNameFromPattern:)], kCTFontStyleNameAttribute, - [self selValue: @selector(readTraitsFromPattern:)], kCTFontTraitsAttribute, - [self selValue: @selector(readSizeFromPattern:)], kCTFontSizeAttribute, - [self selValue: @selector(readCharacterSetFromPattern:)], kCTFontCharacterSetAttribute, - [self selValue: @selector(readLanguagesFromPattern:)], kCTFontLanguagesAttribute, - [self selValue: @selector(readOrientationFromPattern:)], kCTFontOrientationAttribute, - [self selValue: @selector(readFormatFromPattern:)], kCTFontFormatAttribute, - nil]; - } + { + ReadSelectors = [[NSDictionary alloc] initWithObjectsAndKeys: + [self selValue: @selector(readURLFromPattern:)], kCTFontURLAttribute, + [self selValue: @selector(readNameFromPattern:)], kCTFontNameAttribute, + [self selValue: @selector(readDisplayNameFromPattern:)], + kCTFontDisplayNameAttribute, + [self selValue: @selector(readFamilyNameFromPattern:)], + kCTFontFamilyNameAttribute, + [self selValue: @selector(readStyleNameFromPattern:)], + kCTFontStyleNameAttribute, + [self selValue: @selector(readTraitsFromPattern:)], kCTFontTraitsAttribute, + [self selValue: @selector(readSizeFromPattern:)], kCTFontSizeAttribute, + [self selValue: @selector(readCharacterSetFromPattern:)], + kCTFontCharacterSetAttribute, + [self selValue: @selector(readLanguagesFromPattern:)], + kCTFontLanguagesAttribute, + [self selValue: @selector(readOrientationFromPattern:)], + kCTFontOrientationAttribute, + [self selValue: @selector(readFormatFromPattern:)], kCTFontFormatAttribute, + nil]; + } [self matchPattern]; id selValue = [ReadSelectors objectForKey: attribute]; if (selValue) - { - SEL sel; - [selValue getValue: &sel]; + { + SEL sel; + [selValue getValue: &sel]; - id result = [self performSelector: sel withObject: (id)_matchedPat]; - return result; - } + id result = [self performSelector: sel withObject: (id)_matchedPat]; + return result; + } return nil; } -- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: (NSString*)language +- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: + (NSString*)language { // Only FC_FAMILY, FC_STYLE, FC_FULLNAME are localized. @@ -791,39 +828,39 @@ - (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: (N // FIXME: kCTFontNameAttribute hack if ([key isEqualToString: kCTFontNameAttribute] || [key isEqualToString: kCTFontFamilyNameAttribute]) - { - return [self readFontconfigLocalizedStringWithKey: FC_FAMILY - languageKey: FC_FAMILYLANG - language: language - fromPattern: _matchedPat]; - } + { + return [self readFontconfigLocalizedStringWithKey: FC_FAMILY + languageKey: FC_FAMILYLANG + language: language + fromPattern: _matchedPat]; + } else if ([key isEqualToString: kCTFontStyleNameAttribute]) - { - return [self readFontconfigLocalizedStringWithKey: FC_STYLE - languageKey: FC_STYLELANG - language: language - fromPattern: _matchedPat]; - } + { + return [self readFontconfigLocalizedStringWithKey: FC_STYLE + languageKey: FC_STYLELANG + language: language + fromPattern: _matchedPat]; + } else if ([key isEqualToString: kCTFontDisplayNameAttribute]) - { - return [self readFontconfigLocalizedStringWithKey: FC_FULLNAME - languageKey: FC_FULLNAMELANG - language: language - fromPattern: _matchedPat]; - } + { + return [self readFontconfigLocalizedStringWithKey: FC_FULLNAME + languageKey: FC_FULLNAMELANG + language: language + fromPattern: _matchedPat]; + } return nil; } - (NSString*)_fontPath { return [self readFontconfigString: FC_FILE - fromPattern: _matchedPat]; + fromPattern: _matchedPat]; } - (NSInteger)_fontfaceIndex { return [[self readFontconfigInteger: FC_INDEX - fromPattern: _matchedPat] integerValue]; + fromPattern: _matchedPat] integerValue]; } @end diff --git a/Source/OpalText/FreeType/OPFreeTypeFont.h b/Source/OpalText/FreeType/OPFreeTypeFont.h index 0bf111c..34db7a3 100644 --- a/Source/OpalText/FreeType/OPFreeTypeFont.h +++ b/Source/OpalText/FreeType/OPFreeTypeFont.h @@ -28,7 +28,7 @@ #import "../OPFont.h" #include -@interface OPFreeTypeFont: OPFont +@interface OPFreeTypeFont : OPFont { FT_Face fontFace; /** diff --git a/Source/OpalText/FreeType/OPFreeTypeFont.m b/Source/OpalText/FreeType/OPFreeTypeFont.m index 426717b..46afe91 100644 --- a/Source/OpalText/FreeType/OPFreeTypeFont.m +++ b/Source/OpalText/FreeType/OPFreeTypeFont.m @@ -62,18 +62,20 @@ @implementation OPFreeTypeFont - (FT_Library)currentThreadFreeTypeLibrary { NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary]; - + if (nil == [threadDict objectForKey: kOPFreeTypeLibrary]) - { - FT_Library library = NULL; - NSInteger error = FT_Init_FreeType(&library); - if (0 != error) { - [NSException raise: @"OTFontSystemException" - format: @"An error (%ld) occurred when initializing the FreeType library.", error]; + FT_Library library = NULL; + NSInteger error = FT_Init_FreeType(&library); + if (0 != error) + { + [NSException raise: @"OTFontSystemException" + format: @"An error (%ld) occurred when initializing the FreeType library.", + error]; + } + [threadDict setObject: [NSValue valueWithPointer: library] forKey: + kOPFreeTypeLibrary]; } - [threadDict setObject: [NSValue valueWithPointer: library] forKey: kOPFreeTypeLibrary]; - } return [[threadDict objectForKey: kOPFreeTypeLibrary] pointerValue]; } @@ -86,41 +88,43 @@ - (id)_initWithDescriptor: (OPFontDescriptor*)aDescriptor NSInteger faceIndex = NSNotFound; if (nil == (self = [super _initWithDescriptor: aDescriptor options: options])) - { - return nil; - } + { + return nil; + } /* * FIXME: It is ugly to rely on the font descriptor being a * OPFontconfigFontDescriptor but it is probably the most common situation. */ if ([aDescriptor respondsToSelector: @selector(_fontPath)]) - { - path = [[_descriptor _fontPath] UTF8String]; - } + { + path = [[_descriptor _fontPath] UTF8String]; + } else - { - path = NULL; - } + { + path = NULL; + } if ([aDescriptor respondsToSelector: @selector(_fontfaceIndex)]) - { - faceIndex = [_descriptor _fontfaceIndex]; - } + { + faceIndex = [_descriptor _fontfaceIndex]; + } if ((NSNotFound == faceIndex) || (NULL == path)) - { - NSWarnMLog(@"Could not read freetype intialization information from font descriptor"); - [self release]; - return nil; - } + { + NSWarnMLog( + @"Could not read freetype intialization information from font descriptor"); + [self release]; + return nil; + } - error = FT_New_Face([self currentThreadFreeTypeLibrary], path, faceIndex, &fontFace); + error = FT_New_Face([self currentThreadFreeTypeLibrary], path, faceIndex, + &fontFace); if (0 != error) - { - NSWarnMLog(@"Could not initialize freetype font (error: %ld)", - error); - [self release]; - return nil; - } + { + NSWarnMLog(@"Could not initialize freetype font (error: %ld)", + error); + [self release]; + return nil; + } /* * Check whether we are dealing with an sfnt packaged font. If not, we may be @@ -128,22 +132,22 @@ - (id)_initWithDescriptor: (OPFontDescriptor*)aDescriptor * metrics from the corresponding afm file. */ if ((0 == faceIndex) && (NO == (BOOL)FT_IS_SFNT(fontFace))) - { - if (NO == [self attachMetricsForFontAtPath: [_descriptor _fontPath]]) { - [self release]; - return nil; - } - else - { - /* - * We were able to load the metrics for the font and flag the font object - * accordingly. - * FIXME: Move to another subclass in this case. - */ - isType1 = YES; + if (NO == [self attachMetricsForFontAtPath: [_descriptor _fontPath]]) + { + [self release]; + return nil; + } + else + { + /* + * We were able to load the metrics for the font and flag the font object + * accordingly. + * FIXME: Move to another subclass in this case. + */ + isType1 = YES; + } } - } // At this point, we are sure that freetype has a proper reference to the // font, so it's worth setting up our table cache now. tableCache = [[NSCache alloc] init]; @@ -168,18 +172,18 @@ - (BOOL)attachMetricsForFontAtPath: (NSString*)path NSInteger error = 0; if ([@"pfa" isEqual: extension] || [@"pfb" isEqual: extension]) - { - /* - * If the file already has a proper Type-1 extension, we assume that we need - * to replace that with .afm. Hence, we remove the extension from the path - * at this point. - */ - afmPath = [path substringToIndex: ([path length] - 4)]; - } + { + /* + * If the file already has a proper Type-1 extension, we assume that we need + * to replace that with .afm. Hence, we remove the extension from the path + * at this point. + */ + afmPath = [path substringToIndex: ([path length] - 4)]; + } else - { - afmPath = path; - } + { + afmPath = path; + } // Add the proper extension afmPath = [afmPath stringByAppendingString: @".afm"]; @@ -200,28 +204,28 @@ - (NSData*)loadTableForTag: (uint32_t)tag NSData *table = nil; if (0 == tag) - { - // tag == 0 means "whole file", and the caller didn't really mean that. - return nil; - } + { + // tag == 0 means "whole file", and the caller didn't really mean that. + return nil; + } // First, run with a NULL pointer for the buffer to obtain the length needed. [fontFaceLock lock]; error = FT_Load_Sfnt_Table(fontFace, tag, 0, NULL, &length); if (0 != error) - { - [fontFaceLock unlock]; - return nil; - } + { + [fontFaceLock unlock]; + return nil; + } // Allocate memory for the table: buffer = malloc(length); if (NULL == buffer) - { - [fontFaceLock unlock]; - return nil; - } + { + [fontFaceLock unlock]; + return nil; + } // Now load the table into the buffer: error = FT_Load_Sfnt_Table(fontFace, tag, 0, buffer, &length); @@ -229,11 +233,11 @@ - (NSData*)loadTableForTag: (uint32_t)tag [fontFaceLock unlock]; if (0 != error) - { - // Oops, we could not fill the buffer, so we throw it away. - free(buffer); - return nil; - } + { + // Oops, we could not fill the buffer, so we throw it away. + free(buffer); + return nil; + } table = [NSData dataWithBytesNoCopy: buffer length: length]; @@ -256,15 +260,15 @@ - (NSData*)tableForTag: (uint32_t)tag length: 4]; NSData *table = [tableCache objectForKey: tagString]; if (nil == table) - { - table = [self loadTableForTag: tag]; - if (table != nil) { - [tableCache setObject: table - forKey: tagString - cost: [table length]]; + table = [self loadTableForTag: tag]; + if (table != nil) + { + [tableCache setObject: table + forKey: tagString + cost: [table length]]; + } } - } [tagString release]; return table; @@ -282,7 +286,8 @@ - (CGFloat)unitsPerEm - (CGFloat)ascender { [fontFaceLock lock]; - CGFloat result = ((fontFace->ascender * [_descriptor pointSize]) / (CGFloat)fontFace->units_per_EM); + CGFloat result = ((fontFace->ascender * [_descriptor pointSize]) / + (CGFloat)fontFace->units_per_EM); [fontFaceLock unlock]; return result; @@ -292,7 +297,8 @@ - (CGFloat)ascender - (CGFloat)descender { [fontFaceLock lock]; - CGFloat result = ((fontFace->descender * [_descriptor pointSize]) / (CGFloat)fontFace->units_per_EM); + CGFloat result = ((fontFace->descender * [_descriptor pointSize]) / + (CGFloat)fontFace->units_per_EM); [fontFaceLock unlock]; return result; @@ -308,10 +314,10 @@ - (CGFloat)capHeight [fontFaceLock lock]; TT_OS2* OS2Table = FT_Get_Sfnt_Table(fontFace, TTAG_OS2); if (NULL == OS2Table) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } rawCapHeight = OS2Table->sCapHeight; [fontFaceLock unlock]; @@ -325,10 +331,10 @@ - (CGFloat)xHeight [fontFaceLock lock]; TT_OS2* OS2Table = FT_Get_Sfnt_Table(fontFace, TTAG_OS2); if (NULL == OS2Table) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } rawXHeight = OS2Table->sxHeight; [fontFaceLock unlock]; @@ -343,10 +349,10 @@ - (BOOL)isFixedPitch [fontFaceLock lock]; TT_Postscript *postTable = FT_Get_Sfnt_Table(fontFace, TTAG_post); if (NULL == postTable) - { - [fontFaceLock unlock]; - return NO; - } + { + [fontFaceLock unlock]; + return NO; + } isFixedPitch = postTable->isFixedPitch; [fontFaceLock unlock]; @@ -359,10 +365,10 @@ - (CGFloat)italicAngle [fontFaceLock lock]; TT_Postscript *postTable = FT_Get_Sfnt_Table(fontFace, TTAG_post); if (NULL == postTable) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } rawItalicAngle = postTable->italicAngle; [fontFaceLock unlock]; @@ -381,10 +387,10 @@ - (CGFloat)leading [fontFaceLock lock]; TT_HoriHeader *hheaTable = FT_Get_Sfnt_Table(fontFace, TTAG_hhea); if (NULL == hheaTable) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } rawLineGap = hheaTable->Line_Gap; [fontFaceLock unlock]; @@ -397,7 +403,8 @@ - (NSSize)maximumAdvancement * FIXME: We should make this conditional on horizontal/vertical orientation. */ [fontFaceLock lock]; - NSSize size = NSMakeSize(REAL_SIZE(fontFace->max_advance_width), REAL_SIZE(fontFace->max_advance_height)); + NSSize size = NSMakeSize(REAL_SIZE(fontFace->max_advance_width), + REAL_SIZE(fontFace->max_advance_height)); [fontFaceLock unlock]; return size; @@ -412,7 +419,7 @@ - (NSSize)minimumAdvancement */ [fontFaceLock lock]; NSSize size = NSMakeSize(REAL_SIZE((fontFace->bbox).xMin), - REAL_SIZE((fontFace->bbox).yMin)); + REAL_SIZE((fontFace->bbox).yMin)); [fontFaceLock unlock]; return size; @@ -431,10 +438,10 @@ - (CGFloat)underlinePosition [fontFaceLock lock]; TT_Postscript *postTable = FT_Get_Sfnt_Table(fontFace, TTAG_post); if (NULL == postTable) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } CGFloat position = TRANSFORMED_SIZE(0, postTable->underlinePosition).height; [fontFaceLock unlock]; return position; @@ -445,10 +452,10 @@ - (CGFloat)underlineThickness [fontFaceLock lock]; TT_Postscript *postTable = FT_Get_Sfnt_Table(fontFace, TTAG_post); if (NULL == postTable) - { - [fontFaceLock unlock]; - return 0; - } + { + [fontFaceLock unlock]; + return 0; + } CGFloat thickness = TRANSFORMED_SIZE(0, postTable->underlineThickness).height; [fontFaceLock unlock]; return thickness; @@ -457,13 +464,13 @@ - (CGFloat)underlineThickness - (NSSize)advancementForGlyph: (NSGlyph)glyph { if ((NSNullGlyph == glyph) || (NSControlGlyph == glyph)) - { - return NSMakeSize(0, 0); - } + { + return NSMakeSize(0, 0); + } [fontFaceLock lock]; FT_Load_Glyph(fontFace, glyph, FT_LOAD_DEFAULT); NSSize size = NSMakeSize(REAL_SIZE(fontFace->glyph->linearHoriAdvance), - REAL_SIZE(fontFace->glyph->linearVertAdvance)); + REAL_SIZE(fontFace->glyph->linearVertAdvance)); [fontFaceLock unlock]; return size; @@ -475,26 +482,26 @@ - (NSSize)advancementForGlyph: (NSGlyph)glyph - (void)getAdvancements: (NSSizeArray)advancements forGlyphs: (const NSGlyph*)glyphs - count: (NSUInteger)glyphCount + count: (NSUInteger)glyphCount { NSSize nullSize = NSMakeSize(0,0); for (int i = 0; i < glyphCount; i++, glyphs++, advancements++) - { - if ((NSNullGlyph == *glyphs) || (NSControlGlyph == *glyphs)) { - *advancements = nullSize; + if ((NSNullGlyph == *glyphs) || (NSControlGlyph == *glyphs)) + { + *advancements = nullSize; + } + else + { + //TODO: Optimize if too slow. + *advancements = [self advancementForGlyph: *glyphs]; + } } - else - { - //TODO: Optimize if too slow. - *advancements = [self advancementForGlyph: *glyphs]; - } - } } - (void)getAdvancements: (NSSizeArray)advancements forPackedGlyphs: (const void*)packedGlyphs - length: (NSUInteger)length + length: (NSUInteger)length { /* * We only support NSNativeShortGlyphPacking, which gives us glyph streams @@ -505,24 +512,26 @@ - (void)getAdvancements: (NSSizeArray)advancements NSUInteger glyphsPerWord = sizeof(void*)/sizeof(unsigned short); NSUInteger maxGlyphCount = length * glyphsPerWord; NSUInteger step = 0; - for (int i=0; i < maxGlyphCount; i++, step = (i / sizeof(void*)), advancements++) - { - /* - * Mask the value by bit-shifting it to the correct starting point, - * truncating it to short, and converting it back to host byte-order. - */ - - /* - * The modulus of index and word size calculates how many glyphs we - * processed in this word, so we shift the content of the word by n - * times the size of short. - */ - NSUInteger shift = ((i % sizeof(void*)) * sizeof(unsigned short)); - NSGlyph glyph = NSSwapBigShortToHost((unsigned short)(((intptr_t*)packedGlyphs)[step] << shift)); - - // TODO: Optimize if too slow - *advancements = [self advancementForGlyph: glyph]; - } + for (int i=0; i < maxGlyphCount; + i++, step = (i / sizeof(void*)), advancements++) + { + /* + * Mask the value by bit-shifting it to the correct starting point, + * truncating it to short, and converting it back to host byte-order. + */ + + /* + * The modulus of index and word size calculates how many glyphs we + * processed in this word, so we shift the content of the word by n + * times the size of short. + */ + NSUInteger shift = ((i % sizeof(void*)) * sizeof(unsigned short)); + NSGlyph glyph = NSSwapBigShortToHost((unsigned short)((( + intptr_t*)packedGlyphs)[step] << shift)); + + // TODO: Optimize if too slow + *advancements = [self advancementForGlyph: glyph]; + } } - (NSRect)boundingRectForFont @@ -543,37 +552,38 @@ - (NSRect)boundingRectforGlyph: (NSGlyph)glyph { //FIXME: Handle vertical typesetting. if ((NSNullGlyph == glyph) || (NSControlGlyph == glyph)) - { - return NSMakeRect(0, 0, 0, 0); - } + { + return NSMakeRect(0, 0, 0, 0); + } [fontFaceLock lock]; FT_Load_Glyph(fontFace, glyph, FT_LOAD_DEFAULT); - NSRect result = NSRectFromCGRect(TRANSFORMED_RECT(fontFace->glyph->metrics.horiBearingX, - fontFace->glyph->metrics.horiBearingY, - fontFace->glyph->metrics.width, - fontFace->glyph->metrics.height)); + NSRect result = NSRectFromCGRect(TRANSFORMED_RECT( + fontFace->glyph->metrics.horiBearingX, + fontFace->glyph->metrics.horiBearingY, + fontFace->glyph->metrics.width, + fontFace->glyph->metrics.height)); [fontFaceLock unlock]; return result; } - (void)getBoundingRects: (NSRectArray)rects forGlyphs: (const NSGlyph*)glyphs - count: (NSUInteger)glyphCount + count: (NSUInteger)glyphCount { NSRect nullRect = NSMakeRect(0,0,0,0); for (int i = 0; i < glyphCount; i++, glyphs++, rects++) - { - if ((NSNullGlyph == *glyphs) || (NSControlGlyph == *glyphs)) { - *rects = nullRect; + if ((NSNullGlyph == *glyphs) || (NSControlGlyph == *glyphs)) + { + *rects = nullRect; + } + else + { + //TODO: Optimize if too slow. + *rects = [self boundingRectForGlyph: *glyphs]; + } } - else - { - //TODO: Optimize if too slow. - *rects = [self boundingRectForGlyph: *glyphs]; - } - } } - (NSGlyph)glyphWithName: (NSString*)name @@ -581,10 +591,10 @@ - (NSGlyph)glyphWithName: (NSString*)name [fontFaceLock lock]; FT_UInt glyph = FT_Get_Name_Index(fontFace, (FT_String*)[name UTF8String]); [fontFaceLock unlock]; - if(0 == glyph) - { - return NSNullGlyph; - } + if (0 == glyph) + { + return NSNullGlyph; + } return glyph; } diff --git a/Source/OpalText/FreeType/OPFreeTypeUtil.h b/Source/OpalText/FreeType/OPFreeTypeUtil.h index b0ec3fa..8f93518 100644 --- a/Source/OpalText/FreeType/OPFreeTypeUtil.h +++ b/Source/OpalText/FreeType/OPFreeTypeUtil.h @@ -40,24 +40,28 @@ static inline FT_Fixed FT_FixedFromCGFloat(CGFloat f) } -static inline CGFloat CGFloatFromFontUnits(NSInteger units, CGFloat pointSize, NSUInteger unitsPerEm) +static inline CGFloat CGFloatFromFontUnits(NSInteger units, CGFloat pointSize, + NSUInteger unitsPerEm) { return (((CGFloat)units * pointSize) / (CGFloat)unitsPerEm); } -static inline FT_Matrix FT_MatrixFromCGAffineTransform(CGAffineTransform transform) +static inline FT_Matrix FT_MatrixFromCGAffineTransform(CGAffineTransform + transform) { FT_Matrix theMatrix = {FT_FixedFromCGFloat(transform.a), - FT_FixedFromCGFloat(transform.b), - FT_FixedFromCGFloat(transform.c), - FT_FixedFromCGFloat(transform.d)}; + FT_FixedFromCGFloat(transform.b), + FT_FixedFromCGFloat(transform.c), + FT_FixedFromCGFloat(transform.d) + }; return theMatrix; } /** * Creates a Q16.16 fixed point translation vector from an affine transform. */ -static inline FT_Vector FT_VectorQ1616FromCGAffineTransform(CGAffineTransform transform) +static inline FT_Vector FT_VectorQ1616FromCGAffineTransform( + CGAffineTransform transform) { FT_Vector theVector = {FT_FixedFromCGFloat(transform.tx), FT_FixedFromCGFloat(transform.ty)}; return theVector; diff --git a/Source/OpalText/GDI/NSGDIFontDescriptor.m b/Source/OpalText/GDI/NSGDIFontDescriptor.m index eaf28d2..44a1543 100644 --- a/Source/OpalText/GDI/NSGDIFontDescriptor.m +++ b/Source/OpalText/GDI/NSGDIFontDescriptor.m @@ -11,12 +11,12 @@ 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 @@ -52,102 +52,102 @@ - (void)addStyleName: (NSString*)style - (void)addTraits: (NSDictionary*)traits { if ([traits objectForKey: kCTFontSymbolicTrait]) - { - CTFontSymbolicTraits symTraits = [traits objectForKey: kCTFontSymbolicTrait]; - - if (symTraits & kCTFontItalicTrait) - { - _logfont.lfItalic = TRUE; - } - if (symTraits & kCTFontBoldTrait) - { - // NOTE: May be overridden by kCTFontWeightTrait - _logfont.lfWeight = FW_BOLD; - } - if (symTraits & kCTFontExpandedTrait) - { - } - if (symTraits & kCTFontCondensedTrait) { + CTFontSymbolicTraits symTraits = [traits objectForKey: kCTFontSymbolicTrait]; + + if (symTraits & kCTFontItalicTrait) + { + _logfont.lfItalic = TRUE; + } + if (symTraits & kCTFontBoldTrait) + { + // NOTE: May be overridden by kCTFontWeightTrait + _logfont.lfWeight = FW_BOLD; + } + if (symTraits & kCTFontExpandedTrait) + { + } + if (symTraits & kCTFontCondensedTrait) + { + } + if (symTraits & kCTFontMonoSpaceTrait) + { + _logfont.lfPitchAndFamily |= FIXED_PITCH | FF_MODERN; + } + if (symTraits & kCTFontVerticalTrait) + { + } + if (symTraits & kCTFontUIOptimizedTrait) + { + } + + CTFontStylisticClass class = symbolicTraits & kCTFontClassMaskTrait; + + switch (class) + { + default: + case kCTFontUnknownClass: + case kCTFontSymbolicClass: + _logfont.lfPitchAndFamily |= FF_DONTCARE; + break; + case kCTFontOrnamentalsClass: + _logfont.lfPitchAndFamily |= FF_DECORATIVE; + break; + case kCTFontScriptsClass: + _logfont.lfPitchAndFamily |= FF_SCRIPT; + break; + case kCTFontOldStyleSerifsClass: + case kCTFontTransitionalSerifsClass: + case kCTFontModernSerifsClass: + case kCTFontClarendonSerifsClass: + case kCTFontSlabSerifsClass: + case kCTFontFreeformSerifsClass: + _logfont.lfPitchAndFamily |= FF_ROMAN; + break; + case kCTFontSansSerifClass: + _logfont.lfPitchAndFamily |= FF_SWISS; + break; + } } - if (symTraits & kCTFontMonoSpaceTrait) - { - _logfont.lfPitchAndFamily |= FIXED_PITCH | FF_MODERN; - } - if (symTraits & kCTFontVerticalTrait) - { - } - if (symTraits & kCTFontUIOptimizedTrait) - { - } - - CTFontStylisticClass class = symbolicTraits & kCTFontClassMaskTrait; - - switch (class) - { - default: - case kCTFontUnknownClass: - case kCTFontSymbolicClass: - _logfont.lfPitchAndFamily |= FF_DONTCARE; - break; - case kCTFontOrnamentalsClass: - _logfont.lfPitchAndFamily |= FF_DECORATIVE; - break; - case kCTFontScriptsClass: - _logfont.lfPitchAndFamily |= FF_SCRIPT; - break; - case kCTFontOldStyleSerifsClass: - case kCTFontTransitionalSerifsClass: - case kCTFontModernSerifsClass: - case kCTFontClarendonSerifsClass: - case kCTFontSlabSerifsClass: - case kCTFontFreeformSerifsClass: - _logfont.lfPitchAndFamily |= FF_ROMAN; - break; - case kCTFontSansSerifClass: - _logfont.lfPitchAndFamily |= FF_SWISS; - break; - } - } if ([traits objectForKey: kCTFontWeightTrait]) - { - /** - * Scale: -1 is thinnest, 0 is normal, 1 is heaviest - */ - double weight = [[traits objectForKey: kCTFontWeightTrait] doubleValue]; - weight = MAX(-1, MIN(1, weight)); - if (weight <= 0) { - _logfont.lfWeight = FW_THIN + ((weight + 1.0) * (FW_REGULAR - FW_THIN)); + /** + * Scale: -1 is thinnest, 0 is normal, 1 is heaviest + */ + double weight = [[traits objectForKey: kCTFontWeightTrait] doubleValue]; + weight = MAX(-1, MIN(1, weight)); + if (weight <= 0) + { + _logfont.lfWeight = FW_THIN + ((weight + 1.0) * (FW_REGULAR - FW_THIN)); + } + else + { + _logfont.lfWeight = FW_NORMAL + (weight * (FW_BLACK - FW_NORMAL)); + } } - else - { - _logfont.lfWeight = FW_NORMAL + (weight * (FW_BLACK - FW_NORMAL)); - } - } if ([traits objectForKey: kCTFontWidthTrait]) - { - } + { + } if ([traits objectForKey: kCTFontSlantTrait]) - { - /** - * Scale: -1 is 30 degree counterclockwise slant, 0 is no slant, 1 - * is 30 degree clockwise slant - */ - double slant = [[traits objectForKey: kCTFontSlantTrait] doubleValue]; - - if (slant > 0) { - _logfont.lfItalic = TRUE; + /** + * Scale: -1 is 30 degree counterclockwise slant, 0 is no slant, 1 + * is 30 degree clockwise slant + */ + double slant = [[traits objectForKey: kCTFontSlantTrait] doubleValue]; + + if (slant > 0) + { + _logfont.lfItalic = TRUE; + } + else + { + _logfont.lfItalic = FALSE; + } } - else - { - _logfont.lfItalic = FALSE; - } - } } - (void)addVariation: (NSDictionary*)variationDict @@ -211,22 +211,22 @@ - (void)addFormat: (NSNumber*)format { CTFontFormat fmt = [format intValue]; switch (fmt) - { - default: - case kCTFontFormatUnrecognized: - break; - case kCTFontFormatOpenTypePostScript: - case kCTFontFormatOpenTypeTrueType: - case kCTFontFormatTrueType: - _logfont.lfOutPrecision = OUT_OUTLINE_PRECIS; - break; - case kCTFontFormatPostScript: - _logfont.lfOutPrecision = OUT_PS_ONLY_PRECIS; - break; - case kCTFontFormatBitmap: - _logfont.lfOutPrecision = OUT_RASTER_PRECIS; - break; - } + { + default: + case kCTFontFormatUnrecognized: + break; + case kCTFontFormatOpenTypePostScript: + case kCTFontFormatOpenTypeTrueType: + case kCTFontFormatTrueType: + _logfont.lfOutPrecision = OUT_OUTLINE_PRECIS; + break; + case kCTFontFormatPostScript: + _logfont.lfOutPrecision = OUT_PS_ONLY_PRECIS; + break; + case kCTFontFormatBitmap: + _logfont.lfOutPrecision = OUT_RASTER_PRECIS; + break; + } } - (void)addRegistrationScope: (NSNumber*)registrationScope diff --git a/Source/OpalText/OPFont.h b/Source/OpalText/OPFont.h index 75c9b33..0aafd60 100644 --- a/Source/OpalText/OPFont.h +++ b/Source/OpalText/OPFont.h @@ -45,18 +45,21 @@ typedef unsigned int NSGlyph; -enum { +enum +{ NSControlGlyph = 0x00ffffff, GSAttachmentGlyph = 0x00fffffe, NSNullGlyph = 0x0 }; -typedef enum _NSGlyphRelation { +typedef enum _NSGlyphRelation +{ NSGlyphBelow, NSGlyphAbove, } NSGlyphRelation; -typedef enum _NSMultibyteGlyphPacking { +typedef enum _NSMultibyteGlyphPacking +{ NSOneByteGlyphPacking, NSJapaneseEUCGlyphPacking, NSAsciiWithDoubleByteEUCGlyphPacking, @@ -193,7 +196,7 @@ typedef union _OPAffineTransform - (NSString*) nameForGlyph: (CGGlyph)graphicsGlyph; + (CTFontRef) fontWithData: (NSData*)fontData size: (CGFloat)size - matrix: (const CGFloat*)fontMatrix + matrix: (const CGFloat*)fontMatrix additionalDescriptor: (OPFontDescriptor*)descriptor; - (id)_initWithDescriptor: (OPFontDescriptor*)descriptor @@ -209,7 +212,8 @@ typedef union _OPAffineTransform matrix: (const CGFloat*)fontMatrix; + (OPFont*) fontWithName: (NSString*)aFontName size: (CGFloat)fontSize; -+ (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor size: (CGFloat)size; ++ (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor size: + (CGFloat)size; + (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor textTransform: (NSAffineTransform*)transform; // This method was a mistake in the 10.4 documentation @@ -275,14 +279,14 @@ typedef union _OPAffineTransform - (BOOL) glyphIsEncoded: (NSGlyph)aGlyph; - (NSMultibyteGlyphPacking) glyphPacking; - (NSPoint) positionOfGlyph: (NSGlyph)curGlyph - precededByGlyph: (NSGlyph)prevGlyph - isNominal: (BOOL*)nominal; + precededByGlyph: (NSGlyph)prevGlyph + isNominal: (BOOL*)nominal; - (NSPoint) positionOfGlyph: (NSGlyph)aGlyph - forCharacter: (unichar)aChar - struckOverRect: (NSRect)aRect; + forCharacter: (unichar)aChar + struckOverRect: (NSRect)aRect; - (NSPoint) positionOfGlyph: (NSGlyph)aGlyph - struckOverGlyph: (NSGlyph)baseGlyph - metricsExist: (BOOL*)flag; + struckOverGlyph: (NSGlyph)baseGlyph + metricsExist: (BOOL*)flag; - (NSPoint) positionOfGlyph: (NSGlyph)aGlyph struckOverRect: (NSRect)aRect metricsExist: (BOOL*)flag; diff --git a/Source/OpalText/OPFont.m b/Source/OpalText/OPFont.m index 8fd218b..9e19e79 100644 --- a/Source/OpalText/OPFont.m +++ b/Source/OpalText/OPFont.m @@ -198,68 +198,69 @@ + (OPFont*) fontWithDescriptor: (OPFontDescriptor*)descriptor { // FIXME: placeholder code. return [[[OPFont alloc] _initWithDescriptor: descriptor - options: options] autorelease]; + options: options] autorelease]; } + (OPFont*) fontWithGraphicsFont: (CGFontRef)graphics additionalDescriptor: (OPFontDescriptor*)descriptor { - return nil; + return nil; } - (id)_initWithDescriptor: (OPFontDescriptor*)aDescriptor options: (CTFontOptions)options { if (nil == (self = [super init])) - { - return nil; - } + { + return nil; + } ASSIGN(_descriptor, aDescriptor); - NSAffineTransform *transform = [_descriptor objectForKey: OPFontMatrixAttribute]; + NSAffineTransform *transform = [_descriptor objectForKey: + OPFontMatrixAttribute]; if (transform == nil) - { - _matrix.CGTransform = CGAffineTransformIdentity; - } + { + _matrix.CGTransform = CGAffineTransformIdentity; + } else - { - _matrix.NSTransform = [transform transformStruct]; - } + { + _matrix.NSTransform = [transform transformStruct]; + } return self; } - (CGFloat) unitsPerEm { - return 0; + return 0; } - (NSString*) nameForKey: (NSString*)nameKey { - return nil; + return nil; } - (NSString*) localizedNameForKey: (NSString*)nameKey language: (NSString**)languageOut { - return nil; + return nil; } - (bool) getGraphicsGlyphsForCharacters: (const unichar *)characters graphicsGlyphs: (const CGGlyph *)glyphs count: (CFIndex)count { - return 0; + return 0; } - (double) getAdvancesForGraphicsGlyphs: (const CGGlyph *)glyphs advances: (CGSize*)advances orientation: (CTFontOrientation)orientation count: (CFIndex)count { - return 0; + return 0; } - (CGRect) getBoundingRectsForGraphicsGlyphs: (const CGGlyph *)glyphs rects: (CGRect*)rects orientation: (CTFontOrientation)orientation count: (CFIndex)count { - CGRect r = {{0,0},{0,0}}; - return r; + CGRect r = {{0,0},{0,0}}; + return r; } - (void) getVerticalTranslationForGraphicsGlyphs: (const CGGlyph*)glyphs translation: (CGSize*)translation @@ -269,28 +270,28 @@ - (void) getVerticalTranslationForGraphicsGlyphs: (const CGGlyph*)glyphs - (CGPathRef) graphicsPathForGlyph: (CGGlyph)glyph transform: (const CGAffineTransform *)xform { - return nil; + return nil; } - (NSArray*) variationAxes { - return nil; + return nil; } - (NSDictionary*) variation { - return nil; + return nil; } - (CGFontRef) graphicsFontWithDescriptor: (OPFontDescriptor**)descriptorOut { - return nil; + return nil; } - (NSArray*) availableTablesWithOptions: (CTFontTableOptions)options { - return nil; + return nil; } - (NSData*) tableForTag: (CTFontTableTag)tag withOptions: (CTFontTableOptions)options { - return nil; + return nil; } // @@ -298,14 +299,14 @@ - (NSData*) tableForTag: (CTFontTableTag)tag // - (NSString*) nameForGlyph: (CGGlyph)graphicsGlyph { - return nil; + return nil; } + (CTFontRef) fontWithData: (NSData*)fontData size: (CGFloat)size - matrix: (const CGFloat*)fontMatrix + matrix: (const CGFloat*)fontMatrix additionalDescriptor: (OPFontDescriptor*)descriptor { - return nil; + return nil; } @end diff --git a/Source/OpalText/OPFontDescriptor.h b/Source/OpalText/OPFontDescriptor.h index 159771d..25cd99e 100644 --- a/Source/OpalText/OPFontDescriptor.h +++ b/Source/OpalText/OPFontDescriptor.h @@ -1,4 +1,4 @@ -/* +/* OPFontDescriptor.h Holds an image to use as a cursor @@ -7,7 +7,7 @@ Author: Dr. H. Nikolaus Schaller Date: 2006 - + This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or @@ -22,10 +22,10 @@ You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. - If not, see or write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ +*/ #ifndef _GNUstep_H_OPFontDescriptor @@ -58,8 +58,9 @@ typedef enum _OPFontFamilyClass OPFontSymbolicClass = 12U << 28 } OPFontFamilyClass; -enum _OPFontFamilyClassMask { - OPFontFamilyClassMask = 0xF0000000 +enum _OPFontFamilyClassMask +{ + OPFontFamilyClassMask = 0xF0000000 }; enum _OPFontTrait @@ -78,11 +79,11 @@ enum _OPFontTrait NSString *OPFontFamilyAttribute; NSString *OPFontNameAttribute; NSString *OPFontFaceAttribute; -NSString *OPFontSizeAttribute; -NSString *OPFontVisibleNameAttribute; +NSString *OPFontSizeAttribute; +NSString *OPFontVisibleNameAttribute; NSString *OPFontColorAttribute; /** - * NOTE: OPFontMatrixAttribute is a NSAffineTransform, unlike kCTFontMatrixAttribute which + * NOTE: OPFontMatrixAttribute is a NSAffineTransform, unlike kCTFontMatrixAttribute which * is an NSData containing a CGAffineTransform struct. */ NSString *OPFontMatrixAttribute; @@ -150,7 +151,8 @@ NSString *OPFontVariationAxisNameKey; - (NSArray *) matchingFontDescriptorsWithMandatoryKeys: (NSSet *)keys; - (id) objectFromPlatformFontPatternForKey: (NSString *)attribute; -- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: (NSString*)language; +- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: + (NSString*)language; @end diff --git a/Source/OpalText/OPFontDescriptor.m b/Source/OpalText/OPFontDescriptor.m index 967f70b..dcfb3c7 100644 --- a/Source/OpalText/OPFontDescriptor.m +++ b/Source/OpalText/OPFontDescriptor.m @@ -23,10 +23,10 @@ You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. - If not, see or write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ +*/ #import #import @@ -49,26 +49,27 @@ + (Class) fontDescriptorClass + (id) fontDescriptorWithFontAttributes: (NSDictionary *)attributes { - return AUTORELEASE([[[self fontDescriptorClass] alloc] initWithFontAttributes: attributes]); + return AUTORELEASE([[[self fontDescriptorClass] alloc] initWithFontAttributes: + attributes]); } + (id) fontDescriptorWithName: (NSString *)name - matrix: (NSAffineTransform *)matrix + matrix: (NSAffineTransform *)matrix { return [self fontDescriptorWithFontAttributes: - [NSDictionary dictionaryWithObjectsAndKeys: - name, OPFontNameAttribute, - matrix, OPFontMatrixAttribute, - nil]]; + [NSDictionary dictionaryWithObjectsAndKeys: + name, OPFontNameAttribute, + matrix, OPFontMatrixAttribute, + nil]]; } + (id) fontDescriptorWithName: (NSString *)name size: (CGFloat)size { return [self fontDescriptorWithFontAttributes: - [NSDictionary dictionaryWithObjectsAndKeys: - name, OPFontNameAttribute, - [NSString stringWithFormat: @"%f", size], OPFontSizeAttribute, - nil]]; + [NSDictionary dictionaryWithObjectsAndKeys: + name, OPFontNameAttribute, + [NSString stringWithFormat: @"%f", size], OPFontSizeAttribute, + nil]]; } - (NSDictionary *) fontAttributes @@ -93,26 +94,26 @@ - (OPFontDescriptor *) fontDescriptorByAddingAttributes: - (OPFontDescriptor *) fontDescriptorWithFace: (NSString *)face { return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: face forKey: OPFontFaceAttribute]]; + [NSDictionary dictionaryWithObject: face forKey: OPFontFaceAttribute]]; } - (OPFontDescriptor *) fontDescriptorWithFamily: (NSString *)family { return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: family forKey: OPFontFamilyAttribute]]; + [NSDictionary dictionaryWithObject: family forKey: OPFontFamilyAttribute]]; } - (OPFontDescriptor *) fontDescriptorWithMatrix: (NSAffineTransform *)matrix { return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: matrix forKey: OPFontMatrixAttribute]]; + [NSDictionary dictionaryWithObject: matrix forKey: OPFontMatrixAttribute]]; } - (OPFontDescriptor *) fontDescriptorWithSize: (CGFloat)size { return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: [NSString stringWithFormat:@"%f", size] - forKey: OPFontSizeAttribute]]; + [NSDictionary dictionaryWithObject: [NSString stringWithFormat: @"%f", size] + forKey: OPFontSizeAttribute]]; } - (OPFontDescriptor *) fontDescriptorWithSymbolicTraits: @@ -123,60 +124,60 @@ - (OPFontDescriptor *) fontDescriptorWithSymbolicTraits: traits = [_attributes objectForKey: OPFontTraitsAttribute]; if (traits == nil) { - traits = [NSDictionary dictionaryWithObject: - [NSNumber numberWithUnsignedInt: symbolicTraits] - forKey: OPFontSymbolicTrait]; + traits = [NSDictionary dictionaryWithObject: + [NSNumber numberWithUnsignedInt: symbolicTraits] + forKey: OPFontSymbolicTrait]; } else { traits = AUTORELEASE([traits mutableCopy]); - [(NSMutableDictionary*)traits setObject: - [NSNumber numberWithUnsignedInt: symbolicTraits] - forKey: OPFontSymbolicTrait]; + [(NSMutableDictionary*)traits setObject: + [NSNumber numberWithUnsignedInt: symbolicTraits] + forKey: OPFontSymbolicTrait]; } return [self fontDescriptorByAddingAttributes: - [NSDictionary dictionaryWithObject: traits - forKey: OPFontTraitsAttribute]]; + [NSDictionary dictionaryWithObject: traits + forKey: OPFontTraitsAttribute]]; } - (id) initWithFontAttributes: (NSDictionary *)attributes { if ((self = [super init]) != nil) - { - if (attributes) - _attributes = [attributes copy]; - else - _attributes = [NSDictionary new]; - } + { + if (attributes) + _attributes = [attributes copy]; + else + _attributes = [NSDictionary new]; + } return self; } - (void) encodeWithCoder: (NSCoder *)aCoder { - if ([aCoder allowsKeyedCoding]) - { - [aCoder encodeObject: _attributes forKey: @"NSAttributes"]; - } + if ([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _attributes forKey: @"NSAttributes"]; + } else - { - [aCoder encodeObject: _attributes]; - } + { + [aCoder encodeObject: _attributes]; + } } - (id) initWithCoder: (NSCoder *)aDecoder { if ([aDecoder allowsKeyedCoding]) - { - _attributes = RETAIN([aDecoder decodeObjectForKey: @"NSAttributes"]); - } + { + _attributes = RETAIN([aDecoder decodeObjectForKey: @"NSAttributes"]); + } else - { - [aDecoder decodeValueOfObjCType: @encode(id) at: &_attributes]; - } + { + [aDecoder decodeValueOfObjCType: @encode(id) at: &_attributes]; + } return self; } - + - (void) dealloc; { RELEASE(_attributes); @@ -188,9 +189,9 @@ - (id) copyWithZone: (NSZone *)z OPFontDescriptor *f = [isa allocWithZone: z]; if (f != nil) - { - f->_attributes = [_attributes copyWithZone: z]; - } + { + f->_attributes = [_attributes copyWithZone: z]; + } return f; } @@ -207,13 +208,13 @@ - (OPFontDescriptor *) matchingFontDescriptorWithMandatoryKeys: (NSSet *)keys NSArray *found = [self matchingFontDescriptorsWithMandatoryKeys: keys]; if (found && ([found count] > 0)) - { - return [found objectAtIndex: 0]; - } + { + return [found objectAtIndex: 0]; + } else - { - return nil; - } + { + return nil; + } } - (NSAffineTransform *) matrix @@ -232,7 +233,8 @@ - (id) objectFromPlatformFontPatternForKey: (NSString *)attribute /** * Override in subclass */ -- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: (NSString*)language +- (id) localizedObjectFromPlatformFontPatternForKey: (NSString*)key language: + (NSString*)language { return nil; } @@ -242,20 +244,22 @@ - (id) objectForKey: (NSString *)attribute id object = [_attributes objectForKey: attribute]; if (nil == object) - { - return [self objectFromPlatformFontPatternForKey: attribute]; - } + { + return [self objectFromPlatformFontPatternForKey: attribute]; + } return object; } -- (id) localizedObjectForKey: (NSString*)attribute language: (NSString*)language +- (id) localizedObjectForKey: (NSString*)attribute language: + (NSString*)language { - id object = [self localizedObjectFromPlatformFontPatternForKey: attribute language: language]; + id object = [self localizedObjectFromPlatformFontPatternForKey: attribute + language: language]; if (nil == object) - { - return [self objectForKey: attribute]; - } + { + return [self objectForKey: attribute]; + } return object; } @@ -274,13 +278,13 @@ - (OPFontSymbolicTraits) symbolicTraits { NSDictionary *traits = [self objectForKey: OPFontTraitsAttribute]; if (traits == nil) - { - return 0; - } + { + return 0; + } else - { - return [[traits objectForKey: OPFontSymbolicTrait] unsignedIntValue]; - } + { + return [[traits objectForKey: OPFontSymbolicTrait] unsignedIntValue]; + } } @end diff --git a/Source/OpalText/OPLayoutEngine.h b/Source/OpalText/OPLayoutEngine.h index 348380f..c6c3722 100644 --- a/Source/OpalText/OPLayoutEngine.h +++ b/Source/OpalText/OPLayoutEngine.h @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalText/OPSimpleLayoutEngine.h b/Source/OpalText/OPSimpleLayoutEngine.h index 214306d..8316406 100644 --- a/Source/OpalText/OPSimpleLayoutEngine.h +++ b/Source/OpalText/OPSimpleLayoutEngine.h @@ -11,12 +11,12 @@ 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 diff --git a/Source/OpalText/OPSimpleLayoutEngine.m b/Source/OpalText/OPSimpleLayoutEngine.m index d402b7c..8927a45 100644 --- a/Source/OpalText/OPSimpleLayoutEngine.m +++ b/Source/OpalText/OPSimpleLayoutEngine.m @@ -11,12 +11,12 @@ 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 @@ -30,31 +30,31 @@ @implementation OPSimpleLayoutEngine - (CTRunRef) layoutString: (NSString*)chars - withAttributes: (NSDictionary*)attribs + withAttributes: (NSDictionary*)attribs { const NSUInteger length = [chars length]; CGGlyph *glyphs = malloc(sizeof(CGGlyph) * length); unichar *characters = malloc(sizeof(unichar) * length); CGSize *advances = malloc(sizeof(CGSize) * length); - CTFontRef font = [attribs objectForKey: kCTFontAttributeName]; + CTFontRef font = [attribs objectForKey: kCTFontAttributeName]; if (font == nil) - { - NSLog(@"OPSimpleLayoutEngine: Error, layoutString:withAttributes: called without a font"); - } + { + NSLog(@"OPSimpleLayoutEngine: Error, layoutString:withAttributes: called without a font"); + } else - { - bool success = CTFontGetGlyphsForCharacters(font, - characters, - glyphs, - length); + { + bool success = CTFontGetGlyphsForCharacters(font, + characters, + glyphs, + length); - double total = CTFontGetAdvancesForGlyphs(font, - kCTFontDefaultOrientation, - glyphs, - advances, - length); - } + double total = CTFontGetAdvancesForGlyphs(font, + kCTFontDefaultOrientation, + glyphs, + advances, + length); + } free(glyphs); free(characters); free(advances); diff --git a/Tests/arcs.m b/Tests/arcs.m index 5d25dab..59fcda8 100644 --- a/Tests/arcs.m +++ b/Tests/arcs.m @@ -1,20 +1,20 @@ /* - + File: arcs.c - + Abstract: // These are the functions that implement equivalents to the QuickDraw arc drawing APIs, // FrameArc and PaintArc. // See DrawProcs.c for sample usage - + Version: 1.0 - + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. - + In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the @@ -22,7 +22,7 @@ Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following - text and disclaimers in all such redistributions of the Apple Software. + text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except @@ -30,13 +30,13 @@ or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. - + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. - + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -45,10 +45,10 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + Copyright © 2005 Apple Computer, Inc., All Rights Reserved - - */ + + */ #define _BSD_SOURCE #include @@ -72,38 +72,41 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF void pathForArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) { - CGFloat start, end; - CGAffineTransform matrix; - - // Save the context's state because we are going to scale it - CGContextSaveGState(context); - - // Create a transform to scale the context so that a radius of 1 maps to the bounds - // of the rectangle, and transform the origin of the context to the center of - // the bounding rectangle. - matrix = CGAffineTransformMake(r.size.width/2, 0, - 0, r.size.height/2, - r.origin.x + r.size.width/2, - r.origin.y + r.size.height/2); - - // Apply the transform to the context - CGContextConcatCTM(context, matrix); - - // Calculate the start and ending angles - if (arcAngle > 0) { - start = (90 - startAngle - arcAngle) * M_PI / 180; - end = (90 - startAngle) * M_PI / 180; - } else { - start = (90 - startAngle) * M_PI / 180; - end = (90 - startAngle - arcAngle) * M_PI / 180; + CGFloat start, end; + CGAffineTransform matrix; + + // Save the context's state because we are going to scale it + CGContextSaveGState(context); + + // Create a transform to scale the context so that a radius of 1 maps to the bounds + // of the rectangle, and transform the origin of the context to the center of + // the bounding rectangle. + matrix = CGAffineTransformMake(r.size.width/2, 0, + 0, r.size.height/2, + r.origin.x + r.size.width/2, + r.origin.y + r.size.height/2); + + // Apply the transform to the context + CGContextConcatCTM(context, matrix); + + // Calculate the start and ending angles + if (arcAngle > 0) + { + start = (90 - startAngle - arcAngle) * M_PI / 180; + end = (90 - startAngle) * M_PI / 180; + } + else + { + start = (90 - startAngle) * M_PI / 180; + end = (90 - startAngle - arcAngle) * M_PI / 180; } - - // Add the Arc to the path - CGContextAddArc(context, 0, 0, 1, start, end, false); - - // Restore the context's state. This removes the translation and scaling - // but leaves the path, since the path is not part of the graphics state. - CGContextRestoreGState(context); + + // Add the Arc to the path + CGContextAddArc(context, 0, 0, 1, start, end, false); + + // Restore the context's state. This removes the translation and scaling + // but leaves the path, since the path is not part of the graphics state. + CGContextRestoreGState(context); } /* @@ -119,14 +122,14 @@ void pathForArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) void frameArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) { - // Signal the start of a path - CGContextBeginPath(context); + // Signal the start of a path + CGContextBeginPath(context); - // Add to the path the arc of the oval that fits inside the rectangle. - pathForArc(context,r,startAngle,arcAngle); - - // Stroke the path - CGContextStrokePath(context); + // Add to the path the arc of the oval that fits inside the rectangle. + pathForArc(context,r,startAngle,arcAngle); + + // Stroke the path + CGContextStrokePath(context); } /* @@ -141,18 +144,19 @@ void frameArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) void paintArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) { - // Signal the start of a path - CGContextBeginPath(context); - - // Set the start of the path to the arcs focal point - CGContextMoveToPoint(context, r.origin.x + r.size.width/2, r.origin.y + r.size.height/2); - - // Add to the path the arc of the oval that fits inside the rectangle. - pathForArc(context,r,startAngle,arcAngle); - - // Complete the path closing the arc at the focal point - CGContextClosePath(context); - - // Fill the path - CGContextFillPath(context); + // Signal the start of a path + CGContextBeginPath(context); + + // Set the start of the path to the arcs focal point + CGContextMoveToPoint(context, r.origin.x + r.size.width/2, + r.origin.y + r.size.height/2); + + // Add to the path the arc of the oval that fits inside the rectangle. + pathForArc(context,r,startAngle,arcAngle); + + // Complete the path closing the arc at the focal point + CGContextClosePath(context); + + // Fill the path + CGContextFillPath(context); } diff --git a/Tests/bitmaps.m b/Tests/bitmaps.m index 0ed273a..07a4b62 100644 --- a/Tests/bitmaps.m +++ b/Tests/bitmaps.m @@ -8,63 +8,64 @@ static void assert_close(int expected, int actual) { - assert(abs(expected - actual) < 10); + assert(abs(expected - actual) < 10); } void draw(CGContextRef ctx, CGRect rect) { - CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - - /* cairo only supports the kCGImageAlphaPremultipliedFirst format */ - CGContextRef bmp = CGBitmapContextCreate(NULL, 2, 2, 8, 8, cs, kCGImageAlphaPremultipliedLast); - CGColorSpaceRelease(cs); - - const double r = 1.0; - const double g = 0.9; - const double b = 0.8; - const double a = 0.7; - - /* fill the bottom-left pixel with a semitransparent cream pastel color */ - CGContextSetRGBFillColor(bmp, r, g, b, a); - CGContextFillRect(bmp, CGRectMake(0, 0, 1, 1)); - - { - unsigned char * bytes = CGBitmapContextGetData(bmp); - - /* top row, left column */ - assert_close(0, bytes[0]); // r * a - assert_close(0, bytes[1]); // g * a - assert_close(0, bytes[2]); // b * a - assert_close(0, bytes[3]); // a - - /* top row, right column */ - assert_close(0, bytes[4]); // r * a - assert_close(0, bytes[5]); // g * a - assert_close(0, bytes[6]); // b * a - assert_close(0, bytes[7]); // a - - /* bottom row, left column */ - assert_close(255 * r * a, bytes[8]); // r * a - assert_close(255 * g * a, bytes[9]); // g * a - assert_close(255 * b * a, bytes[10]); // b * a - assert_close(255 * a, bytes[11]); // a - - /* bottom row, right column */ - assert_close(0, bytes[12]); // r * a - assert_close(0, bytes[13]); // g * a - assert_close(0, bytes[14]); // b * a - assert_close(0, bytes[15]); // a - } - - /* fill the window background with black */ - CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); - CGContextFillRect(ctx, rect); - - CGImageRef img = CGBitmapContextCreateImage(bmp); - CGContextRelease(bmp); - - /* draw the bitmap stretched across the window */ - CGContextDrawImage(ctx, rect, img); + CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - CGImageRelease(img); + /* cairo only supports the kCGImageAlphaPremultipliedFirst format */ + CGContextRef bmp = CGBitmapContextCreate(NULL, 2, 2, 8, 8, cs, + kCGImageAlphaPremultipliedLast); + CGColorSpaceRelease(cs); + + const double r = 1.0; + const double g = 0.9; + const double b = 0.8; + const double a = 0.7; + + /* fill the bottom-left pixel with a semitransparent cream pastel color */ + CGContextSetRGBFillColor(bmp, r, g, b, a); + CGContextFillRect(bmp, CGRectMake(0, 0, 1, 1)); + + { + unsigned char * bytes = CGBitmapContextGetData(bmp); + + /* top row, left column */ + assert_close(0, bytes[0]); // r * a + assert_close(0, bytes[1]); // g * a + assert_close(0, bytes[2]); // b * a + assert_close(0, bytes[3]); // a + + /* top row, right column */ + assert_close(0, bytes[4]); // r * a + assert_close(0, bytes[5]); // g * a + assert_close(0, bytes[6]); // b * a + assert_close(0, bytes[7]); // a + + /* bottom row, left column */ + assert_close(255 * r * a, bytes[8]); // r * a + assert_close(255 * g * a, bytes[9]); // g * a + assert_close(255 * b * a, bytes[10]); // b * a + assert_close(255 * a, bytes[11]); // a + + /* bottom row, right column */ + assert_close(0, bytes[12]); // r * a + assert_close(0, bytes[13]); // g * a + assert_close(0, bytes[14]); // b * a + assert_close(0, bytes[15]); // a + } + + /* fill the window background with black */ + CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); + CGContextFillRect(ctx, rect); + + CGImageRef img = CGBitmapContextCreateImage(bmp); + CGContextRelease(bmp); + + /* draw the bitmap stretched across the window */ + CGContextDrawImage(ctx, rect, img); + + CGImageRelease(img); } diff --git a/Tests/cocoa.m b/Tests/cocoa.m index b3d2492..7798ccf 100644 --- a/Tests/cocoa.m +++ b/Tests/cocoa.m @@ -7,7 +7,8 @@ @interface MyView : NSView @implementation MyView - (void)drawRect: (NSRect)rect { - CGRect r = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); + CGRect r = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, + rect.size.height); draw([[NSGraphicsContext currentContext] graphicsPort], r); } @end @@ -25,9 +26,9 @@ - (void) applicationDidFinishLaunching: (id)notif { NSRect r = NSMakeRect(0,0,640,480); win = [[NSWindow alloc] initWithContentRect: r - styleMask:NSResizableWindowMask | NSTitledWindowMask | NSClosableWindowMask - backing:NSBackingStoreBuffered - defer:NO]; + styleMask: NSResizableWindowMask | NSTitledWindowMask | NSClosableWindowMask + backing: NSBackingStoreBuffered + defer: NO]; view = [[MyView alloc] initWithFrame: r]; [win setContentView: view]; [win makeKeyAndOrderFront: nil]; diff --git a/Tests/colorspace.m b/Tests/colorspace.m index 3ee2420..bc3febd 100644 --- a/Tests/colorspace.m +++ b/Tests/colorspace.m @@ -11,13 +11,13 @@ void draw(CGContextRef ctx, CGRect rect) CGContextScaleCTM(ctx, rect.size.width, rect.size.height); CGColorSpaceRef AdobeRGB, sRGB; - + AdobeRGB = CGColorSpaceCreateWithName(kCGColorSpaceAdobeRGB1998); sRGB = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); const CGFloat full[4] = {0.0, 1.0, 0.0, 1.0}; const CGFloat partial[4] = {0.0, 0.75, 0.0, 1.0}; - + CGColorRef adobe1, adobe2, srgb1, srgb2; adobe1 = CGColorCreate(AdobeRGB, full); adobe2 = CGColorCreate(AdobeRGB, partial); @@ -27,13 +27,13 @@ void draw(CGContextRef ctx, CGRect rect) /* AdobeRGB 100% green | sRGB 100% green --------------------+---------------- AdobeRGB 75% green | sRGB 75% green */ - + CGContextSetFillColorWithColor(ctx, adobe1); CGContextFillRect(ctx, CGRectMake(0, 0.5, 0.5, 0.5)); CGContextSetFillColorWithColor(ctx, srgb1); CGContextFillRect(ctx, CGRectMake(0.5, 0.5, 0.5, 0.5)); - CGContextSetFillColorWithColor(ctx, adobe2); + CGContextSetFillColorWithColor(ctx, adobe2); CGContextFillRect(ctx, CGRectMake(0, 0, 0.5, 0.5)); CGContextSetFillColorWithColor(ctx, srgb2); CGContextFillRect(ctx, CGRectMake(0.5, 0, 0.5, 0.5)); diff --git a/Tests/doublebuffer.m b/Tests/doublebuffer.m index b0d5381..db4bb6c 100644 --- a/Tests/doublebuffer.m +++ b/Tests/doublebuffer.m @@ -8,7 +8,7 @@ /* Taken from GSQuartzCore's CABackingStore */ static CGContextRef createCGBitmapContext(int pixelsWide, - int pixelsHigh) + int pixelsHigh) { CGContextRef context = NULL; CGColorSpaceRef colorSpace; @@ -52,17 +52,17 @@ void draw_red(CGContextRef ctx, CGRect rect) CGContextSetRGBFillColor(ctx, r, g, b, a); CGContextFillRect(ctx, rect); -} +} void draw(CGContextRef ctx, CGRect rect) { CGContextRef ctx1 = createCGBitmapContext(rect.size.width, - rect.size.height); + rect.size.height); draw_red(ctx1, rect); CGImageRef backingImage = CGBitmapContextCreateImage(ctx1); CGContextDrawImage(ctx, rect, backingImage); -} +} diff --git a/Tests/gradients.m b/Tests/gradients.m index df1d1ab..e5f30fb 100644 --- a/Tests/gradients.m +++ b/Tests/gradients.m @@ -11,36 +11,37 @@ void draw(CGContextRef ctx, CGRect rect) { CGContextScaleCTM(ctx, rect.size.width, rect.size.height); - -CGGradientRef myGradient; -CGColorSpaceRef myColorspace; -size_t num_locations = 2; -CGFloat locations[2] = { 0.0, 1.0 }; -CGFloat components[8] = { 1.0, 0.5, 0.4, 1.0, // Start color - 0.8, 0.8, 0.3, 1.0 }; // End color - -myColorspace = CGColorSpaceCreateDeviceRGB(); -myGradient = CGGradientCreateWithColorComponents (myColorspace, components, - locations, num_locations); + CGGradientRef myGradient; + CGColorSpaceRef myColorspace; + size_t num_locations = 2; + CGFloat locations[2] = { 0.0, 1.0 }; + CGFloat components[8] = { 1.0, 0.5, 0.4, 1.0, // Start color + 0.8, 0.8, 0.3, 1.0 + }; // End color -CGPoint myStartPoint, myEndPoint; -CGFloat myStartRadius, myEndRadius; -myStartPoint.x = 0.15; -myStartPoint.y = 0.15; -myEndPoint.x = 0.5; -myEndPoint.y = 0.5; -myStartRadius = 0.1; -myEndRadius = 0.25; -CGContextDrawRadialGradient (ctx, myGradient, myStartPoint, - myStartRadius, myEndPoint, myEndRadius, - kCGGradientDrawsAfterEndLocation); -{ -CGPoint myStartPoint, myEndPoint; -myStartPoint.x = 0.0; -myStartPoint.y = 0.0; -myEndPoint.x = 1.0; -myEndPoint.y = 1.0; -CGContextDrawLinearGradient (ctx, myGradient, myStartPoint, myEndPoint, 0); -} + myColorspace = CGColorSpaceCreateDeviceRGB(); + myGradient = CGGradientCreateWithColorComponents (myColorspace, components, + locations, num_locations); + + + CGPoint myStartPoint, myEndPoint; + CGFloat myStartRadius, myEndRadius; + myStartPoint.x = 0.15; + myStartPoint.y = 0.15; + myEndPoint.x = 0.5; + myEndPoint.y = 0.5; + myStartRadius = 0.1; + myEndRadius = 0.25; + CGContextDrawRadialGradient (ctx, myGradient, myStartPoint, + myStartRadius, myEndPoint, myEndRadius, + kCGGradientDrawsAfterEndLocation); + { + CGPoint myStartPoint, myEndPoint; + myStartPoint.x = 0.0; + myStartPoint.y = 0.0; + myEndPoint.x = 1.0; + myEndPoint.y = 1.0; + CGContextDrawLinearGradient (ctx, myGradient, myStartPoint, myEndPoint, 0); + } } diff --git a/Tests/gstate.m b/Tests/gstate.m index 3674bb8..dbad816 100644 --- a/Tests/gstate.m +++ b/Tests/gstate.m @@ -14,9 +14,9 @@ NSString * affineTransformRepr(CGAffineTransform at) { return [NSString stringWithFormat: @"((%g %g), (%g %g), (%g %g))", - at.a, at.b, - at.c, at.d, - at.tx, at.ty]; + at.a, at.b, + at.c, at.d, + at.tx, at.ty]; } void draw(CGContextRef ctx, CGRect rect) @@ -50,10 +50,12 @@ void draw(CGContextRef ctx, CGRect rect) } else { - NSLog(@"- CTM differs from CGAffineTransformIdentity - is %@", affineTransformRepr(ctm)); + NSLog(@"- CTM differs from CGAffineTransformIdentity - is %@", + affineTransformRepr(ctm)); } - CGAffineTransform matrix1 = { + CGAffineTransform matrix1 = + { .a = 1.0, .b = 0.0, .c = 0.0, .d = 1.0, .tx = 2.0, .ty = 3.0 @@ -66,10 +68,12 @@ void draw(CGContextRef ctx, CGRect rect) } else { - NSLog(@"- Concatenating matrix1 failed - expected %@, got %@", affineTransformRepr(matrix1), affineTransformRepr(ctm)); + NSLog(@"- Concatenating matrix1 failed - expected %@, got %@", + affineTransformRepr(matrix1), affineTransformRepr(ctm)); } - - CGAffineTransform matrix2 = { + + CGAffineTransform matrix2 = + { .a = 2.0, .b = 0.0, .c = 0.0, .d = 2.0, .tx = 2.0, .ty = 3.0 @@ -83,7 +87,8 @@ void draw(CGContextRef ctx, CGRect rect) } else { - NSLog(@"- Concatenating matrix2 failed - expected %@, got %@", affineTransformRepr(matrix2), affineTransformRepr(ctm)); + NSLog(@"- Concatenating matrix2 failed - expected %@, got %@", + affineTransformRepr(matrix2), affineTransformRepr(ctm)); } CGContextRestoreGState(ctx); @@ -95,7 +100,8 @@ void draw(CGContextRef ctx, CGRect rect) } else { - NSLog(@"- CTM not the same as before - expected %@, got %@", affineTransformRepr(oldctm), affineTransformRepr(ctm)); + NSLog(@"- CTM not the same as before - expected %@, got %@", + affineTransformRepr(oldctm), affineTransformRepr(ctm)); } } #else diff --git a/Tests/images.m b/Tests/images.m index adcff9b..91910ba 100644 --- a/Tests/images.m +++ b/Tests/images.m @@ -17,70 +17,78 @@ void draw(CGContextRef ctx, CGRect rect) { CGContextSetRGBFillColor(ctx, 0.45, 0.45, 0.45, 1.0); CGContextFillRect(ctx, rect); - + // Draw a checkerboard CGContextSetRGBFillColor(ctx, 0.4, 0.4, 0.4, 1.0); - unsigned int x, y; - for (x=0; x @@ -58,8 +58,8 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #else #include #endif - - /* + +/* addOvalToPath : Adds to the context a path for an oval just inside the bounding rectangle that you specify. Parameter Descriptions @@ -69,38 +69,38 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF void addOvalToPath(CGContextRef context, CGRect r) { - CGAffineTransform matrix; - - // Save the context's state because we are going to transform and scale it - CGContextSaveGState(context); - - // Create a transform to scale the context so that a radius of 1 - // is equal to the bounds of the rectangle, and transform the origin - // of the context to the center of the bounding rectangle. The - // center of the bounding rectangle will now be the center of - // the oval. - matrix = CGAffineTransformMake((r.size.width)/2, 0, - 0, (r.size.height)/2, - r.origin.x + (r.size.width)/2, - r.origin.y + (r.size.height)/2); - - // Apply the transform to the context - CGContextConcatCTM(context, matrix); - - // Signal the start of a path - CGContextBeginPath(context); - - // Add a circle to the path. After the circle is transformed by the - // context's transformation matrix, it will become an oval lying - // just inside the bounding rectangle. - CGContextAddArc(context, 0, 0, 1, 0, 2*M_PI, 0); - - // Restore the context's state. This removes the translation and scaling but leaves - // the path, since the path is not part of the graphics state. - CGContextRestoreGState(context); + CGAffineTransform matrix; + + // Save the context's state because we are going to transform and scale it + CGContextSaveGState(context); + + // Create a transform to scale the context so that a radius of 1 + // is equal to the bounds of the rectangle, and transform the origin + // of the context to the center of the bounding rectangle. The + // center of the bounding rectangle will now be the center of + // the oval. + matrix = CGAffineTransformMake((r.size.width)/2, 0, + 0, (r.size.height)/2, + r.origin.x + (r.size.width)/2, + r.origin.y + (r.size.height)/2); + + // Apply the transform to the context + CGContextConcatCTM(context, matrix); + + // Signal the start of a path + CGContextBeginPath(context); + + // Add a circle to the path. After the circle is transformed by the + // context's transformation matrix, it will become an oval lying + // just inside the bounding rectangle. + CGContextAddArc(context, 0, 0, 1, 0, 2*M_PI, 0); + + // Restore the context's state. This removes the translation and scaling but leaves + // the path, since the path is not part of the graphics state. + CGContextRestoreGState(context); } - + /* paintOval : Paints the interior of an oval just inside the bounding rectangle that you specify. @@ -111,11 +111,11 @@ void addOvalToPath(CGContextRef context, CGRect r) void paintOval(CGContextRef context, CGRect r) { - // Add a path for the oval to this context - addOvalToPath(context,r); + // Add a path for the oval to this context + addOvalToPath(context,r); - // Fill the oval - CGContextFillPath(context); + // Fill the oval + CGContextFillPath(context); } /* @@ -127,9 +127,9 @@ void paintOval(CGContextRef context, CGRect r) */ void frameOval(CGContextRef context, CGRect r) { - // Add a path for the oval to this context - addOvalToPath(context,r); + // Add a path for the oval to this context + addOvalToPath(context,r); - // Stroke the path - CGContextStrokePath(context); + // Stroke the path + CGContextStrokePath(context); } diff --git a/Tests/pdf.m b/Tests/pdf.m index 1d09ffa..a791d82 100644 --- a/Tests/pdf.m +++ b/Tests/pdf.m @@ -7,111 +7,117 @@ #define pi 3.14159265358979323846 -extern void frameArc(CGContextRef context, CGRect r, int startAngle, int arcAngle); -extern void paintArc(CGContextRef context, CGRect r, int startAngle, int arcAngle); +extern void frameArc(CGContextRef context, CGRect r, int startAngle, + int arcAngle); +extern void paintArc(CGContextRef context, CGRect r, int startAngle, + int arcAngle); extern void frameOval(CGContextRef context, CGRect r); extern void paintOval(CGContextRef context, CGRect r); extern void frameRect(CGContextRef context, CGRect r); extern void paintRect(CGContextRef context, CGRect r); -extern void fillRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFloat ovalHeight); -extern void strokeRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFloat ovalHeight); +extern void fillRoundedRect(CGContextRef context, CGRect rect, + CGFloat ovalWidth, CGFloat ovalHeight); +extern void strokeRoundedRect(CGContextRef context, CGRect rect, + CGFloat ovalWidth, CGFloat ovalHeight); void drawRect(CGContextRef ctx, CGRect r) { - CGRect bounds = r; - double a, b; - int count, k; + CGRect bounds = r; + double a, b; + int count, k; CGContextTranslateCTM(ctx, r.origin.x, r.origin.y); - CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); - CGContextFillRect(ctx, CGRectMake(0, r.size.height / 2, r.size.width, r.size.height / 2)); + CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); + CGContextFillRect(ctx, CGRectMake(0, r.size.height / 2, r.size.width, + r.size.height / 2)); - // Use a transparency layer for the first shape + // Use a transparency layer for the first shape - CGContextSetAlpha(ctx, 0.5); - CGContextBeginTransparencyLayer(ctx, NULL); + CGContextSetAlpha(ctx, 0.5); + CGContextBeginTransparencyLayer(ctx, NULL); - // Calculate the dimensions for an oval inside the bounding box - a = 0.9 * bounds.size.width/4; - b = 0.3 * bounds.size.height/2; - count = 5; + // Calculate the dimensions for an oval inside the bounding box + a = 0.9 * bounds.size.width/4; + b = 0.3 * bounds.size.height/2; + count = 5; - // Set the fill color to a partially transparent blue - CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); + // Set the fill color to a partially transparent blue + CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); - // Set the stroke color to an opaque black - CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); + // Set the stroke color to an opaque black + CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); - // Set the line width to be used, in user space units. - CGContextSetLineWidth(ctx, 3); + // Set the line width to be used, in user space units. + CGContextSetLineWidth(ctx, 3); - // Save the conexts state because we are going to be moving the origin and - // rotating context for drawing, but we would like to restore the current - // state before drawing the next image. - CGContextSaveGState(ctx); + // Save the conexts state because we are going to be moving the origin and + // rotating context for drawing, but we would like to restore the current + // state before drawing the next image. + CGContextSaveGState(ctx); - // Move the origin to the middle of the first image (left side) to draw. - CGContextTranslateCTM(ctx, bounds.size.width/4, bounds.size.height/2); + // Move the origin to the middle of the first image (left side) to draw. + CGContextTranslateCTM(ctx, bounds.size.width/4, bounds.size.height/2); - // Draw "count" ovals, rotating the context around the newly translated origin - // 1/count radians after drawing each oval - for (k = 0; k < count; k++) - { - // Paint the oval with the fill color - paintOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); + // Draw "count" ovals, rotating the context around the newly translated origin + // 1/count radians after drawing each oval + for (k = 0; k < count; k++) + { + // Paint the oval with the fill color + paintOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); - // Frame the oval with the stroke color - frameOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); + // Frame the oval with the stroke color + frameOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); - // Rotate the context around the center of the image - CGContextRotateCTM(ctx, pi / count); - } - // Restore the saved state to a known state for dawing the next image - CGContextRestoreGState(ctx); + // Rotate the context around the center of the image + CGContextRotateCTM(ctx, pi / count); + } + // Restore the saved state to a known state for dawing the next image + CGContextRestoreGState(ctx); - // End the transparency layer - CGContextEndTransparencyLayer(ctx); + // End the transparency layer + CGContextEndTransparencyLayer(ctx); - // Calculate a bounding box for the rounded rect - a = 0.9 * bounds.size.width/4; - b = 0.3 * bounds.size.height/2; - count = 5; + // Calculate a bounding box for the rounded rect + a = 0.9 * bounds.size.width/4; + b = 0.3 * bounds.size.height/2; + count = 5; - // Set the fill color to a partially transparent red - CGContextSetRGBFillColor(ctx, 1, 0, 0, 0.5); + // Set the fill color to a partially transparent red + CGContextSetRGBFillColor(ctx, 1, 0, 0, 0.5); - // Set the stroke color to an opaque black - CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); + // Set the stroke color to an opaque black + CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); - // Set the line width to be used, in user space units. - CGContextSetLineWidth(ctx, 3); + // Set the line width to be used, in user space units. + CGContextSetLineWidth(ctx, 3); - // Save the conexts state because we are going to be moving the origin and - // rotating context for drawing, but we would like to restore the current - // state before drawing the next image. - CGContextSaveGState(ctx); + // Save the conexts state because we are going to be moving the origin and + // rotating context for drawing, but we would like to restore the current + // state before drawing the next image. + CGContextSaveGState(ctx); - // Move the origin to the middle of the second image (right side) to draw. - CGContextTranslateCTM(ctx, bounds.size.width/4 + bounds.size.width/2, bounds.size.height/2); + // Move the origin to the middle of the second image (right side) to draw. + CGContextTranslateCTM(ctx, bounds.size.width/4 + bounds.size.width/2, + bounds.size.height/2); - for (k = 0; k < count; k++) - { - // Fill then stroke the rounding rect, otherwise the fill would cover the stroke - fillRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); - strokeRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); - // Rotate the context for the next rounded rect - CGContextRotateCTM(ctx, pi / count); - } - CGContextRestoreGState(ctx); + for (k = 0; k < count; k++) + { + // Fill then stroke the rounding rect, otherwise the fill would cover the stroke + fillRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); + strokeRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); + // Rotate the context for the next rounded rect + CGContextRotateCTM(ctx, pi / count); + } + CGContextRestoreGState(ctx); } int main(int argc, char **argv) { [NSAutoreleasePool new]; CFURLRef url = [NSURL fileURLWithPath: @"test.pdf"]; - + CGContextRef ctx = CGPDFContextCreateWithURL(url, NULL, NULL); drawRect(ctx, CGRectMake(0, 2.25*72, 8.5*72, 5.5*72)); CGPDFContextClose(ctx); diff --git a/Tests/qeb2-draw.m b/Tests/qeb2-draw.m index bb78292..dff0932 100644 --- a/Tests/qeb2-draw.m +++ b/Tests/qeb2-draw.m @@ -1,12 +1,12 @@ /* File: myDraw.m - + Description: Quartz 2D early bird sample from WWDC 2001 Author: DH Copyright: © Copyright 2000 Apple Computer, Inc. All rights reserved. - + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software @@ -41,7 +41,7 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + Change History (most recent first): */ @@ -53,7 +53,7 @@ Change History (most recent first): * Copyright (c) 2001 Apple Computer, Inc. All rights reserved. * */ - + #ifdef __APPLE__ #include #else @@ -67,110 +67,126 @@ Change History (most recent first): * myDraw is called whenever the view is updated. * context - CG context to draw into * windowRect - rectangle defining the window rectangle - */ + */ void drawRandomPaths(CGContextRef context, int w, int h) { - int i; - for (i = 0; i < 20; i++) { - int numberOfSegments = rand() % 8; - int j; - CGFloat sx, sy; - - CGContextBeginPath(context); - sx = rand()%w; sy = rand()%h; - CGContextMoveToPoint(context, rand()%w, rand()%h); - for (j = 0; j < numberOfSegments; j++) { - if (j % 2) { - CGContextAddLineToPoint(context, rand()%w, rand()%h); + int i; + for (i = 0; i < 20; i++) + { + int numberOfSegments = rand() % 8; + int j; + CGFloat sx, sy; + + CGContextBeginPath(context); + sx = rand()%w; + sy = rand()%h; + CGContextMoveToPoint(context, rand()%w, rand()%h); + for (j = 0; j < numberOfSegments; j++) + { + if (j % 2) + { + CGContextAddLineToPoint(context, rand()%w, rand()%h); } - else { - CGContextAddCurveToPoint(context, rand()%w, rand()%h, - rand()%w, rand()%h, rand()%h, rand()%h); + else + { + CGContextAddCurveToPoint(context, rand()%w, rand()%h, + rand()%w, rand()%h, rand()%h, rand()%h); } } - if(i % 2) { - CGContextAddCurveToPoint(context, rand()%w, rand()%h, - rand()%w, rand()%h, sx, sy); - CGContextClosePath(context); - CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); - CGContextFillPath(context); + if (i % 2) + { + CGContextAddCurveToPoint(context, rand()%w, rand()%h, + rand()%w, rand()%h, sx, sy); + CGContextClosePath(context); + CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); + CGContextFillPath(context); } - else { - CGContextSetLineWidth(context, (rand()%10)+2); - CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); - CGContextStrokePath(context); + else + { + CGContextSetLineWidth(context, (rand()%10)+2); + CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); + CGContextStrokePath(context); } } } void draw(CGContextRef context, CGRect contextRect) { - int i; - int w, h; - static int n = 0; - - w = contextRect.size.width; - h = contextRect.size.height; - - switch (n) { - case 0: + int i; + int w, h; + static int n = 0; + + w = contextRect.size.width; + h = contextRect.size.height; + + switch (n) + { + case 0: // Draw random rectangles (some stroked some filled) - for (i = 0; i < 20; i++) { - if(i % 2) { - CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); + for (i = 0; i < 20; i++) + { + if (i % 2) + { + CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); CGContextFillRect(context, CGRectMake(rand()%w, rand()%h, rand()%w, rand()%h)); - } - else { + } + else + { CGContextSetLineWidth(context, (rand()%10)+2); - CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); - CGContextStrokeRect(context, CGRectMake(rand()%w, rand()%h, rand()%w, rand()%h)); - } - } + CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); + CGContextStrokeRect(context, CGRectMake(rand()%w, rand()%h, rand()%w, + rand()%h)); + } + } break; - case 1: + case 1: // Draw random circles (some stroked, some filled) - for (i = 0; i < 20; i++) { + for (i = 0; i < 20; i++) + { CGContextBeginPath(context); - CGContextAddArc(context, rand()%w, rand()%h, rand()%((w>h) ? h : w), 0, 2*PI, 0); + CGContextAddArc(context, rand()%w, rand()%h, rand()%((w>h) ? h : w), 0, 2*PI, + 0); CGContextClosePath(context); - if(i % 2) { - CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); + if (i % 2) + { + CGContextSetRGBFillColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); CGContextFillPath(context); - } - else { + } + else + { CGContextSetLineWidth(context, (rand()%10)+2); - CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, - (CGFloat)(rand()%256)/255); + CGContextSetRGBStrokeColor(context, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255, (CGFloat)(rand()%256)/255, + (CGFloat)(rand()%256)/255); CGContextStrokePath(context); - } - } + } + } break; - case 2: + case 2: drawRandomPaths(context, w, h); break; - case 3: + case 3: /* Clipping example - draw random path through a circular clip */ CGContextBeginPath(context); CGContextAddArc(context, w/2, h/2, ((w>h) ? h : w)/2, 0, 2*PI, 0); CGContextClosePath(context); CGContextClip(context); - + // Draw something into the clip drawRandomPaths(context, w, h); - + // Draw an clip path on top as a black stroked circle. CGContextBeginPath(context); CGContextAddArc(context, w/2, h/2, ((w>h) ? h : w)/2, 0, 2*PI, 0); @@ -179,10 +195,10 @@ void draw(CGContextRef context, CGRect contextRect) CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); CGContextStrokePath(context); break; - - default: + + default: break; } - - n = ((n+1) % kNumOfExamples); + + n = ((n+1) % kNumOfExamples); } diff --git a/Tests/rects.m b/Tests/rects.m index 4169037..e2eae9b 100644 --- a/Tests/rects.m +++ b/Tests/rects.m @@ -1,20 +1,20 @@ /* - + File: rects.c - + Abstract: // These are the functions that implement equivalents to the QuickDraw rect, // drawing APIs, FrameRect, PaintRect. // See DrawProcs.c for sample usage - + Version: 1.0 - + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. - + In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the @@ -22,7 +22,7 @@ Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following - text and disclaimers in all such redistributions of the Apple Software. + text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except @@ -30,13 +30,13 @@ or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. - + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. - + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS @@ -45,10 +45,10 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + Copyright � 2005 Apple Computer, Inc., All Rights Reserved - - */ + + */ #ifdef __APPLE__ #include @@ -64,8 +64,8 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF r : The CG rectangle that defines the rectangle's boundary. */ void frameRect(CGContextRef context, CGRect r) -{ - CGContextStrokeRect(context, r); +{ + CGContextStrokeRect(context, r); } /* @@ -77,7 +77,7 @@ void frameRect(CGContextRef context, CGRect r) */ void paintRect(CGContextRef context, CGRect r) { - CGContextFillRect(context, r); + CGContextFillRect(context, r); } /* @@ -90,46 +90,48 @@ void paintRect(CGContextRef context, CGRect r) context : The CG context to render to. */ -static void addRoundedRectToPath(CGContextRef context, CGRect rect, CGFloat ovalWidth, - CGFloat ovalHeight) +static void addRoundedRectToPath(CGContextRef context, CGRect rect, + CGFloat ovalWidth, + CGFloat ovalHeight) { - CGFloat fw, fh; - // If the width or height of the corner oval is zero, then it reduces to a right angle, - // so instead of a rounded rectangle we have an ordinary one. - if (ovalWidth == 0 || ovalHeight == 0) { - CGContextAddRect(context, rect); - return; - } - - // Save the context's state so that the translate and scale can be undone with a call - // to CGContextRestoreGState. - CGContextSaveGState(context); - - // Translate the origin of the contex to the lower left corner of the rectangle. - CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); - - //Normalize the scale of the context so that the width and height of the arcs are 1.0 - CGContextScaleCTM(context, ovalWidth, ovalHeight); - - // Calculate the width and height of the rectangle in the new coordinate system. - fw = CGRectGetWidth(rect) / ovalWidth; - fh = CGRectGetHeight(rect) / ovalHeight; - - // CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded - // corners). It also adds a line from the path's last point to the begining of the arc, making - // the sides of the rectangle. - CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner - CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner - CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner - CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner - CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right - - // Close the path - CGContextClosePath(context); - - // Restore the context's state. This removes the translation and scaling - // but leaves the path, since the path is not part of the graphics state. - CGContextRestoreGState(context); + CGFloat fw, fh; + // If the width or height of the corner oval is zero, then it reduces to a right angle, + // so instead of a rounded rectangle we have an ordinary one. + if (ovalWidth == 0 || ovalHeight == 0) + { + CGContextAddRect(context, rect); + return; + } + + // Save the context's state so that the translate and scale can be undone with a call + // to CGContextRestoreGState. + CGContextSaveGState(context); + + // Translate the origin of the contex to the lower left corner of the rectangle. + CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); + + //Normalize the scale of the context so that the width and height of the arcs are 1.0 + CGContextScaleCTM(context, ovalWidth, ovalHeight); + + // Calculate the width and height of the rectangle in the new coordinate system. + fw = CGRectGetWidth(rect) / ovalWidth; + fh = CGRectGetHeight(rect) / ovalHeight; + + // CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded + // corners). It also adds a line from the path's last point to the begining of the arc, making + // the sides of the rectangle. + CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner + CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner + CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner + CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner + CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right + + // Close the path + CGContextClosePath(context); + + // Restore the context's state. This removes the translation and scaling + // but leaves the path, since the path is not part of the graphics state. + CGContextRestoreGState(context); } /* @@ -141,15 +143,16 @@ static void addRoundedRectToPath(CGContextRef context, CGRect rect, CGFloat oval ovalHeight : The height of the CG rectangle that encloses the rounded corners context : The CG context to render to. */ -void fillRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFloat - ovalHeight) +void fillRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, + CGFloat + ovalHeight) { - // Signal the start of a path - CGContextBeginPath(context); - // Add a rounded rect to the path - addRoundedRectToPath(context, rect, ovalWidth, ovalHeight); - // Fill the path - CGContextFillPath(context); + // Signal the start of a path + CGContextBeginPath(context); + // Add a rounded rect to the path + addRoundedRectToPath(context, rect, ovalWidth, ovalHeight); + // Fill the path + CGContextFillPath(context); } @@ -163,13 +166,13 @@ void fillRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFlo context : The CG context to render to. */ void strokeRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, - CGFloat ovalHeight) + CGFloat ovalHeight) { - - // Signal the start of a path - CGContextBeginPath(context); - // Add a rounded rect to the path - addRoundedRectToPath(context, rect, ovalWidth, ovalHeight); - // Stroke the path - CGContextStrokePath(context); + + // Signal the start of a path + CGContextBeginPath(context); + // Add a rounded rect to the path + addRoundedRectToPath(context, rect, ovalWidth, ovalHeight); + // Stroke the path + CGContextStrokePath(context); } diff --git a/Tests/shadows.m b/Tests/shadows.m index f61d820..c7428ab 100644 --- a/Tests/shadows.m +++ b/Tests/shadows.m @@ -10,9 +10,11 @@ void draw(CGContextRef ctx, CGRect r) { CGContextSetRGBFillColor(ctx, 0, 0, 1, 0.5); CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); - CGContextFillRect(ctx, CGRectMake(10,10,r.size.width - 20, r.size.height - 20)); - CGContextStrokeRect(ctx, CGRectMake(10,10,r.size.width - 20, r.size.height - 20)); - + CGContextFillRect(ctx, CGRectMake(10,10,r.size.width - 20, + r.size.height - 20)); + CGContextStrokeRect(ctx, CGRectMake(10,10,r.size.width - 20, + r.size.height - 20)); + CGContextSetShadow(ctx, CGSizeMake(3.0,3.0), 2.0); // Draw some rotated, shadowed squares @@ -20,12 +22,13 @@ void draw(CGContextRef ctx, CGRect r) CGContextSaveGState(ctx); CGContextTranslateCTM(ctx, 225, 125); int i; - for (i = 0; i < 2; i++) { - CGContextRotateCTM(ctx, 0.4); - CGContextFillRect(ctx, CGRectMake(-50,-50,100,100)); - } + for (i = 0; i < 2; i++) + { + CGContextRotateCTM(ctx, 0.4); + CGContextFillRect(ctx, CGRectMake(-50,-50,100,100)); + } CGContextRestoreGState(ctx); - + CGContextSetRGBFillColor(ctx, 1, 0, 0.5, 1); CGContextFillRect(ctx, CGRectMake(10, 200, 50, 15)); CGContextFillRect(ctx, CGRectMake(10, 10, 15, 75)); diff --git a/Tests/shapes.m b/Tests/shapes.m index 289d226..324f6c9 100644 --- a/Tests/shapes.m +++ b/Tests/shapes.m @@ -5,107 +5,113 @@ #endif #define pi 3.14159265358979323846 -extern void frameArc(CGContextRef context, CGRect r, int startAngle, int arcAngle); -extern void paintArc(CGContextRef context, CGRect r, int startAngle, int arcAngle); +extern void frameArc(CGContextRef context, CGRect r, int startAngle, + int arcAngle); +extern void paintArc(CGContextRef context, CGRect r, int startAngle, + int arcAngle); extern void frameOval(CGContextRef context, CGRect r); extern void paintOval(CGContextRef context, CGRect r); extern void frameRect(CGContextRef context, CGRect r); extern void paintRect(CGContextRef context, CGRect r); -extern void fillRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFloat ovalHeight); -extern void strokeRoundedRect(CGContextRef context, CGRect rect, CGFloat ovalWidth, CGFloat ovalHeight); +extern void fillRoundedRect(CGContextRef context, CGRect rect, + CGFloat ovalWidth, CGFloat ovalHeight); +extern void strokeRoundedRect(CGContextRef context, CGRect rect, + CGFloat ovalWidth, CGFloat ovalHeight); void draw(CGContextRef ctx, CGRect r) { - CGRect bounds = r; - double a, b; - int count, k; + CGRect bounds = r; + double a, b; + int count, k; - CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); - CGContextFillRect(ctx, CGRectMake(0, r.size.height / 2, r.size.width, r.size.height / 2)); + CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); + CGContextFillRect(ctx, CGRectMake(0, r.size.height / 2, r.size.width, + r.size.height / 2)); - // Use a transparency layer for the first shape + // Use a transparency layer for the first shape - CGContextSetAlpha(ctx, 0.5); - CGContextBeginTransparencyLayer(ctx, NULL); + CGContextSetAlpha(ctx, 0.5); + CGContextBeginTransparencyLayer(ctx, NULL); - // Calculate the dimensions for an oval inside the bounding box - a = 0.9 * bounds.size.width/4; - b = 0.3 * bounds.size.height/2; - count = 5; + // Calculate the dimensions for an oval inside the bounding box + a = 0.9 * bounds.size.width/4; + b = 0.3 * bounds.size.height/2; + count = 5; - // Set the fill color to a partially transparent blue - CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); + // Set the fill color to a partially transparent blue + CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); - // Set the stroke color to an opaque black - CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); + // Set the stroke color to an opaque black + CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); - // Set the line width to be used, in user space units. - CGContextSetLineWidth(ctx, 3); + // Set the line width to be used, in user space units. + CGContextSetLineWidth(ctx, 3); - // Save the conexts state because we are going to be moving the origin and - // rotating context for drawing, but we would like to restore the current - // state before drawing the next image. - CGContextSaveGState(ctx); + // Save the conexts state because we are going to be moving the origin and + // rotating context for drawing, but we would like to restore the current + // state before drawing the next image. + CGContextSaveGState(ctx); - // Move the origin to the middle of the first image (left side) to draw. - CGContextTranslateCTM(ctx, bounds.size.width/4, bounds.size.height/2); + // Move the origin to the middle of the first image (left side) to draw. + CGContextTranslateCTM(ctx, bounds.size.width/4, bounds.size.height/2); CGColorRef shadowColor = CGColorCreateGenericRGB(0, 0.2, 0.3, 0.75); - - // Draw "count" ovals, rotating the context around the newly translated origin - // 1/count radians after drawing each oval - for (k = 0; k < count; k++) - { - CGContextSaveGState(ctx); - CGContextSetShadowWithColor(ctx, CGSizeMake(6.0,-6.0), 2.0, shadowColor); - // Paint the oval with the fill color - paintOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); - CGContextRestoreGState(ctx); - - // Frame the oval with the stroke color - frameOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); - - // Rotate the context around the center of the image - CGContextRotateCTM(ctx, pi / count); - } - // Restore the saved state to a known state for dawing the next image - CGContextRestoreGState(ctx); + + // Draw "count" ovals, rotating the context around the newly translated origin + // 1/count radians after drawing each oval + for (k = 0; k < count; k++) + { + CGContextSaveGState(ctx); + CGContextSetShadowWithColor(ctx, CGSizeMake(6.0,-6.0), 2.0, shadowColor); + // Paint the oval with the fill color + paintOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); + CGContextRestoreGState(ctx); + + // Frame the oval with the stroke color + frameOval(ctx, CGRectMake(-a, -b, 2 * a, 2 * b)); + + // Rotate the context around the center of the image + CGContextRotateCTM(ctx, pi / count); + } + // Restore the saved state to a known state for dawing the next image + CGContextRestoreGState(ctx); CGColorRelease(shadowColor); - - // End the transparency layer + + // End the transparency layer CGContextEndTransparencyLayer(ctx); - // Calculate a bounding box for the rounded rect - a = 0.9 * bounds.size.width/4; - b = 0.3 * bounds.size.height/2; - count = 5; + // Calculate a bounding box for the rounded rect + a = 0.9 * bounds.size.width/4; + b = 0.3 * bounds.size.height/2; + count = 5; - // Set the fill color to a partially transparent red - CGContextSetRGBFillColor(ctx, 1, 0, 0, 0.5); + // Set the fill color to a partially transparent red + CGContextSetRGBFillColor(ctx, 1, 0, 0, 0.5); - // Set the stroke color to an opaque black - CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); + // Set the stroke color to an opaque black + CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 1); - // Set the line width to be used, in user space units. - CGContextSetLineWidth(ctx, 3); + // Set the line width to be used, in user space units. + CGContextSetLineWidth(ctx, 3); - // Save the conexts state because we are going to be moving the origin and - // rotating context for drawing, but we would like to restore the current - // state before drawing the next image. - CGContextSaveGState(ctx); + // Save the conexts state because we are going to be moving the origin and + // rotating context for drawing, but we would like to restore the current + // state before drawing the next image. + CGContextSaveGState(ctx); - // Move the origin to the middle of the second image (right side) to draw. - CGContextTranslateCTM(ctx, bounds.size.width/4 + bounds.size.width/2, bounds.size.height/2); + // Move the origin to the middle of the second image (right side) to draw. + CGContextTranslateCTM(ctx, bounds.size.width/4 + bounds.size.width/2, + bounds.size.height/2); - for (k = 0; k < count; k++) - { - // Fill then stroke the rounding rect, otherwise the fill would cover the stroke - fillRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); - strokeRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); - // Rotate the context for the next rounded rect - CGContextRotateCTM(ctx, pi / count); - } - CGContextRestoreGState(ctx); + for (k = 0; k < count; k++) + { + // Fill then stroke the rounding rect, otherwise the fill would cover the stroke + fillRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); + strokeRoundedRect(ctx, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); + // Rotate the context for the next rounded rect + CGContextRotateCTM(ctx, pi / count); + } + CGContextRestoreGState(ctx); } diff --git a/Tests/textlayout.m b/Tests/textlayout.m index bc8b2e9..807866f 100644 --- a/Tests/textlayout.m +++ b/Tests/textlayout.m @@ -19,90 +19,100 @@ void dumpFontDescriptorInfo(CTFontDescriptorRef descriptor) { printf("Dumping font descriptor info for %p\n", descriptor); - NSLog(@"Attribute dictionary: %@", [CTFontDescriptorCopyAttributes(descriptor) autorelease]); + NSLog(@"Attribute dictionary: %@", [CTFontDescriptorCopyAttributes( + descriptor) autorelease]); NSArray *allAttributes = [NSArray arrayWithObjects: - kCTFontURLAttribute, - kCTFontNameAttribute, - kCTFontDisplayNameAttribute, - kCTFontFamilyNameAttribute, - kCTFontStyleNameAttribute, - kCTFontTraitsAttribute, - kCTFontVariationAttribute, - kCTFontSizeAttribute, - kCTFontMatrixAttribute, - kCTFontCascadeListAttribute, - kCTFontCharacterSetAttribute, - kCTFontLanguagesAttribute, - kCTFontBaselineAdjustAttribute, - kCTFontMacintoshEncodingsAttribute, - kCTFontFeaturesAttribute, - kCTFontFeatureSettingsAttribute, - kCTFontFixedAdvanceAttribute, - kCTFontOrientationAttribute, - kCTFontEnabledAttribute, - kCTFontFormatAttribute, - kCTFontRegistrationScopeAttribute, - kCTFontPriorityAttribute, - nil]; + kCTFontURLAttribute, + kCTFontNameAttribute, + kCTFontDisplayNameAttribute, + kCTFontFamilyNameAttribute, + kCTFontStyleNameAttribute, + kCTFontTraitsAttribute, + kCTFontVariationAttribute, + kCTFontSizeAttribute, + kCTFontMatrixAttribute, + kCTFontCascadeListAttribute, + kCTFontCharacterSetAttribute, + kCTFontLanguagesAttribute, + kCTFontBaselineAdjustAttribute, + kCTFontMacintoshEncodingsAttribute, + kCTFontFeaturesAttribute, + kCTFontFeatureSettingsAttribute, + kCTFontFixedAdvanceAttribute, + kCTFontOrientationAttribute, + kCTFontEnabledAttribute, + kCTFontFormatAttribute, + kCTFontRegistrationScopeAttribute, + kCTFontPriorityAttribute, + nil]; NSLog(@"Attributes fetched via CTFontDescriptorCopyAttribute:"); NSEnumerator *attribEnumerator = [allAttributes objectEnumerator]; NSString *attrib; while (attrib = [attribEnumerator nextObject]) - { - NSLog(@"Value for '%@': %@", attrib, [CTFontDescriptorCopyAttribute(descriptor, (CFStringRef)attrib) autorelease]); - } + { + NSLog(@"Value for '%@': %@", attrib, [CTFontDescriptorCopyAttribute(descriptor, + (CFStringRef)attrib) autorelease]); + } } void dumpFontInfo(CTFontRef font) { printf("Dumping font info for %p\n", font); - -/* Glyphs */ + + /* Glyphs */ CFIndex glyphs = CTFontGetGlyphCount(font); for (CGGlyph i=0; i 0) - { + while (GetMessage(&msg, NULL, 0, 0) > 0) + { NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; - TranslateMessage(&msg); - DispatchMessage(&msg); + TranslateMessage(&msg); + DispatchMessage(&msg); [pool2 release]; } [pool release]; return 0; -} +} diff --git a/Tests/x11.m b/Tests/x11.m index 7609cd3..47757c4 100644 --- a/Tests/x11.m +++ b/Tests/x11.m @@ -33,15 +33,15 @@ int main(int argc, char **argv) /* Create a window */ win = XCreateWindow(d, /* Display */ - DefaultRootWindow(d), /* Parent */ - cr.origin.x, cr.origin.y, /* x, y */ - cr.size.width, cr.size.height, /* width, height */ - 0, /* border_width */ - CopyFromParent, /* depth */ - InputOutput, /* class */ - CopyFromParent, /* visual */ - CWBackPixel | CWEventMask, /* valuemask */ - &wa); /* attributes */ + DefaultRootWindow(d), /* Parent */ + cr.origin.x, cr.origin.y, /* x, y */ + cr.size.width, cr.size.height, /* width, height */ + 0, /* border_width */ + CopyFromParent, /* depth */ + InputOutput, /* class */ + CopyFromParent, /* visual */ + CWBackPixel | CWEventMask, /* valuemask */ + &wa); /* attributes */ printf("XCreateWindow returned: %lx\n", win); XSelectInput(d, win, ExposureMask | StructureNotifyMask | ButtonReleaseMask ); /* Map the window */ @@ -50,50 +50,53 @@ int main(int argc, char **argv) /* Create a CGContext */ ctx = OPX11ContextCreate(d, win); - if (!ctx) { - fprintf(stderr,"Cannot create context\n"); - exit(EXIT_FAILURE); - } + if (!ctx) + { + fprintf(stderr,"Cannot create context\n"); + exit(EXIT_FAILURE); + } printf("Created context\n"); - while(1) - { - NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; - XNextEvent(d,&e); - switch(e.type) + while (1) { - case Expose: - /* Dispose multiple events */ - while (XCheckTypedEvent(d, Expose, &e)); - - /* Draw window contents */ - if(e.xexpose.count == 0) { - CGContextSaveGState(ctx); - XClearWindow(d, win); - draw(ctx, cr); - CGContextRestoreGState(ctx); - } - break; - case ConfigureNotify: + NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; + XNextEvent(d,&e); + switch (e.type) { - if (cr.size.width != e.xconfigure.width || cr.size.height != e.xconfigure.height) + case Expose: + /* Dispose multiple events */ + while (XCheckTypedEvent(d, Expose, &e)); + + /* Draw window contents */ + if (e.xexpose.count == 0) + { + CGContextSaveGState(ctx); + XClearWindow(d, win); + draw(ctx, cr); + CGContextRestoreGState(ctx); + } + break; + case ConfigureNotify: { - cr.size.width = e.xconfigure.width; - cr.size.height = e.xconfigure.height; - NSLog(@"New rect: %f x %f", (float)cr.size.width, (float)cr.size.height); - OPContextSetSize(ctx, cr.size); + if (cr.size.width != e.xconfigure.width + || cr.size.height != e.xconfigure.height) + { + cr.size.width = e.xconfigure.width; + cr.size.height = e.xconfigure.height; + NSLog(@"New rect: %f x %f", (float)cr.size.width, (float)cr.size.height); + OPContextSetSize(ctx, cr.size); + } } + break; + case ButtonRelease: + /* Finish program */ + CGContextRelease(ctx); + XCloseDisplay(d); + exit(EXIT_SUCCESS); + break; } - break; - case ButtonRelease: - /* Finish program */ - CGContextRelease(ctx); - XCloseDisplay(d); - exit(EXIT_SUCCESS); - break; + [pool2 release]; } - [pool2 release]; - } [pool release]; return EXIT_SUCCESS; } From b6a19f0ffebcb4d9ec6960be87857577e3220ccc Mon Sep 17 00:00:00 2001 From: Daniel Ferreira Date: Tue, 11 Jul 2017 11:42:18 +1000 Subject: [PATCH 2/2] chore: convert from DOS encoding to Unix --- Headers/CoreGraphics/CGGradient.h | 136 +- Headers/CoreGraphics/CGImageDestination.h | 202 +-- Headers/CoreGraphics/CGImageSource.h | 276 ++-- Headers/CoreGraphics/CGPDFArray.h | 144 +- Headers/CoreGraphics/CGPDFContentStream.h | 126 +- Headers/CoreGraphics/CGPDFDictionary.h | 164 +-- Headers/CoreGraphics/CGPDFObject.h | 130 +- Headers/CoreGraphics/CGPDFOperatorTable.h | 112 +- Headers/CoreGraphics/CGPDFPage.h | 154 +-- Headers/CoreGraphics/CGPDFScanner.h | 154 +-- Headers/CoreGraphics/CGPDFStream.h | 108 +- Headers/CoreGraphics/CGPDFString.h | 96 +- Headers/CoreGraphics/CGPSConverter.h | 196 +-- Headers/CoreGraphics/CoreGraphics.h | 122 +- Source/OpalGraphics/CGDataConsumer.m | 332 ++--- Source/OpalGraphics/CGFunction.m | 126 +- Source/OpalGraphics/CGGradient-private.h | 60 +- Source/OpalGraphics/CGGradient.m | 276 ++-- .../OpalGraphics/CGImageDestination-private.h | 42 +- Source/OpalGraphics/CGImageDestination.m | 420 +++--- Source/OpalGraphics/CGImageSource-private.h | 52 +- Source/OpalGraphics/CGImageSource.m | 782 +++++------ Source/OpalGraphics/CGPDFArray.m | 174 +-- Source/OpalGraphics/CGPDFContentStream.m | 122 +- Source/OpalGraphics/CGPDFDictionary.m | 184 +-- Source/OpalGraphics/CGPDFDocument.m | 162 +-- Source/OpalGraphics/CGPDFObject.m | 72 +- Source/OpalGraphics/CGPDFOperatorTable.m | 96 +- Source/OpalGraphics/CGPDFPage.m | 152 +- Source/OpalGraphics/CGPDFScanner.m | 198 +-- Source/OpalGraphics/CGPDFStream.m | 72 +- Source/OpalGraphics/CGPDFString.m | 90 +- Source/OpalGraphics/CGPSConverter.m | 122 +- Source/OpalGraphics/CGPath.m | 1028 +++++++------- Source/OpalGraphics/CGShading.m | 144 +- Source/OpalGraphics/OPImageConversion.h | 146 +- Source/OpalGraphics/OPImageConversion.m | 702 +++++----- Source/OpalGraphics/OPPath.h | 152 +- Source/OpalGraphics/OPPath.m | 758 +++++----- Source/OpalGraphics/cairo/CairoFont.h | 70 +- Source/OpalGraphics/cairo/CairoFont.m | 130 +- Source/OpalGraphics/cairo/CairoFontWin32.h | 66 +- Source/OpalGraphics/cairo/CairoFontWin32.m | 950 ++++++------- Source/OpalGraphics/cairo/CairoFontX11.h | 64 +- Source/OpalGraphics/cairo/CairoFontX11.m | 1220 ++++++++--------- Source/OpalGraphics/internal/CGFontInternal.h | 200 +-- Source/OpalGraphics/opal-win32.m | 114 +- Tests/win32.m | 162 +-- 48 files changed, 5780 insertions(+), 5780 deletions(-) diff --git a/Headers/CoreGraphics/CGGradient.h b/Headers/CoreGraphics/CGGradient.h index 0584c75..afe2df3 100644 --- a/Headers/CoreGraphics/CGGradient.h +++ b/Headers/CoreGraphics/CGGradient.h @@ -1,68 +1,68 @@ -/** CGGradient - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGGradient; -typedef CGGradient* CGGradientRef; -#else -typedef struct CGGradient* CGGradientRef; -#endif - -#include -#include - -/* 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 +/** CGGradient + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGGradient; +typedef CGGradient* CGGradientRef; +#else +typedef struct CGGradient* CGGradientRef; +#endif + +#include +#include + +/* 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 diff --git a/Headers/CoreGraphics/CGImageDestination.h b/Headers/CoreGraphics/CGImageDestination.h index 3f47181..cf01040 100644 --- a/Headers/CoreGraphics/CGImageDestination.h +++ b/Headers/CoreGraphics/CGImageDestination.h @@ -1,101 +1,101 @@ -/** CGImageDestination - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#include - -/* Constants */ - -extern const CFStringRef kCGImageDestinationLossyCompressionQuality; -extern const CFStringRef kCGImageDestinationBackgroundColor; - -/* Data Types */ - -#ifdef INTERNAL_BUILD_OBJC -@class CGImageDestination; -typedef CGImageDestination* CGImageDestinationRef; -#else -typedef struct CGImageDestination* CGImageDestinationRef; -#endif - -#include -#include - -/* 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 */ +/** CGImageDestination + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#include + +/* Constants */ + +extern const CFStringRef kCGImageDestinationLossyCompressionQuality; +extern const CFStringRef kCGImageDestinationBackgroundColor; + +/* Data Types */ + +#ifdef INTERNAL_BUILD_OBJC +@class CGImageDestination; +typedef CGImageDestination* CGImageDestinationRef; +#else +typedef struct CGImageDestination* CGImageDestinationRef; +#endif + +#include +#include + +/* 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 */ diff --git a/Headers/CoreGraphics/CGImageSource.h b/Headers/CoreGraphics/CGImageSource.h index 47f6c1d..d7c036c 100644 --- a/Headers/CoreGraphics/CGImageSource.h +++ b/Headers/CoreGraphics/CGImageSource.h @@ -1,138 +1,138 @@ -/** CGImageSource - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#include - -/* 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 INTERNAL_BUILD_OBJC -@class CGImageSource; -typedef CGImageSource* CGImageSourceRef; -#else -typedef struct CGImageSource* CGImageSourceRef; -#endif - -#include - -/* 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 */ +/** CGImageSource + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#include + +/* 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 INTERNAL_BUILD_OBJC +@class CGImageSource; +typedef CGImageSource* CGImageSourceRef; +#else +typedef struct CGImageSource* CGImageSourceRef; +#endif + +#include + +/* 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 */ diff --git a/Headers/CoreGraphics/CGPDFArray.h b/Headers/CoreGraphics/CGPDFArray.h index bafe14e..7a41f0a 100644 --- a/Headers/CoreGraphics/CGPDFArray.h +++ b/Headers/CoreGraphics/CGPDFArray.h @@ -1,73 +1,73 @@ -/** CGPDFArray - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFArray; -typedef CGPDFArray* CGPDFArrayRef; -#else -typedef struct CGPDFArray* CGPDFArrayRef; -#endif - -#include -#include -#include -#include -#include - -/* 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); - +/** CGPDFArray + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFArray; +typedef CGPDFArray* CGPDFArrayRef; +#else +typedef struct CGPDFArray* CGPDFArrayRef; +#endif + +#include +#include +#include +#include +#include + +/* 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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFContentStream.h b/Headers/CoreGraphics/CGPDFContentStream.h index cdb4c95..44416ce 100644 --- a/Headers/CoreGraphics/CGPDFContentStream.h +++ b/Headers/CoreGraphics/CGPDFContentStream.h @@ -1,63 +1,63 @@ -/** CGPDFContentStream - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFContentStream; -typedef CGPDFContentStream* CGPDFContentStreamRef; -#else -typedef struct CGPDFContentStream* CGPDFContentStreamRef; -#endif - -#include -#include -#include -#include - -/* 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 */ +/** CGPDFContentStream + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFContentStream; +typedef CGPDFContentStream* CGPDFContentStreamRef; +#else +typedef struct CGPDFContentStream* CGPDFContentStreamRef; +#endif + +#include +#include +#include +#include + +/* 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 */ diff --git a/Headers/CoreGraphics/CGPDFDictionary.h b/Headers/CoreGraphics/CGPDFDictionary.h index 631a2ac..73c7af1 100644 --- a/Headers/CoreGraphics/CGPDFDictionary.h +++ b/Headers/CoreGraphics/CGPDFDictionary.h @@ -1,83 +1,83 @@ -/** CGPDFDictionary - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFDictionary; -typedef CGPDFDictionary* CGPDFDictionaryRef; -#else -typedef struct CGPDFDictionary* CGPDFDictionaryRef; -#endif - -#include -#include -#include -#include - -/* 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); - +/** CGPDFDictionary + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFDictionary; +typedef CGPDFDictionary* CGPDFDictionaryRef; +#else +typedef struct CGPDFDictionary* CGPDFDictionaryRef; +#endif + +#include +#include +#include +#include + +/* 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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFObject.h b/Headers/CoreGraphics/CGPDFObject.h index 02e4b3e..ecfeab3 100644 --- a/Headers/CoreGraphics/CGPDFObject.h +++ b/Headers/CoreGraphics/CGPDFObject.h @@ -1,66 +1,66 @@ -/** CGPDFObject - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 - -/* Data Types */ - -typedef unsigned char CGPDFBoolean; - -typedef long int CGPDFInteger; - -typedef CGFloat CGPDFReal; - -#ifdef INTERNAL_BUILD_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); - +/** CGPDFObject + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 + +/* Data Types */ + +typedef unsigned char CGPDFBoolean; + +typedef long int CGPDFInteger; + +typedef CGFloat CGPDFReal; + +#ifdef INTERNAL_BUILD_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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFOperatorTable.h b/Headers/CoreGraphics/CGPDFOperatorTable.h index d1692aa..d649ede 100644 --- a/Headers/CoreGraphics/CGPDFOperatorTable.h +++ b/Headers/CoreGraphics/CGPDFOperatorTable.h @@ -1,57 +1,57 @@ -/** CGPDFOperatorTable - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFOperatorTable; -typedef CGPDFOperatorTable* CGPDFOperatorTableRef; -#else -typedef struct CGPDFOperatorTable* CGPDFOperatorTableRef; -#endif - -#include -#include - -/* 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); - +/** CGPDFOperatorTable + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFOperatorTable; +typedef CGPDFOperatorTable* CGPDFOperatorTableRef; +#else +typedef struct CGPDFOperatorTable* CGPDFOperatorTableRef; +#endif + +#include +#include + +/* 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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFPage.h b/Headers/CoreGraphics/CGPDFPage.h index e1a9950..611c342 100644 --- a/Headers/CoreGraphics/CGPDFPage.h +++ b/Headers/CoreGraphics/CGPDFPage.h @@ -1,78 +1,78 @@ -/** CGPDFPage - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFPage; -typedef CGPDFPage* CGPDFPageRef; -#else -typedef struct CGPDFPage* CGPDFPageRef; -#endif - -#include -#include -#include -#include - -/* 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); - +/** CGPDFPage + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFPage; +typedef CGPDFPage* CGPDFPageRef; +#else +typedef struct CGPDFPage* CGPDFPageRef; +#endif + +#include +#include +#include +#include + +/* 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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFScanner.h b/Headers/CoreGraphics/CGPDFScanner.h index 74a3d2a..4393907 100644 --- a/Headers/CoreGraphics/CGPDFScanner.h +++ b/Headers/CoreGraphics/CGPDFScanner.h @@ -1,78 +1,78 @@ -/** CGPDFScanner - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFScanner; -typedef CGPDFScanner* CGPDFScannerRef; -#else -typedef struct CGPDFScanner* CGPDFScannerRef; -#endif - -#include -#include -#include -#include -#include -#include - -/* 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); - +/** CGPDFScanner + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFScanner; +typedef CGPDFScanner* CGPDFScannerRef; +#else +typedef struct CGPDFScanner* CGPDFScannerRef; +#endif + +#include +#include +#include +#include +#include +#include + +/* 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 */ \ No newline at end of file diff --git a/Headers/CoreGraphics/CGPDFStream.h b/Headers/CoreGraphics/CGPDFStream.h index 2f27468..346a627 100644 --- a/Headers/CoreGraphics/CGPDFStream.h +++ b/Headers/CoreGraphics/CGPDFStream.h @@ -1,54 +1,54 @@ -/** CGPDFStream - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFStream; -typedef CGPDFStream* CGPDFStreamRef; -#else -typedef struct CGPDFStream* CGPDFStreamRef; -#endif - -#include -#include - -/* 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 */ +/** CGPDFStream + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFStream; +typedef CGPDFStream* CGPDFStreamRef; +#else +typedef struct CGPDFStream* CGPDFStreamRef; +#endif + +#include +#include + +/* 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 */ diff --git a/Headers/CoreGraphics/CGPDFString.h b/Headers/CoreGraphics/CGPDFString.h index 36d6fb5..1ce0e5d 100644 --- a/Headers/CoreGraphics/CGPDFString.h +++ b/Headers/CoreGraphics/CGPDFString.h @@ -1,48 +1,48 @@ -/** CGPDFString - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 INTERNAL_BUILD_OBJC -@class CGPDFString; -typedef CGPDFString* CGPDFStringRef; -#else -typedef struct CGPDFString* CGPDFStringRef; -#endif - -#include - -/* Functions */ - -size_t CGPDFStringGetLength(CGPDFStringRef string); - -const unsigned char *CGPDFStringGetBytePtr(CGPDFStringRef string); - -CFStringRef CGPDFStringCopyTextString(CGPDFStringRef string); - -CFDateRef CGPDFStringCopyDate(CGPDFStringRef string); - -#endif /* OPAL_CGPDFString_h */ +/** CGPDFString + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 INTERNAL_BUILD_OBJC +@class CGPDFString; +typedef CGPDFString* CGPDFStringRef; +#else +typedef struct CGPDFString* CGPDFStringRef; +#endif + +#include + +/* Functions */ + +size_t CGPDFStringGetLength(CGPDFStringRef string); + +const unsigned char *CGPDFStringGetBytePtr(CGPDFStringRef string); + +CFStringRef CGPDFStringCopyTextString(CGPDFStringRef string); + +CFDateRef CGPDFStringCopyDate(CGPDFStringRef string); + +#endif /* OPAL_CGPDFString_h */ diff --git a/Headers/CoreGraphics/CGPSConverter.h b/Headers/CoreGraphics/CGPSConverter.h index af50ef5..217dbfb 100644 --- a/Headers/CoreGraphics/CGPSConverter.h +++ b/Headers/CoreGraphics/CGPSConverter.h @@ -1,98 +1,98 @@ -/** CGPSConverter - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#include -#include - -/* 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 INTERNAL_BUILD_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 */ +/** CGPSConverter + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#include +#include + +/* 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 INTERNAL_BUILD_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 */ diff --git a/Headers/CoreGraphics/CoreGraphics.h b/Headers/CoreGraphics/CoreGraphics.h index 442a6c4..3721954 100644 --- a/Headers/CoreGraphics/CoreGraphics.h +++ b/Headers/CoreGraphics/CoreGraphics.h @@ -1,61 +1,61 @@ -/** CoreGraphics - - C Interface to graphics drawing library - - geometry routines - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* OPAL_CoreGraphics_h */ +/** CoreGraphics + + C Interface to graphics drawing library + - geometry routines + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* OPAL_CoreGraphics_h */ diff --git a/Source/OpalGraphics/CGDataConsumer.m b/Source/OpalGraphics/CGDataConsumer.m index 14ba35e..9e1fd6f 100644 --- a/Source/OpalGraphics/CGDataConsumer.m +++ b/Source/OpalGraphics/CGDataConsumer.m @@ -1,166 +1,166 @@ -/** CGDataConsumer - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#import -#import -#import -#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 - }; - - NSString *path = [(NSURL*)url path]; - - NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath: path]; - if (handle == nil) - { - [[NSFileManager defaultManager] createFileAtPath: path contents: nil - attributes: nil]; - handle = [NSFileHandle fileHandleForWritingAtPath: 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]; -} +/** CGDataConsumer + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#import +#import +#import +#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 + }; + + NSString *path = [(NSURL*)url path]; + + NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath: path]; + if (handle == nil) + { + [[NSFileManager defaultManager] createFileAtPath: path contents: nil + attributes: nil]; + handle = [NSFileHandle fileHandleForWritingAtPath: 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]; +} diff --git a/Source/OpalGraphics/CGFunction.m b/Source/OpalGraphics/CGFunction.m index afa355d..80462a6 100644 --- a/Source/OpalGraphics/CGFunction.m +++ b/Source/OpalGraphics/CGFunction.m @@ -1,63 +1,63 @@ -/** CGFunction - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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]; -} +/** CGFunction + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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]; +} diff --git a/Source/OpalGraphics/CGGradient-private.h b/Source/OpalGraphics/CGGradient-private.h index 5723eb1..33976c6 100644 --- a/Source/OpalGraphics/CGGradient-private.h +++ b/Source/OpalGraphics/CGGradient-private.h @@ -1,30 +1,30 @@ -/** CGGradient - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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); +/** CGGradient + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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); diff --git a/Source/OpalGraphics/CGGradient.m b/Source/OpalGraphics/CGGradient.m index ff3c04f..0f10228 100644 --- a/Source/OpalGraphics/CGGradient.m +++ b/Source/OpalGraphics/CGGradient.m @@ -1,138 +1,138 @@ -/** CGGradient - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#import -#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; iCGGradient + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#import +#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 -#import - -@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; - +#include "CoreGraphics/CGImageDestination.h" +#import +#import + +@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 \ No newline at end of file diff --git a/Source/OpalGraphics/CGImageDestination.m b/Source/OpalGraphics/CGImageDestination.m index a18bf2e..c37f942 100644 --- a/Source/OpalGraphics/CGImageDestination.m +++ b/Source/OpalGraphics/CGImageDestination.m @@ -1,210 +1,210 @@ -/** CGImageDestination - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#import -#import - -#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; iCGImageDestination + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#import +#import + +#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 -#import - -@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; - +#include "CoreGraphics/CGImageSource.h" +#import +#import + +@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 \ No newline at end of file diff --git a/Source/OpalGraphics/CGImageSource.m b/Source/OpalGraphics/CGImageSource.m index 3b99a1f..ebd844a 100644 --- a/Source/OpalGraphics/CGImageSource.m +++ b/Source/OpalGraphics/CGImageSource.m @@ -1,391 +1,391 @@ -/** CGImageSource - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - Author: Eric Wasylishen - - 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 -#import -#import - -#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; iCGImageSource + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + Author: Eric Wasylishen + + 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 +#import +#import + +#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; iCGPDFArray - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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; +/** CGPDFArray + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFContentStream.m b/Source/OpalGraphics/CGPDFContentStream.m index 66ef590..92b357d 100644 --- a/Source/OpalGraphics/CGPDFContentStream.m +++ b/Source/OpalGraphics/CGPDFContentStream.m @@ -1,62 +1,62 @@ -/** CGPDFContentStream - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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) -{ - +/** CGPDFContentStream + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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) +{ + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFDictionary.m b/Source/OpalGraphics/CGPDFDictionary.m index 2a3dc8f..b0b962f 100644 --- a/Source/OpalGraphics/CGPDFDictionary.m +++ b/Source/OpalGraphics/CGPDFDictionary.m @@ -1,92 +1,92 @@ -/** CGPDFDictionary - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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; -} +/** CGPDFDictionary + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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; +} diff --git a/Source/OpalGraphics/CGPDFDocument.m b/Source/OpalGraphics/CGPDFDocument.m index fe55d0f..4035053 100644 --- a/Source/OpalGraphics/CGPDFDocument.m +++ b/Source/OpalGraphics/CGPDFDocument.m @@ -1,81 +1,81 @@ -/** CGPDFDocument - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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; -} +/** CGPDFDocument + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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; +} diff --git a/Source/OpalGraphics/CGPDFObject.m b/Source/OpalGraphics/CGPDFObject.m index 9b71e07..f7cccf8 100644 --- a/Source/OpalGraphics/CGPDFObject.m +++ b/Source/OpalGraphics/CGPDFObject.m @@ -1,37 +1,37 @@ -/** CGPDFObject - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#include "CoreGraphics/CGPDFObject.h" - -CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object) -{ - return kCGPDFObjectTypeNull; -} - -bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, - void *value) -{ - return false; +/** CGPDFObject + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#include "CoreGraphics/CGPDFObject.h" + +CGPDFObjectType CGPDFObjectGetType(CGPDFObjectRef object) +{ + return kCGPDFObjectTypeNull; +} + +bool CGPDFObjectGetValue(CGPDFObjectRef object, CGPDFObjectType type, + void *value) +{ + return false; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFOperatorTable.m b/Source/OpalGraphics/CGPDFOperatorTable.m index 14e963f..62abd3e 100644 --- a/Source/OpalGraphics/CGPDFOperatorTable.m +++ b/Source/OpalGraphics/CGPDFOperatorTable.m @@ -1,49 +1,49 @@ -/** CGPDFOperatorTable - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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) -{ - +/** CGPDFOperatorTable + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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) +{ + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFPage.m b/Source/OpalGraphics/CGPDFPage.m index 7361d84..e9fadb6 100644 --- a/Source/OpalGraphics/CGPDFPage.m +++ b/Source/OpalGraphics/CGPDFPage.m @@ -1,76 +1,76 @@ -/** CGPDFPage - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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) -{ - -} +/** CGPDFPage + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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) +{ + +} diff --git a/Source/OpalGraphics/CGPDFScanner.m b/Source/OpalGraphics/CGPDFScanner.m index 6f7220e..430f2ae 100644 --- a/Source/OpalGraphics/CGPDFScanner.m +++ b/Source/OpalGraphics/CGPDFScanner.m @@ -1,100 +1,100 @@ -/** CGPDFScanner - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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) -{ - +/** CGPDFScanner + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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) +{ + } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPDFStream.m b/Source/OpalGraphics/CGPDFStream.m index 95035d4..98da9c8 100644 --- a/Source/OpalGraphics/CGPDFStream.m +++ b/Source/OpalGraphics/CGPDFStream.m @@ -1,36 +1,36 @@ -/** CGPDFStream - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#include "CoreGraphics/CGPDFStream.h" - -CGPDFDictionaryRef CGPDFStreamGetDictionary(CGPDFStreamRef stream) -{ - return nil; -} - -CFDataRef CGPDFStreamCopyData(CGPDFStreamRef stream, CGPDFDataFormat *format) -{ - return nil; -} +/** CGPDFStream + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#include "CoreGraphics/CGPDFStream.h" + +CGPDFDictionaryRef CGPDFStreamGetDictionary(CGPDFStreamRef stream) +{ + return nil; +} + +CFDataRef CGPDFStreamCopyData(CGPDFStreamRef stream, CGPDFDataFormat *format) +{ + return nil; +} diff --git a/Source/OpalGraphics/CGPDFString.m b/Source/OpalGraphics/CGPDFString.m index d29cf3b..62532cd 100644 --- a/Source/OpalGraphics/CGPDFString.m +++ b/Source/OpalGraphics/CGPDFString.m @@ -1,46 +1,46 @@ -/** CGPDFString - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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; +/** CGPDFString + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPSConverter.m b/Source/OpalGraphics/CGPSConverter.m index ac1a342..245c06f 100644 --- a/Source/OpalGraphics/CGPSConverter.m +++ b/Source/OpalGraphics/CGPSConverter.m @@ -1,62 +1,62 @@ -/** CGPSConverter - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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; +/** CGPSConverter + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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; } \ No newline at end of file diff --git a/Source/OpalGraphics/CGPath.m b/Source/OpalGraphics/CGPath.m index 9c862f0..43b78c1 100644 --- a/Source/OpalGraphics/CGPath.m +++ b/Source/OpalGraphics/CGPath.m @@ -1,514 +1,514 @@ -/** CGPath - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#include "CoreGraphics/CGPath.h" - -#import "OPPath.h" - -// This magic number is 4 *(sqrt(2) -1)/3 -#define KAPPA 0.5522847498 - -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 CGPathGetPathBoundingBox(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 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 (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; iCGPath + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#include "CoreGraphics/CGPath.h" + +#import "OPPath.h" + +// This magic number is 4 *(sqrt(2) -1)/3 +#define KAPPA 0.5522847498 + +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 CGPathGetPathBoundingBox(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 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 (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; iCGShading - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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]; +/** CGShading + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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]; } \ No newline at end of file diff --git a/Source/OpalGraphics/OPImageConversion.h b/Source/OpalGraphics/OPImageConversion.h index 4e8da0a..9fb1e82 100644 --- a/Source/OpalGraphics/OPImageConversion.h +++ b/Source/OpalGraphics/OPImageConversion.h @@ -1,73 +1,73 @@ -/** CGImage-conversion.h - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - Author: Eric Wasylishen - 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 -#include - -/** - * 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; - bool needs32Swap; - // FIXME: More flags are needed -} 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); +/** CGImage-conversion.h + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + Author: Eric Wasylishen + 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 +#include + +/** + * 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; + bool needs32Swap; + // FIXME: More flags are needed +} 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); diff --git a/Source/OpalGraphics/OPImageConversion.m b/Source/OpalGraphics/OPImageConversion.m index 4ab21b3..fa57f7f 100644 --- a/Source/OpalGraphics/OPImageConversion.m +++ b/Source/OpalGraphics/OPImageConversion.m @@ -1,351 +1,351 @@ -/** CGImage-conversion.m - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - Author: Eric Wasylishen - 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 -#import - -#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; - } - NSDebugLLog(@"Opal", - @"%@: <%@, 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<compFormat = kOPComponentFormat8bpc; - break; - case 16: - out->compFormat = kOPComponentFormat16bpc; - break; - case 32: - if (bitmapInfo & kCGBitmapFloatComponents) - { - out->compFormat = kOPComponentFormatFloat32bpc; - } - else - { - out->compFormat = kOPComponentFormat32bpc; - } - 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); - // LCMS use big endian - out->needs32Swap = bitmapInfo & kCGBitmapByteOrder32Little; - - 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"); - } - - if ((dstBitsPerComponent == srcBitsPerComponent) && - (dstBitsPerPixel == srcBitsPerPixel) && - (dstBytesPerRow == srcBytesPerRow) && - (dstBitmapInfo == srcBitmapInfo) && - [dstColorSpace isEqual: srcColorSpace]) - { - // No conversion needed, copy over the data - memcpy(dstData, srcData, height * srcBytesPerRow); - - return; - } - - OPImageFormatLog(srcFormat, @"OPImageConversion source"); - OPImageFormatLog(dstFormat, @"OPImageConversion dest"); - - id 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 (needsByteSwap(srcBitmapInfo)) - { - for (uint32_t *pixel = (uint32_t*)tempInput; - pixel < (uint32_t*)(tempInput + srcBytesPerRow); - pixel++) - { - *pixel = GSSwapI32(*pixel); - } - input = tempInput; - } - */ - [xform transformPixelData: input - output: dstData + (row * dstBytesPerRow)]; - /* - if (needsByteSwap(dstBitmapInfo)) - { - for (uint32_t *pixel = (uint32_t*) (dstData + (row * dstBytesPerRow)); - pixel < (uint32_t*)(dstData + (row * dstBytesPerRow) + dstBytesPerRow); - pixel++) - { - *pixel = GSSwapI32(*pixel); - } - } - */ - } - - free(tempInput); -} +/** CGImage-conversion.m + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + Author: Eric Wasylishen + 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 +#import + +#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; + } + NSDebugLLog(@"Opal", + @"%@: <%@, 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<compFormat = kOPComponentFormat8bpc; + break; + case 16: + out->compFormat = kOPComponentFormat16bpc; + break; + case 32: + if (bitmapInfo & kCGBitmapFloatComponents) + { + out->compFormat = kOPComponentFormatFloat32bpc; + } + else + { + out->compFormat = kOPComponentFormat32bpc; + } + 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); + // LCMS use big endian + out->needs32Swap = bitmapInfo & kCGBitmapByteOrder32Little; + + 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"); + } + + if ((dstBitsPerComponent == srcBitsPerComponent) && + (dstBitsPerPixel == srcBitsPerPixel) && + (dstBytesPerRow == srcBytesPerRow) && + (dstBitmapInfo == srcBitmapInfo) && + [dstColorSpace isEqual: srcColorSpace]) + { + // No conversion needed, copy over the data + memcpy(dstData, srcData, height * srcBytesPerRow); + + return; + } + + OPImageFormatLog(srcFormat, @"OPImageConversion source"); + OPImageFormatLog(dstFormat, @"OPImageConversion dest"); + + id 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 (needsByteSwap(srcBitmapInfo)) + { + for (uint32_t *pixel = (uint32_t*)tempInput; + pixel < (uint32_t*)(tempInput + srcBytesPerRow); + pixel++) + { + *pixel = GSSwapI32(*pixel); + } + input = tempInput; + } + */ + [xform transformPixelData: input + output: dstData + (row * dstBytesPerRow)]; + /* + if (needsByteSwap(dstBitmapInfo)) + { + for (uint32_t *pixel = (uint32_t*) (dstData + (row * dstBytesPerRow)); + pixel < (uint32_t*)(dstData + (row * dstBytesPerRow) + dstBytesPerRow); + pixel++) + { + *pixel = GSSwapI32(*pixel); + } + } + */ + } + + free(tempInput); +} diff --git a/Source/OpalGraphics/OPPath.h b/Source/OpalGraphics/OPPath.h index 68b7f1d..0336eeb 100644 --- a/Source/OpalGraphics/OPPath.h +++ b/Source/OpalGraphics/OPPath.h @@ -1,76 +1,76 @@ -/** CGPath - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 -#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 - * radius after applying the affine transform from m. - * FIXME: Uses fixed tolerance to compute the number of segments needed. - */ -NSUInteger -_OPPathRequiredArcSegments(CGFloat angle, - CGFloat radius, - const CGAffineTransform *m); - +/** CGPath + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 +#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 + * radius after applying the affine transform from m. + * FIXME: Uses fixed tolerance to compute the number of segments needed. + */ +NSUInteger +_OPPathRequiredArcSegments(CGFloat angle, + CGFloat radius, + const CGAffineTransform *m); + diff --git a/Source/OpalGraphics/OPPath.m b/Source/OpalGraphics/OPPath.m index fd602ed..48174d1 100644 --- a/Source/OpalGraphics/OPPath.m +++ b/Source/OpalGraphics/OPPath.m @@ -1,379 +1,379 @@ -/** CGPath - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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; iorigin = _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)); -} - - +/** CGPath + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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; iorigin = _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)); +} + + diff --git a/Source/OpalGraphics/cairo/CairoFont.h b/Source/OpalGraphics/cairo/CairoFont.h index c0812d7..ea4b828 100644 --- a/Source/OpalGraphics/cairo/CairoFont.h +++ b/Source/OpalGraphics/cairo/CairoFont.h @@ -1,35 +1,35 @@ -/** CairoFont - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 "internal/CGFontInternal.h" -#include - -@interface CairoFont : CGFont -{ -@public - cairo_scaled_font_t *cairofont; -} - -@end - +/** CairoFont + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 "internal/CGFontInternal.h" +#include + +@interface CairoFont : CGFont +{ +@public + cairo_scaled_font_t *cairofont; +} + +@end + diff --git a/Source/OpalGraphics/cairo/CairoFont.m b/Source/OpalGraphics/cairo/CairoFont.m index a412d0d..fb9ea66 100644 --- a/Source/OpalGraphics/cairo/CairoFont.m +++ b/Source/OpalGraphics/cairo/CairoFont.m @@ -1,65 +1,65 @@ -/** CairoFont - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 "CairoFont.h" - - -@implementation CairoFont - -- (void) dealloc -{ - cairo_scaled_font_destroy(cairofont); - [super dealloc]; -} - -- (bool) canCreatePostScriptSubset: (CGFontPostScriptFormat)format -{ - return false; -} - -- (CFDataRef) createPostScriptSubset: (CFStringRef)name - : (CGFontPostScriptFormat)format - : (const CGGlyph[])glyphs - : (size_t)count - : (const CGGlyph[])encoding -{ - return NULL; -} - -+ (CGFontRef) createWithDataProvider: (CGDataProviderRef)provider -{ - // FIXME: implement - return nil; -} - -#ifdef __MINGW__ // FIXME: proper check for fontconfig -typedef void FcPattern; -#endif -+ (CGFontRef) createWithFcPattern: (FcPattern *)pat -{ - NSLog(@"%s: not implemented in %@", __PRETTY_FUNCTION__, [self class]); - return nil; -} - -@end +/** CairoFont + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 "CairoFont.h" + + +@implementation CairoFont + +- (void) dealloc +{ + cairo_scaled_font_destroy(cairofont); + [super dealloc]; +} + +- (bool) canCreatePostScriptSubset: (CGFontPostScriptFormat)format +{ + return false; +} + +- (CFDataRef) createPostScriptSubset: (CFStringRef)name + : (CGFontPostScriptFormat)format + : (const CGGlyph[])glyphs + : (size_t)count + : (const CGGlyph[])encoding +{ + return NULL; +} + ++ (CGFontRef) createWithDataProvider: (CGDataProviderRef)provider +{ + // FIXME: implement + return nil; +} + +#ifdef __MINGW__ // FIXME: proper check for fontconfig +typedef void FcPattern; +#endif ++ (CGFontRef) createWithFcPattern: (FcPattern *)pat +{ + NSLog(@"%s: not implemented in %@", __PRETTY_FUNCTION__, [self class]); + return nil; +} + +@end diff --git a/Source/OpalGraphics/cairo/CairoFontWin32.h b/Source/OpalGraphics/cairo/CairoFontWin32.h index 9500946..cbb7ec5 100644 --- a/Source/OpalGraphics/cairo/CairoFontWin32.h +++ b/Source/OpalGraphics/cairo/CairoFontWin32.h @@ -1,33 +1,33 @@ -/** CairoFontWin32 - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 "CairoFont.h" -#include -#include - -@interface CairoFontWin32 : CairoFont -{ - HFONT hfont; -} -@end +/** CairoFontWin32 + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 "CairoFont.h" +#include +#include + +@interface CairoFontWin32 : CairoFont +{ + HFONT hfont; +} +@end diff --git a/Source/OpalGraphics/cairo/CairoFontWin32.m b/Source/OpalGraphics/cairo/CairoFontWin32.m index e963407..8ab30af 100644 --- a/Source/OpalGraphics/cairo/CairoFontWin32.m +++ b/Source/OpalGraphics/cairo/CairoFontWin32.m @@ -1,475 +1,475 @@ -/** CairoFontWin32 - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - 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 - */ - -// FIXME: hack, fix the build system -#ifdef __MINGW__ - -#import "CairoFontWin32.h" -#import "StandardGlyphNames.h" - -typedef uint32_t Fixed; -typedef int16_t FWord; -typedef uint16_t UFWORD; - -struct post_table -{ - Fixed Version; - Fixed italicAngle; - FWord underlinePosition; - FWord underlineThickness; - ULONG isFixedPitch; - ULONG minMemType42; - ULONG maxMemType42; - ULONG minMemType1; - ULONG maxMemType1; - // Only for version 2.0 - USHORT numberOfGlyphs; - USHORT glyphNameIndex; //USHORT glyphNameIndex[numGlyphs]; - //CHAR names[numberNewGlyphs]; -}; - -struct hhea_table -{ - Fixed ver; - FWord Ascender; - FWord Descender; - FWord LineGap; - UFWORD advanceWidthMax; - FWord minLeftSideBearing; - FWord minRightSideBearing; - FWord xMaxExtent; - SHORT caretSlopeRise; - SHORT caretSlopeRun; - SHORT caretOffset; - SHORT r1; - SHORT r2; - SHORT r3; - SHORT r4; - SHORT metricDataFormat; - USHORT numberOfHMetrics; -}; - -typedef struct _longHorMetric -{ - USHORT advanceWidth; - SHORT lsb; -} longHorMetric; - - - -@implementation CairoFontWin32 - -- (void) dealloc -{ - DeleteObject(hfont); - [super dealloc]; -} - -- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph -{ - HDC hdc = CreateCompatibleDC(NULL); - SelectObject(hdc, hfont); - - // See http://www.microsoft.com/typography/otspec150/post.htm - - DWORD tableName = GSSwapBigI32ToHost('post'); - DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); - if (size == GDI_ERROR) - { - printf("CGFontCopyGlyphNameForGlyph: GDI error getting 'post' table"); - DeleteDC(hdc); - return nil; - } - - struct post_table *data = malloc(size); - - if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontCopyGlyphNameForGlyph: Getting 'post' table contents failed"); - DeleteDC(hdc); - free(data); - return nil; - } - - if (GSSwapBigI32ToHost(data->Version) != 0x00020000) - { - // FIXME: handle other versions. - printf("CGFontCopyGlyphNameForGlyph: 'post' table version != 2"); - DeleteDC(hdc); - free(data); - return nil; - } - - USHORT glyphNameIndex = GSSwapBigI16ToHost((&(data->glyphNameIndex))[glyph]); - - if (glyphNameIndex < 258) - { - DeleteDC(hdc); - CFStringRef ret = [[NSString alloc] initWithUTF8String: - StandardGlyphNames[glyphNameIndex]]; - free(data); - return ret; - } - else - { - glyphNameIndex -= 258; // Use this as an index into the list of pascal strings - } - - unsigned char *names = (unsigned char *)(&(data->glyphNameIndex) + - GSSwapBigI16ToHost(data->numberOfGlyphs)); - - int index = 0; - for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) - { - int count = ptr[0]; - ptr++; - - if (index == glyphNameIndex) - { - DeleteDC(hdc); - CFStringRef ret = [[NSString alloc] initWithBytes: ptr length: count encoding: - NSASCIIStringEncoding]; - free(data); - return ret; - } - else - { - ptr += count; - } - index++; - } - - DeleteDC(hdc); - free(data); - return nil; -} - -- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName -{ - HDC hdc = CreateCompatibleDC(NULL); - SelectObject(hdc, hfont); - - // See http://www.microsoft.com/typography/otspec150/post.htm - - DWORD tableName = GSSwapBigI32ToHost('post'); - DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); - if (size == GDI_ERROR) - { - printf("CGFontGetGlyphWithGlyphName: GDI error getting 'post' table"); - DeleteDC(hdc); - return 0; - } - - struct post_table *data = malloc(size); - - if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontGetGlyphWithGlyphName: Getting 'post' table contents failed"); - DeleteDC(hdc); - free(data); - return 0; - } - - if (GSSwapBigI16ToHost(data->Version) != 2) - { - // FIXME: handle other versions. - printf("CGFontGetGlyphWithGlyphName: 'post' table version != 2"); - DeleteDC(hdc); - free(data); - return 0; - } - - const char *glyphNameCString = [glyphName UTF8String]; - const int glyphNameCStringLen = strlen(glyphNameCString); - - for (int i=0; i<258; i++) - { - if (0 == strcmp(glyphNameCString, StandardGlyphNames[i])) - { - for (CFIndex j=0; jnumberOfGlyphs; j++) - { - if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == i) - { - DeleteDC(hdc); - free(data); - return (CGGlyph)j; - } - } - - printf("CGFontGetGlyphWithGlyphName: Warning, %s is a standard glyph name but it is not present in the font\n", - glyphNameCString); - break; - } - } - - unsigned char *names = (unsigned char*)(&(data->glyphNameIndex) + - self->numberOfGlyphs); - - int index = 0; - for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) - { - int count = ptr[0]; - ptr++; - if (count == glyphNameCStringLen && 0 == memcmp(ptr, glyphNameCString, count)) - { - int glyphNameIndex = index + 258; - - // Search for the glyph with this glyphNameIndex - for (CFIndex j=0; jnumberOfGlyphs; j++) - { - if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == glyphNameIndex) - { - DeleteDC(hdc); - free(data); - return (CGGlyph)j; - } - } - - printf("CGFontGetGlyphWithGlyphName: Warning, %s is in the font glyph name dictionary but it is not assigned to any glyph in the font\n", - glyphNameCString); - break; - } - else - { - ptr += count; - } - index++; - } - - DeleteDC(hdc); - free(data); - return (CGGlyph)0; -} - -- (CGGlyph) glyphWithCharacter: (unichar)character -{ - // FIXME: Implement - return 0; -} - -- (bool) getGlyphAdvances: (const CGGlyph[])glyphs -: (size_t)count -: (int[]) advances -{ - HDC hdc = CreateCompatibleDC(NULL); - SelectObject(hdc, hfont); - - DWORD tableName = GSSwapBigI32ToHost('hhea'); - DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); - if (size == GDI_ERROR) - { - printf("CGFontGetGlyphAdvances: GDI error getting 'hhea' table"); - DeleteDC(hdc); - return false; - } - - struct hhea_table *data = malloc(size); - - if (size != GetFontData(hdc, tableName, 0, data, size)) - { - printf("CGFontGetGlyphAdvances: Error getting contents of 'hhea' table"); - DeleteDC(hdc); - free(data); - return false; - } - - UINT numHMetrics = GSSwapBigI16ToHost(data->numberOfHMetrics); - - DWORD tableName2 = GSSwapBigI32ToHost('hmtx'); - DWORD size2 = GetFontData(hdc, tableName2, 0, NULL, 0); - if (size2 == GDI_ERROR) - { - printf("CGFontGetGlyphAdvances: GDI error getting 'hmtx' table"); - DeleteDC(hdc); - free(data); - return false; - } - - longHorMetric *data2 = malloc(size2); - - if (size2 != GetFontData(hdc, tableName2, 0, data2, size2)) - { - printf("CGFontGetGlyphAdvances: Error getting contents of 'hmtx' table"); - DeleteDC(hdc); - free(data); - free(data2); - return false; - } - - for (int i=0; i (numHMetrics - 1)) - indexToUse = numHMetrics - 1; - else - indexToUse = g; - advances[i] = GSSwapBigI16ToHost(data2[indexToUse].advanceWidth); - } - - DeleteDC(hdc); - free(data); - free(data2); - return true; -} - -- (CFDataRef) copyTableForTag: (uint32_t)tag -{ - return nil; -} - -- (CFArrayRef) copyTableTags -{ - return nil; -} - -- (CFArrayRef) copyVariationAxes -{ - return nil; -} - -- (CFDictionaryRef) copyVariations -{ - return nil; -} - -- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations -{ - return nil; -} - -- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding -{ - return nil; -} - -+ (CGFontRef) createWithFontName: (CFStringRef)name -{ - CairoFontWin32 *font = [[CairoFontWin32 alloc] init]; - cairo_font_face_t *unscaled; - - if (NULL == font) return nil; - - font->hfont = CreateFont(46, 28, 215, 0, - FW_NORMAL, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, - DEFAULT_PITCH | FF_ROMAN, - "Times New Roman"); - - if (font->hfont) - { - unscaled = cairo_win32_font_face_create_for_hfont(font->hfont); - } - else - { - [font release]; - return nil; - } - - // Create a cairo_scaled_font which we just use to access the underlying - // FT_Face - - cairo_matrix_t ident; - cairo_matrix_init_identity(&ident); - - cairo_font_options_t *opts = cairo_font_options_create(); - cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); - - font->cairofont = cairo_scaled_font_create(unscaled, &ident, &ident, opts); - - cairo_font_options_destroy(opts); - - - - - // Get metrics - - HDC hdc = CreateCompatibleDC(NULL); - SelectObject(hdc, font->hfont); - - - UINT metricsSize = GetOutlineTextMetrics(hdc, 0, NULL); - if (metricsSize != 0) - { - LPOUTLINETEXTMETRIC metricsData = malloc(metricsSize); - GetOutlineTextMetrics(hdc, metricsSize, metricsData); - - font->unitsPerEm = metricsData->otmEMSquare; - - // FIXME: get real values - font->fullName = @""; - font->postScriptName = @""; - font->ascent = 2000; - font->capHeight = 2000; - font->descent = 500; - font->fontBBox = CGRectMake(0,0,2000,2000); - font->italicAngle = 0; - font->leading = 500; - font->stemV = 500; - font->xHeight = 2000; - - free(metricsData); - } - else - { - printf("CGCreateFontWithName: Warning: couldn't get font metrics"); - } - - /* Get the number of glyphs from the 'post' table */ - - font->numberOfGlyphs = 0; - - DWORD tableName = GSSwapBigI32ToHost('post'); - DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); - if (size != GDI_ERROR) - { - struct post_table *data = malloc(size); - if (size == GetFontData(hdc, tableName, 0, data, size)) - { - font->numberOfGlyphs = GSSwapBigI16ToHost(data->numberOfGlyphs); - } - } - - if (font->numberOfGlyphs == 0) - { - printf("CGCreateFontWithName: Warning: font has 0 glyphs"); - } - - DeleteDC(hdc); - - return (CGFontRef)font; -} - -+ (CGFontRef) createWithPlatformFont: (void *)platformFontReference -{ - return nil; -} - - - -@end - -#endif +/** CairoFontWin32 + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + 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 + */ + +// FIXME: hack, fix the build system +#ifdef __MINGW__ + +#import "CairoFontWin32.h" +#import "StandardGlyphNames.h" + +typedef uint32_t Fixed; +typedef int16_t FWord; +typedef uint16_t UFWORD; + +struct post_table +{ + Fixed Version; + Fixed italicAngle; + FWord underlinePosition; + FWord underlineThickness; + ULONG isFixedPitch; + ULONG minMemType42; + ULONG maxMemType42; + ULONG minMemType1; + ULONG maxMemType1; + // Only for version 2.0 + USHORT numberOfGlyphs; + USHORT glyphNameIndex; //USHORT glyphNameIndex[numGlyphs]; + //CHAR names[numberNewGlyphs]; +}; + +struct hhea_table +{ + Fixed ver; + FWord Ascender; + FWord Descender; + FWord LineGap; + UFWORD advanceWidthMax; + FWord minLeftSideBearing; + FWord minRightSideBearing; + FWord xMaxExtent; + SHORT caretSlopeRise; + SHORT caretSlopeRun; + SHORT caretOffset; + SHORT r1; + SHORT r2; + SHORT r3; + SHORT r4; + SHORT metricDataFormat; + USHORT numberOfHMetrics; +}; + +typedef struct _longHorMetric +{ + USHORT advanceWidth; + SHORT lsb; +} longHorMetric; + + + +@implementation CairoFontWin32 + +- (void) dealloc +{ + DeleteObject(hfont); + [super dealloc]; +} + +- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph +{ + HDC hdc = CreateCompatibleDC(NULL); + SelectObject(hdc, hfont); + + // See http://www.microsoft.com/typography/otspec150/post.htm + + DWORD tableName = GSSwapBigI32ToHost('post'); + DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); + if (size == GDI_ERROR) + { + printf("CGFontCopyGlyphNameForGlyph: GDI error getting 'post' table"); + DeleteDC(hdc); + return nil; + } + + struct post_table *data = malloc(size); + + if (size != GetFontData(hdc, tableName, 0, data, size)) + { + printf("CGFontCopyGlyphNameForGlyph: Getting 'post' table contents failed"); + DeleteDC(hdc); + free(data); + return nil; + } + + if (GSSwapBigI32ToHost(data->Version) != 0x00020000) + { + // FIXME: handle other versions. + printf("CGFontCopyGlyphNameForGlyph: 'post' table version != 2"); + DeleteDC(hdc); + free(data); + return nil; + } + + USHORT glyphNameIndex = GSSwapBigI16ToHost((&(data->glyphNameIndex))[glyph]); + + if (glyphNameIndex < 258) + { + DeleteDC(hdc); + CFStringRef ret = [[NSString alloc] initWithUTF8String: + StandardGlyphNames[glyphNameIndex]]; + free(data); + return ret; + } + else + { + glyphNameIndex -= 258; // Use this as an index into the list of pascal strings + } + + unsigned char *names = (unsigned char *)(&(data->glyphNameIndex) + + GSSwapBigI16ToHost(data->numberOfGlyphs)); + + int index = 0; + for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) + { + int count = ptr[0]; + ptr++; + + if (index == glyphNameIndex) + { + DeleteDC(hdc); + CFStringRef ret = [[NSString alloc] initWithBytes: ptr length: count encoding: + NSASCIIStringEncoding]; + free(data); + return ret; + } + else + { + ptr += count; + } + index++; + } + + DeleteDC(hdc); + free(data); + return nil; +} + +- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName +{ + HDC hdc = CreateCompatibleDC(NULL); + SelectObject(hdc, hfont); + + // See http://www.microsoft.com/typography/otspec150/post.htm + + DWORD tableName = GSSwapBigI32ToHost('post'); + DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); + if (size == GDI_ERROR) + { + printf("CGFontGetGlyphWithGlyphName: GDI error getting 'post' table"); + DeleteDC(hdc); + return 0; + } + + struct post_table *data = malloc(size); + + if (size != GetFontData(hdc, tableName, 0, data, size)) + { + printf("CGFontGetGlyphWithGlyphName: Getting 'post' table contents failed"); + DeleteDC(hdc); + free(data); + return 0; + } + + if (GSSwapBigI16ToHost(data->Version) != 2) + { + // FIXME: handle other versions. + printf("CGFontGetGlyphWithGlyphName: 'post' table version != 2"); + DeleteDC(hdc); + free(data); + return 0; + } + + const char *glyphNameCString = [glyphName UTF8String]; + const int glyphNameCStringLen = strlen(glyphNameCString); + + for (int i=0; i<258; i++) + { + if (0 == strcmp(glyphNameCString, StandardGlyphNames[i])) + { + for (CFIndex j=0; jnumberOfGlyphs; j++) + { + if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == i) + { + DeleteDC(hdc); + free(data); + return (CGGlyph)j; + } + } + + printf("CGFontGetGlyphWithGlyphName: Warning, %s is a standard glyph name but it is not present in the font\n", + glyphNameCString); + break; + } + } + + unsigned char *names = (unsigned char*)(&(data->glyphNameIndex) + + self->numberOfGlyphs); + + int index = 0; + for (unsigned char *ptr = names; (ptr - (unsigned char *)data) < size; ) + { + int count = ptr[0]; + ptr++; + if (count == glyphNameCStringLen && 0 == memcmp(ptr, glyphNameCString, count)) + { + int glyphNameIndex = index + 258; + + // Search for the glyph with this glyphNameIndex + for (CFIndex j=0; jnumberOfGlyphs; j++) + { + if (GSSwapBigI16ToHost((&(data->glyphNameIndex))[j]) == glyphNameIndex) + { + DeleteDC(hdc); + free(data); + return (CGGlyph)j; + } + } + + printf("CGFontGetGlyphWithGlyphName: Warning, %s is in the font glyph name dictionary but it is not assigned to any glyph in the font\n", + glyphNameCString); + break; + } + else + { + ptr += count; + } + index++; + } + + DeleteDC(hdc); + free(data); + return (CGGlyph)0; +} + +- (CGGlyph) glyphWithCharacter: (unichar)character +{ + // FIXME: Implement + return 0; +} + +- (bool) getGlyphAdvances: (const CGGlyph[])glyphs +: (size_t)count +: (int[]) advances +{ + HDC hdc = CreateCompatibleDC(NULL); + SelectObject(hdc, hfont); + + DWORD tableName = GSSwapBigI32ToHost('hhea'); + DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); + if (size == GDI_ERROR) + { + printf("CGFontGetGlyphAdvances: GDI error getting 'hhea' table"); + DeleteDC(hdc); + return false; + } + + struct hhea_table *data = malloc(size); + + if (size != GetFontData(hdc, tableName, 0, data, size)) + { + printf("CGFontGetGlyphAdvances: Error getting contents of 'hhea' table"); + DeleteDC(hdc); + free(data); + return false; + } + + UINT numHMetrics = GSSwapBigI16ToHost(data->numberOfHMetrics); + + DWORD tableName2 = GSSwapBigI32ToHost('hmtx'); + DWORD size2 = GetFontData(hdc, tableName2, 0, NULL, 0); + if (size2 == GDI_ERROR) + { + printf("CGFontGetGlyphAdvances: GDI error getting 'hmtx' table"); + DeleteDC(hdc); + free(data); + return false; + } + + longHorMetric *data2 = malloc(size2); + + if (size2 != GetFontData(hdc, tableName2, 0, data2, size2)) + { + printf("CGFontGetGlyphAdvances: Error getting contents of 'hmtx' table"); + DeleteDC(hdc); + free(data); + free(data2); + return false; + } + + for (int i=0; i (numHMetrics - 1)) + indexToUse = numHMetrics - 1; + else + indexToUse = g; + advances[i] = GSSwapBigI16ToHost(data2[indexToUse].advanceWidth); + } + + DeleteDC(hdc); + free(data); + free(data2); + return true; +} + +- (CFDataRef) copyTableForTag: (uint32_t)tag +{ + return nil; +} + +- (CFArrayRef) copyTableTags +{ + return nil; +} + +- (CFArrayRef) copyVariationAxes +{ + return nil; +} + +- (CFDictionaryRef) copyVariations +{ + return nil; +} + +- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations +{ + return nil; +} + +- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding +{ + return nil; +} + ++ (CGFontRef) createWithFontName: (CFStringRef)name +{ + CairoFontWin32 *font = [[CairoFontWin32 alloc] init]; + cairo_font_face_t *unscaled; + + if (NULL == font) return nil; + + font->hfont = CreateFont(46, 28, 215, 0, + FW_NORMAL, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + DEFAULT_PITCH | FF_ROMAN, + "Times New Roman"); + + if (font->hfont) + { + unscaled = cairo_win32_font_face_create_for_hfont(font->hfont); + } + else + { + [font release]; + return nil; + } + + // Create a cairo_scaled_font which we just use to access the underlying + // FT_Face + + cairo_matrix_t ident; + cairo_matrix_init_identity(&ident); + + cairo_font_options_t *opts = cairo_font_options_create(); + cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); + + font->cairofont = cairo_scaled_font_create(unscaled, &ident, &ident, opts); + + cairo_font_options_destroy(opts); + + + + + // Get metrics + + HDC hdc = CreateCompatibleDC(NULL); + SelectObject(hdc, font->hfont); + + + UINT metricsSize = GetOutlineTextMetrics(hdc, 0, NULL); + if (metricsSize != 0) + { + LPOUTLINETEXTMETRIC metricsData = malloc(metricsSize); + GetOutlineTextMetrics(hdc, metricsSize, metricsData); + + font->unitsPerEm = metricsData->otmEMSquare; + + // FIXME: get real values + font->fullName = @""; + font->postScriptName = @""; + font->ascent = 2000; + font->capHeight = 2000; + font->descent = 500; + font->fontBBox = CGRectMake(0,0,2000,2000); + font->italicAngle = 0; + font->leading = 500; + font->stemV = 500; + font->xHeight = 2000; + + free(metricsData); + } + else + { + printf("CGCreateFontWithName: Warning: couldn't get font metrics"); + } + + /* Get the number of glyphs from the 'post' table */ + + font->numberOfGlyphs = 0; + + DWORD tableName = GSSwapBigI32ToHost('post'); + DWORD size = GetFontData(hdc, tableName, 0, NULL, 0); + if (size != GDI_ERROR) + { + struct post_table *data = malloc(size); + if (size == GetFontData(hdc, tableName, 0, data, size)) + { + font->numberOfGlyphs = GSSwapBigI16ToHost(data->numberOfGlyphs); + } + } + + if (font->numberOfGlyphs == 0) + { + printf("CGCreateFontWithName: Warning: font has 0 glyphs"); + } + + DeleteDC(hdc); + + return (CGFontRef)font; +} + ++ (CGFontRef) createWithPlatformFont: (void *)platformFontReference +{ + return nil; +} + + + +@end + +#endif diff --git a/Source/OpalGraphics/cairo/CairoFontX11.h b/Source/OpalGraphics/cairo/CairoFontX11.h index 6fa7054..d2e5033 100644 --- a/Source/OpalGraphics/cairo/CairoFontX11.h +++ b/Source/OpalGraphics/cairo/CairoFontX11.h @@ -1,32 +1,32 @@ -/** CairoFontX11 - - C Interface to graphics drawing library - - Copyright (C) 2006 Free Software Foundation, Inc. - - 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 "CairoFont.h" - -@interface CairoFontX11 : CairoFont -{ - -} -@end +/** CairoFontX11 + + C Interface to graphics drawing library + + Copyright (C) 2006 Free Software Foundation, Inc. + + 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 "CairoFont.h" + +@interface CairoFontX11 : CairoFont +{ + +} +@end diff --git a/Source/OpalGraphics/cairo/CairoFontX11.m b/Source/OpalGraphics/cairo/CairoFontX11.m index 289e822..7b1407b 100644 --- a/Source/OpalGraphics/cairo/CairoFontX11.m +++ b/Source/OpalGraphics/cairo/CairoFontX11.m @@ -1,610 +1,610 @@ -/** CairoFontX11 - - C Interface to graphics drawing library - - Copyright (C) 2006 Free Software Foundation, Inc. - - Author: BALATON Zoltan - Date: 2006 - 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 - */ - -// FIXME: hack, fix the build system -#ifndef __MINGW__ - -#import -#include "CoreGraphics/CGBase.h" -#include "CoreGraphics/CGDataProvider.h" -#include "CoreGraphics/CGFont.h" -#include -#include - -#include -#include FT_LIST_H -#include FT_SFNT_NAMES_H -#include FT_TRUETYPE_IDS_H -#include FT_TRUETYPE_TABLES_H - -#import "CairoFontX11.h" - - -/* We just return a (cairo_font_face_t *) as a (CGFontRef) */ - -static FcPattern *opal_FcPatternCreateFromName(const char *name); - -/* We keep an LRU cache of patterns looked up by name to avoid calling - * fontconfig too frequently (like when refreshing a window repeatedly) */ -/* But we cache patterns and let cairo handle FT_Face objects because of - * memory management problems (lack of reference counting on FT_Face) */ -/* We can't use Freetype's Cache Manager to implement our cache because its API - * seems to be in a flux (for other than Face, CMap, Image and SBit at least) */ - -/* Number of entries to keep in the cache */ -#define CACHE_SIZE 10 - -static FT_ListRec pattern_cache; - -typedef struct cache_entry -{ - FT_ListNodeRec node; - unsigned int hash; - FcPattern *pat; -} cache_entry; - -typedef struct iter_state -{ - unsigned int hash; - FcPattern *pat; - int cnt; -} iter_state; - -static FT_Error cache_iterator(FT_ListNode node, void *user) -{ - cache_entry *entry = (cache_entry *)node; - iter_state *state = user; - - state->cnt++; - if (!node) return 1; - if (entry->hash == state->hash) - { - state->pat = entry->pat; - FT_List_Up(&pattern_cache, node); - return 2; - } - return 0; -} - -static unsigned int hash_string(const char *str) -{ - unsigned int hash; - - for (hash = 0; *str != '\0'; str++) - hash = 31 * hash + *str; - - return hash; -} - -static FcPattern *opal_FcPatternCacheLookup(const char *name) -{ - iter_state state; - - state.cnt = 0; - state.pat = NULL; - state.hash = hash_string(name); - FT_List_Iterate(&pattern_cache, cache_iterator, &state); - - if (state.pat) - return state.pat; - - state.pat = opal_FcPatternCreateFromName(name); - if (!state.pat) return NULL; - - if (state.cnt >= CACHE_SIZE) /* Remove last entry from the cache */ - { - FT_ListNode node; - - node = pattern_cache.tail; - FT_List_Remove(&pattern_cache, node); - FcPatternDestroy(((cache_entry *)node)->pat); - free(node); - } - /* Add new entry to the cache */ - { - cache_entry *entry; - - entry = calloc(1, sizeof(*entry)); - if (!entry) - { - NSLog(@"calloc failed"); - return state.pat; - } - entry->hash = state.hash; - entry->pat = state.pat; - FT_List_Insert(&pattern_cache, (FT_ListNode)entry); - } - return state.pat; -} - -/* End of cache related things */ - - - -// -// Note on CGFont: we really need David Turner's cairo-ft rewrite, -// which is on the roadmap for cairo 1.12. -// -// The current cairo_ft_scaled_font_lock_face function is almost useless. -// With it, we can only (safely) look at immutable parts of the FT_Face. -// -@implementation CairoFontX11 - -- (CFStringRef) copyFullName; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CFStringRef result = NULL; - - if (ft_face) - { - const int FULL_NAME = 4; - FT_SfntName nameStruct; - if (0 == FT_Get_Sfnt_Name(ft_face, FULL_NAME, &nameStruct)) - { - if (nameStruct.platform_id == TT_PLATFORM_APPLE_UNICODE) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: - nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; - } - else if (nameStruct.platform_id == TT_PLATFORM_MACINTOSH && - nameStruct.encoding_id == TT_MAC_ID_ROMAN) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: - nameStruct.string_len encoding: NSMacOSRomanStringEncoding]; - } - else if (nameStruct.platform_id == TT_PLATFORM_MICROSOFT && - nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) - { - result = [[NSString alloc] initWithBytes: nameStruct.string length: - nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; - } - } - - if (NULL != ft_face->family_name) - { - result = [[NSString alloc] initWithUTF8String: ft_face->family_name]; - } - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CFStringRef result = NULL; - - if (ft_face) - { - char buffer[256]; - FT_Get_Glyph_Name(ft_face, glyph, buffer, 256); - result = [[NSString alloc] initWithUTF8String: buffer]; - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CFStringRef) copyPostScriptName; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CFStringRef result = NULL; - - if (ft_face) - { - const char *psname = FT_Get_Postscript_Name(ft_face); - if (NULL != psname) - { - result = [[NSString alloc] initWithUTF8String: psname]; - } - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CFDataRef) copyTableForTag: (uint32_t)tag; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CFDataRef result = NULL; - - if (ft_face) - { - FT_ULong length = 0; - void *buffer; - - if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, NULL, &length)) - { - buffer = malloc(length); - if (buffer) - { - if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, buffer, &length)) - { - result = [[NSData alloc] initWithBytes: buffer length: length]; - } - free(buffer); - } - } - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CFArrayRef) copyTableTags; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CFMutableArrayRef result = [[NSMutableArray alloc] init]; - - if (ft_face) - { - unsigned int i = 0; - unsigned long tag, length; - - while (FT_Err_Table_Missing != - FT_Sfnt_Table_Info(ft_face, i, &tag, &length)) - { - // FIXME: see CGFontCopyTableTags reference, the CFArray should contain raw tags and not NSNumbers - [result addObject: [NSNumber numberWithInt: tag]]; - i++; - } - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CFArrayRef) copyVariationAxes; -{ - return NULL; -} - -- (CFDictionaryRef) copyVariations; -{ - return NULL; -} - -- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations; -{ - return NULL; -} - -- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding; -{ - return NULL; -} - -- (int) ascent; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - int result = ft_face->bbox.yMax; - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (int) capHeight; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - int result = 0; - - TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); - if (NULL != os2table) - { - result = os2table->sCapHeight; - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (int) descent; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - int result = -ft_face->descender; - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CGRect) fontBBox; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - FT_BBox bbox = ft_face->bbox; - CGRect result = CGRectMake( - bbox.xMin, - bbox.yMin, - bbox.xMax - bbox.xMin, - bbox.yMax - bbox.yMin); - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CGGlyph result = 0; - - const char *name = [glyphName UTF8String]; - result = (CGGlyph)FT_Get_Name_Index(ft_face, (FT_String*)name); - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CGGlyph) glyphWithCharacter: (unichar)character -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CGGlyph result = (CGGlyph)FT_Get_Char_Index(ft_face, character); - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CGFloat) italicAngle; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - CGFloat result = 0; - - TT_Postscript *pstable = (TT_Postscript *)FT_Get_Sfnt_Table(ft_face, - ft_sfnt_post); - if (NULL != pstable) - { - result = pstable->italicAngle; - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (int) leading; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - - // see http://www.typophile.com/node/13081 - int result = ft_face->height - ft_face->ascender + - ft_face->descender; - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (size_t) numberOfGlyphs; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - - int result = ft_face->num_glyphs; - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (CGFloat) stemV; -{ - return 0; -} - -- (int) unitsPerEm; -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - - int result = ft_face->units_per_EM; - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -- (int) xHeight -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - int result = 0; - - TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); - if (NULL != os2table) - { - result = os2table->sxHeight; - } - - cairo_ft_scaled_font_unlock_face(self->cairofont); - return result; -} - -// FIXME: quite possibly not thread safe -- (CGSize) maximumAdvancement -{ - cairo_font_extents_t font_extents; - CGSize maximum_advancement = CGSizeZero; - - //FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - - cairo_scaled_font_extents(self->cairofont, &font_extents); - if (cairo_scaled_font_status(self->cairofont) == CAIRO_STATUS_SUCCESS) - { - maximum_advancement = CGSizeMake(font_extents.max_x_advance, - font_extents.max_y_advance); - } - - //cairo_ft_scaled_font_unlock_face(self->cairofont); - - return maximum_advancement; -} - -+ (CGFontRef) createWithFontName: (CFStringRef)name; -{ - FcPattern *pat; - - pat = opal_FcPatternCacheLookup([(NSString*)name UTF8String]); - return [self createWithFcPattern: pat]; -} - -+ (CGFontRef) createWithFcPattern: (FcPattern *)pat -{ - cairo_font_face_t *unscaled; - CairoFontX11 *font = [[CairoFontX11 alloc] init]; - if (!font) return NULL; - - if (pat) - { - unscaled = cairo_ft_font_face_create_for_pattern(pat); - } - else - { - CGFontRelease(font); - return NULL; - } - - // Create a cairo_scaled_font which we just use to access the underlying - // FT_Face - - cairo_matrix_t ident; - cairo_matrix_init_identity(&ident); - - cairo_font_options_t *opts = cairo_font_options_create(); - cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); - cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); - - font->cairofont = cairo_scaled_font_create(unscaled, - &ident, &ident, opts); - - cairo_font_options_destroy(opts); - - font->fullName = [font copyFullName]; - font->postScriptName = [font copyPostScriptName]; - font->ascent = [font ascent]; - font->capHeight = [font capHeight]; - font->descent = [font descent]; - font->fontBBox = [font fontBBox]; - font->italicAngle = [font italicAngle]; - font->leading = [font leading]; - font->numberOfGlyphs = [font numberOfGlyphs]; - font->stemV = [font stemV]; - font->unitsPerEm = [font unitsPerEm]; - font->xHeight = [font xHeight]; - font->maximumAdvancement = [font maximumAdvancement]; - return (CGFontRef)font; -} - -+ (CGFontRef) createWithPlatformFont: (void *)platformFontReference; -{ - return NULL; -} - -//FIXME: Not threadsafe -- (bool) getGlyphAdvances: (const CGGlyph[])glyphs -: (size_t)count -: (int[]) advances -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - for (size_t i=0; iglyph->metrics.horiAdvance; - } - cairo_ft_scaled_font_unlock_face(self->cairofont); - return true; -} - -//FIXME: Not threadsafe -- (bool) getGlyphBBoxes: (const CGGlyph[])glyphs - : (size_t)count - : (CGRect[])bboxes -{ - FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); - for (size_t i=0; iglyph->metrics; - bboxes[i] = CGRectMake(m.horiBearingX, m.horiBearingY - m.height, m.width, - m.height); - } - cairo_ft_scaled_font_unlock_face(self->cairofont); - return true; -} - -@end - - - - - - - - - - -static FcPattern *opal_FcPatternCreateFromName(const char *name) -{ - char *family, *traits; - FcPattern *pat; - FcResult fcres; - FcBool success; - - if (!name) return NULL; - family = strdup(name); - pat = FcPatternCreate(); - if (!family || !pat) goto error; - - /* Try to parse a Postscript font name and make a corresponding pattern */ - /* Consider everything up to the first dash to be the family name */ - traits = strchr(family, '-'); - if (traits) - { - *traits = '\0'; - traits++; - } - success = FcPatternAddString(pat, FC_FAMILY, (FcChar8 *)family); - if (!success) goto error; - if (traits) - { - /* FIXME: The following is incomplete and may also be wrong */ - /* Fontconfig assumes Medium Roman Regular so don't care about theese */ - if (strstr(traits, "Bold")) - success |= FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); - if (strstr(traits, "Italic")) - success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_ITALIC); - if (strstr(traits, "Oblique")) - success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_OBLIQUE); - if (strstr(traits, "Condensed")) - success |= FcPatternAddInteger(pat, FC_WIDTH, FC_WIDTH_CONDENSED); - if (!success) goto error; - } - - success = FcConfigSubstitute(NULL, pat, FcMatchPattern); - if (!success) goto error; - FcDefaultSubstitute(pat); - pat = FcFontMatch(NULL, pat, &fcres); - if (!pat) goto error; - free(family); - return pat; - -error: - NSLog(@"opal_FcPatternCreateFromName failed"); - if (family) free (family); - if (pat) FcPatternDestroy(pat); - return NULL; -} - -#endif +/** CairoFontX11 + + C Interface to graphics drawing library + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: BALATON Zoltan + Date: 2006 + 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 + */ + +// FIXME: hack, fix the build system +#ifndef __MINGW__ + +#import +#include "CoreGraphics/CGBase.h" +#include "CoreGraphics/CGDataProvider.h" +#include "CoreGraphics/CGFont.h" +#include +#include + +#include +#include FT_LIST_H +#include FT_SFNT_NAMES_H +#include FT_TRUETYPE_IDS_H +#include FT_TRUETYPE_TABLES_H + +#import "CairoFontX11.h" + + +/* We just return a (cairo_font_face_t *) as a (CGFontRef) */ + +static FcPattern *opal_FcPatternCreateFromName(const char *name); + +/* We keep an LRU cache of patterns looked up by name to avoid calling + * fontconfig too frequently (like when refreshing a window repeatedly) */ +/* But we cache patterns and let cairo handle FT_Face objects because of + * memory management problems (lack of reference counting on FT_Face) */ +/* We can't use Freetype's Cache Manager to implement our cache because its API + * seems to be in a flux (for other than Face, CMap, Image and SBit at least) */ + +/* Number of entries to keep in the cache */ +#define CACHE_SIZE 10 + +static FT_ListRec pattern_cache; + +typedef struct cache_entry +{ + FT_ListNodeRec node; + unsigned int hash; + FcPattern *pat; +} cache_entry; + +typedef struct iter_state +{ + unsigned int hash; + FcPattern *pat; + int cnt; +} iter_state; + +static FT_Error cache_iterator(FT_ListNode node, void *user) +{ + cache_entry *entry = (cache_entry *)node; + iter_state *state = user; + + state->cnt++; + if (!node) return 1; + if (entry->hash == state->hash) + { + state->pat = entry->pat; + FT_List_Up(&pattern_cache, node); + return 2; + } + return 0; +} + +static unsigned int hash_string(const char *str) +{ + unsigned int hash; + + for (hash = 0; *str != '\0'; str++) + hash = 31 * hash + *str; + + return hash; +} + +static FcPattern *opal_FcPatternCacheLookup(const char *name) +{ + iter_state state; + + state.cnt = 0; + state.pat = NULL; + state.hash = hash_string(name); + FT_List_Iterate(&pattern_cache, cache_iterator, &state); + + if (state.pat) + return state.pat; + + state.pat = opal_FcPatternCreateFromName(name); + if (!state.pat) return NULL; + + if (state.cnt >= CACHE_SIZE) /* Remove last entry from the cache */ + { + FT_ListNode node; + + node = pattern_cache.tail; + FT_List_Remove(&pattern_cache, node); + FcPatternDestroy(((cache_entry *)node)->pat); + free(node); + } + /* Add new entry to the cache */ + { + cache_entry *entry; + + entry = calloc(1, sizeof(*entry)); + if (!entry) + { + NSLog(@"calloc failed"); + return state.pat; + } + entry->hash = state.hash; + entry->pat = state.pat; + FT_List_Insert(&pattern_cache, (FT_ListNode)entry); + } + return state.pat; +} + +/* End of cache related things */ + + + +// +// Note on CGFont: we really need David Turner's cairo-ft rewrite, +// which is on the roadmap for cairo 1.12. +// +// The current cairo_ft_scaled_font_lock_face function is almost useless. +// With it, we can only (safely) look at immutable parts of the FT_Face. +// +@implementation CairoFontX11 + +- (CFStringRef) copyFullName; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CFStringRef result = NULL; + + if (ft_face) + { + const int FULL_NAME = 4; + FT_SfntName nameStruct; + if (0 == FT_Get_Sfnt_Name(ft_face, FULL_NAME, &nameStruct)) + { + if (nameStruct.platform_id == TT_PLATFORM_APPLE_UNICODE) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; + } + else if (nameStruct.platform_id == TT_PLATFORM_MACINTOSH && + nameStruct.encoding_id == TT_MAC_ID_ROMAN) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSMacOSRomanStringEncoding]; + } + else if (nameStruct.platform_id == TT_PLATFORM_MICROSOFT && + nameStruct.encoding_id == TT_MS_ID_UNICODE_CS) + { + result = [[NSString alloc] initWithBytes: nameStruct.string length: + nameStruct.string_len encoding: NSUTF16BigEndianStringEncoding]; + } + } + + if (NULL != ft_face->family_name) + { + result = [[NSString alloc] initWithUTF8String: ft_face->family_name]; + } + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CFStringRef result = NULL; + + if (ft_face) + { + char buffer[256]; + FT_Get_Glyph_Name(ft_face, glyph, buffer, 256); + result = [[NSString alloc] initWithUTF8String: buffer]; + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CFStringRef) copyPostScriptName; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CFStringRef result = NULL; + + if (ft_face) + { + const char *psname = FT_Get_Postscript_Name(ft_face); + if (NULL != psname) + { + result = [[NSString alloc] initWithUTF8String: psname]; + } + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CFDataRef) copyTableForTag: (uint32_t)tag; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CFDataRef result = NULL; + + if (ft_face) + { + FT_ULong length = 0; + void *buffer; + + if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, NULL, &length)) + { + buffer = malloc(length); + if (buffer) + { + if (0 == FT_Load_Sfnt_Table(ft_face, tag, 0, buffer, &length)) + { + result = [[NSData alloc] initWithBytes: buffer length: length]; + } + free(buffer); + } + } + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CFArrayRef) copyTableTags; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CFMutableArrayRef result = [[NSMutableArray alloc] init]; + + if (ft_face) + { + unsigned int i = 0; + unsigned long tag, length; + + while (FT_Err_Table_Missing != + FT_Sfnt_Table_Info(ft_face, i, &tag, &length)) + { + // FIXME: see CGFontCopyTableTags reference, the CFArray should contain raw tags and not NSNumbers + [result addObject: [NSNumber numberWithInt: tag]]; + i++; + } + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CFArrayRef) copyVariationAxes; +{ + return NULL; +} + +- (CFDictionaryRef) copyVariations; +{ + return NULL; +} + +- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations; +{ + return NULL; +} + +- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding; +{ + return NULL; +} + +- (int) ascent; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + int result = ft_face->bbox.yMax; + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (int) capHeight; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + int result = 0; + + TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); + if (NULL != os2table) + { + result = os2table->sCapHeight; + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (int) descent; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + int result = -ft_face->descender; + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CGRect) fontBBox; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + FT_BBox bbox = ft_face->bbox; + CGRect result = CGRectMake( + bbox.xMin, + bbox.yMin, + bbox.xMax - bbox.xMin, + bbox.yMax - bbox.yMin); + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CGGlyph result = 0; + + const char *name = [glyphName UTF8String]; + result = (CGGlyph)FT_Get_Name_Index(ft_face, (FT_String*)name); + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CGGlyph) glyphWithCharacter: (unichar)character +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CGGlyph result = (CGGlyph)FT_Get_Char_Index(ft_face, character); + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CGFloat) italicAngle; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + CGFloat result = 0; + + TT_Postscript *pstable = (TT_Postscript *)FT_Get_Sfnt_Table(ft_face, + ft_sfnt_post); + if (NULL != pstable) + { + result = pstable->italicAngle; + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (int) leading; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + + // see http://www.typophile.com/node/13081 + int result = ft_face->height - ft_face->ascender + + ft_face->descender; + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (size_t) numberOfGlyphs; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + + int result = ft_face->num_glyphs; + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (CGFloat) stemV; +{ + return 0; +} + +- (int) unitsPerEm; +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + + int result = ft_face->units_per_EM; + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +- (int) xHeight +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + int result = 0; + + TT_OS2 *os2table = (TT_OS2 *)FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); + if (NULL != os2table) + { + result = os2table->sxHeight; + } + + cairo_ft_scaled_font_unlock_face(self->cairofont); + return result; +} + +// FIXME: quite possibly not thread safe +- (CGSize) maximumAdvancement +{ + cairo_font_extents_t font_extents; + CGSize maximum_advancement = CGSizeZero; + + //FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + + cairo_scaled_font_extents(self->cairofont, &font_extents); + if (cairo_scaled_font_status(self->cairofont) == CAIRO_STATUS_SUCCESS) + { + maximum_advancement = CGSizeMake(font_extents.max_x_advance, + font_extents.max_y_advance); + } + + //cairo_ft_scaled_font_unlock_face(self->cairofont); + + return maximum_advancement; +} + ++ (CGFontRef) createWithFontName: (CFStringRef)name; +{ + FcPattern *pat; + + pat = opal_FcPatternCacheLookup([(NSString*)name UTF8String]); + return [self createWithFcPattern: pat]; +} + ++ (CGFontRef) createWithFcPattern: (FcPattern *)pat +{ + cairo_font_face_t *unscaled; + CairoFontX11 *font = [[CairoFontX11 alloc] init]; + if (!font) return NULL; + + if (pat) + { + unscaled = cairo_ft_font_face_create_for_pattern(pat); + } + else + { + CGFontRelease(font); + return NULL; + } + + // Create a cairo_scaled_font which we just use to access the underlying + // FT_Face + + cairo_matrix_t ident; + cairo_matrix_init_identity(&ident); + + cairo_font_options_t *opts = cairo_font_options_create(); + cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); + + font->cairofont = cairo_scaled_font_create(unscaled, + &ident, &ident, opts); + + cairo_font_options_destroy(opts); + + font->fullName = [font copyFullName]; + font->postScriptName = [font copyPostScriptName]; + font->ascent = [font ascent]; + font->capHeight = [font capHeight]; + font->descent = [font descent]; + font->fontBBox = [font fontBBox]; + font->italicAngle = [font italicAngle]; + font->leading = [font leading]; + font->numberOfGlyphs = [font numberOfGlyphs]; + font->stemV = [font stemV]; + font->unitsPerEm = [font unitsPerEm]; + font->xHeight = [font xHeight]; + font->maximumAdvancement = [font maximumAdvancement]; + return (CGFontRef)font; +} + ++ (CGFontRef) createWithPlatformFont: (void *)platformFontReference; +{ + return NULL; +} + +//FIXME: Not threadsafe +- (bool) getGlyphAdvances: (const CGGlyph[])glyphs +: (size_t)count +: (int[]) advances +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + for (size_t i=0; iglyph->metrics.horiAdvance; + } + cairo_ft_scaled_font_unlock_face(self->cairofont); + return true; +} + +//FIXME: Not threadsafe +- (bool) getGlyphBBoxes: (const CGGlyph[])glyphs + : (size_t)count + : (CGRect[])bboxes +{ + FT_Face ft_face = cairo_ft_scaled_font_lock_face(self->cairofont); + for (size_t i=0; iglyph->metrics; + bboxes[i] = CGRectMake(m.horiBearingX, m.horiBearingY - m.height, m.width, + m.height); + } + cairo_ft_scaled_font_unlock_face(self->cairofont); + return true; +} + +@end + + + + + + + + + + +static FcPattern *opal_FcPatternCreateFromName(const char *name) +{ + char *family, *traits; + FcPattern *pat; + FcResult fcres; + FcBool success; + + if (!name) return NULL; + family = strdup(name); + pat = FcPatternCreate(); + if (!family || !pat) goto error; + + /* Try to parse a Postscript font name and make a corresponding pattern */ + /* Consider everything up to the first dash to be the family name */ + traits = strchr(family, '-'); + if (traits) + { + *traits = '\0'; + traits++; + } + success = FcPatternAddString(pat, FC_FAMILY, (FcChar8 *)family); + if (!success) goto error; + if (traits) + { + /* FIXME: The following is incomplete and may also be wrong */ + /* Fontconfig assumes Medium Roman Regular so don't care about theese */ + if (strstr(traits, "Bold")) + success |= FcPatternAddInteger(pat, FC_WEIGHT, FC_WEIGHT_BOLD); + if (strstr(traits, "Italic")) + success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_ITALIC); + if (strstr(traits, "Oblique")) + success |= FcPatternAddInteger(pat, FC_SLANT, FC_SLANT_OBLIQUE); + if (strstr(traits, "Condensed")) + success |= FcPatternAddInteger(pat, FC_WIDTH, FC_WIDTH_CONDENSED); + if (!success) goto error; + } + + success = FcConfigSubstitute(NULL, pat, FcMatchPattern); + if (!success) goto error; + FcDefaultSubstitute(pat); + pat = FcFontMatch(NULL, pat, &fcres); + if (!pat) goto error; + free(family); + return pat; + +error: + NSLog(@"opal_FcPatternCreateFromName failed"); + if (family) free (family); + if (pat) FcPatternDestroy(pat); + return NULL; +} + +#endif diff --git a/Source/OpalGraphics/internal/CGFontInternal.h b/Source/OpalGraphics/internal/CGFontInternal.h index e34174b..741ed3e 100644 --- a/Source/OpalGraphics/internal/CGFontInternal.h +++ b/Source/OpalGraphics/internal/CGFontInternal.h @@ -1,100 +1,100 @@ -/** CGFontInternal - - C Interface to graphics drawing library - - Copyright (C) 2006 Free Software Foundation, Inc. - - Author: BALATON Zoltan - Date: 2006 - 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 - */ - -#import -#include "CoreGraphics/CGFont.h" - -//FIXME: hack -#ifdef __MINGW__ -typedef void FcPattern; -#else -#include -#endif - -@interface CGFont : NSObject -{ -@public - CFStringRef fullName; - CFStringRef postScriptName; - int ascent; - int capHeight; - int descent; - CGRect fontBBox; - CGFloat italicAngle; - int leading; - size_t numberOfGlyphs; - CGFloat stemV; - int unitsPerEm; - int xHeight; - CGSize maximumAdvancement; -} - -- (bool) canCreatePostScriptSubset: (CGFontPostScriptFormat)format; - -- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph; - -- (CFDataRef) copyTableForTag: (uint32_t)tag; - -- (CFArrayRef) copyTableTags; - -- (CFArrayRef) copyVariationAxes; - -- (CFDictionaryRef) copyVariations; - -- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations; - -- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding; - -- (CFDataRef) createPostScriptSubset: (CFStringRef)name - : (CGFontPostScriptFormat)format - : (const CGGlyph[])glyphs - : (size_t)count - : (const CGGlyph[])encoding; - -+ (CGFontRef) createWithDataProvider: (CGDataProviderRef)provider; - -+ (CGFontRef) createWithFontName: (CFStringRef)name; - -#ifndef __MINGW__ // FIXME: proper check for fontconfig -+ (CGFontRef) createWithFcPattern: (FcPattern *)pat; -#endif - -+ (CGFontRef) createWithPlatformFont: (void *)platformFontReference; - - - -- (bool) getGlyphAdvances: (const CGGlyph[])glyphs -: (size_t)count -: (int[]) advances; - -- (bool) getGlyphBBoxes: (const CGGlyph[])glyphs -: (size_t)count -: (CGRect[])bboxes; - -- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; -- (CGGlyph) glyphWithCharacter: (unichar)character; - -@end +/** CGFontInternal + + C Interface to graphics drawing library + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: BALATON Zoltan + Date: 2006 + 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 + */ + +#import +#include "CoreGraphics/CGFont.h" + +//FIXME: hack +#ifdef __MINGW__ +typedef void FcPattern; +#else +#include +#endif + +@interface CGFont : NSObject +{ +@public + CFStringRef fullName; + CFStringRef postScriptName; + int ascent; + int capHeight; + int descent; + CGRect fontBBox; + CGFloat italicAngle; + int leading; + size_t numberOfGlyphs; + CGFloat stemV; + int unitsPerEm; + int xHeight; + CGSize maximumAdvancement; +} + +- (bool) canCreatePostScriptSubset: (CGFontPostScriptFormat)format; + +- (CFStringRef) copyGlyphNameForGlyph: (CGGlyph)glyph; + +- (CFDataRef) copyTableForTag: (uint32_t)tag; + +- (CFArrayRef) copyTableTags; + +- (CFArrayRef) copyVariationAxes; + +- (CFDictionaryRef) copyVariations; + +- (CGFontRef) createCopyWithVariations: (CFDictionaryRef)variations; + +- (CFDataRef) createPostScriptEncoding: (const CGGlyph[])encoding; + +- (CFDataRef) createPostScriptSubset: (CFStringRef)name + : (CGFontPostScriptFormat)format + : (const CGGlyph[])glyphs + : (size_t)count + : (const CGGlyph[])encoding; + ++ (CGFontRef) createWithDataProvider: (CGDataProviderRef)provider; + ++ (CGFontRef) createWithFontName: (CFStringRef)name; + +#ifndef __MINGW__ // FIXME: proper check for fontconfig ++ (CGFontRef) createWithFcPattern: (FcPattern *)pat; +#endif + ++ (CGFontRef) createWithPlatformFont: (void *)platformFontReference; + + + +- (bool) getGlyphAdvances: (const CGGlyph[])glyphs +: (size_t)count +: (int[]) advances; + +- (bool) getGlyphBBoxes: (const CGGlyph[])glyphs +: (size_t)count +: (CGRect[])bboxes; + +- (CGGlyph) glyphWithGlyphName: (CFStringRef)glyphName; +- (CGGlyph) glyphWithCharacter: (unichar)character; + +@end diff --git a/Source/OpalGraphics/opal-win32.m b/Source/OpalGraphics/opal-win32.m index f879d2c..d490559 100644 --- a/Source/OpalGraphics/opal-win32.m +++ b/Source/OpalGraphics/opal-win32.m @@ -1,57 +1,57 @@ -/** opal-win32 - - C Interface to graphics drawing library - - Copyright (C) 2010 Free Software Foundation, Inc. - - Author: Eric Wasylishen - Date: 2010 - - This file is part of GNUstep - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. - */ - -#ifdef __MINGW__ - -#include -#include -#include "CoreGraphics/CGContext.h" -#include "CGContext-private.h" -// TODO: add OpalWin32Context class -CGContextRef opal_Win32ContextCreate(HDC hdc) -{ - CGContextRef ctx; - cairo_surface_t *target; - RECT r; - - target = cairo_win32_surface_create(hdc); - - GetClipBox(hdc, &r); - - ctx = opal_new_CGContext(target, CGSizeMake(r.right - r.left, - r.bottom - r.top)); - - cairo_surface_destroy(target); - - return ctx; -} -// TODO: move to OpalWin32Context class -void opal_surface_flush(cairo_surface_t *target) -{ - cairo_surface_flush(target); -} - -#endif +/** opal-win32 + + C Interface to graphics drawing library + + Copyright (C) 2010 Free Software Foundation, Inc. + + Author: Eric Wasylishen + Date: 2010 + + This file is part of GNUstep + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + */ + +#ifdef __MINGW__ + +#include +#include +#include "CoreGraphics/CGContext.h" +#include "CGContext-private.h" +// TODO: add OpalWin32Context class +CGContextRef opal_Win32ContextCreate(HDC hdc) +{ + CGContextRef ctx; + cairo_surface_t *target; + RECT r; + + target = cairo_win32_surface_create(hdc); + + GetClipBox(hdc, &r); + + ctx = opal_new_CGContext(target, CGSizeMake(r.right - r.left, + r.bottom - r.top)); + + cairo_surface_destroy(target); + + return ctx; +} +// TODO: move to OpalWin32Context class +void opal_surface_flush(cairo_surface_t *target) +{ + cairo_surface_flush(target); +} + +#endif diff --git a/Tests/win32.m b/Tests/win32.m index 2bdbbba..a3489dd 100644 --- a/Tests/win32.m +++ b/Tests/win32.m @@ -1,81 +1,81 @@ -#import -#include -#include -#include - -#include - - -extern CGContextRef opal_Win32ContextCreate(HDC dc); -void draw(CGContextRef ctx, CGRect r); - -LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -{ - switch (msg) - { - case WM_PAINT: - { - PAINTSTRUCT ps; - RECT r; - GetClientRect(hwnd, &r); - HDC hdc = BeginPaint(hwnd, &ps); - - CGContextRef ctx = opal_Win32ContextCreate(hdc); - draw(ctx, CGRectMake(0, 0, r.right - r.left, r.bottom - r.top)); - CGContextRelease(ctx); - - EndPaint(hwnd, &ps); - break; - } - - case WM_DESTROY: - PostQuitMessage(0); - break; - - default: - return DefWindowProc(hwnd, msg, wparam, lparam); - } - return 0; -} - -APIENTRY int WinMain(HINSTANCE hInst, HINSTANCE x, LPSTR y, int nCmdShow) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - WNDCLASS wc; - HWND hwnd; - MSG msg; - const char *title = "Opal"; - - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = WindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInst; - wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME; - wc.lpszMenuName = NULL; - wc.lpszClassName = title; - - if (!RegisterClass(&wc)) - return 0; - - hwnd = CreateWindow(title, title, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, - NULL, NULL, hInst, NULL); - if (!hwnd) - return 0; - - ShowWindow(hwnd,nCmdShow); - UpdateWindow(hwnd); - - while (GetMessage(&msg, NULL, 0, 0) > 0) - { - NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; - TranslateMessage(&msg); - DispatchMessage(&msg); - [pool2 release]; - } - [pool release]; - return 0; -} +#import +#include +#include +#include + +#include + + +extern CGContextRef opal_Win32ContextCreate(HDC dc); +void draw(CGContextRef ctx, CGRect r); + +LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + switch (msg) + { + case WM_PAINT: + { + PAINTSTRUCT ps; + RECT r; + GetClientRect(hwnd, &r); + HDC hdc = BeginPaint(hwnd, &ps); + + CGContextRef ctx = opal_Win32ContextCreate(hdc); + draw(ctx, CGRectMake(0, 0, r.right - r.left, r.bottom - r.top)); + CGContextRelease(ctx); + + EndPaint(hwnd, &ps); + break; + } + + case WM_DESTROY: + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hwnd, msg, wparam, lparam); + } + return 0; +} + +APIENTRY int WinMain(HINSTANCE hInst, HINSTANCE x, LPSTR y, int nCmdShow) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + WNDCLASS wc; + HWND hwnd; + MSG msg; + const char *title = "Opal"; + + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = WindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInst; + wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME; + wc.lpszMenuName = NULL; + wc.lpszClassName = title; + + if (!RegisterClass(&wc)) + return 0; + + hwnd = CreateWindow(title, title, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, + NULL, NULL, hInst, NULL); + if (!hwnd) + return 0; + + ShowWindow(hwnd,nCmdShow); + UpdateWindow(hwnd); + + while (GetMessage(&msg, NULL, 0, 0) > 0) + { + NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; + TranslateMessage(&msg); + DispatchMessage(&msg); + [pool2 release]; + } + [pool release]; + return 0; +}