Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions Headers/CoreGraphics/CGContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ enum {
};
typedef int CGTextEncoding;

// NOTE: This `typedef enum` in opposition to defining enum constants and
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you find these values? As WebKit has its own definitions of these values we should kept them private within Opal.

// their types as integers is here to maintain compatibility with the original
// CoreGraphics API, although this is *NOT* an ideal way to define these types.
typedef enum {
kCGContextTypeUnknown,
kCGContextTypePDF,
kCGContextTypePostScript,
kCGContextTypeWindow,
kCGContextTypeBitmap,
kCGContextTypeGL,
kCGContextTypeDisplayList,
kCGContextTypeKSeparation,
kCGContextTypeIOSurface,
kCGContextTypeCount
} CGContextType;

/* Functions */

/* Managing Graphics Contexts */
Expand Down Expand Up @@ -562,6 +578,31 @@ CGRect CGContextConvertRectToDeviceSpace(CGContextRef ctx, CGRect rect);

CGRect CGContextConvertRectToUserSpace(CGContextRef ctx, CGRect rect);

bool CGContextPathContainsPoint(CGContextRef c,
CGPoint point, CGPathDrawingMode mode);

/* CoreGraphics Private APIs */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are not part of the public API, I propose we move them into a separate header + implementation file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function gets exported by the Apple implementation as well. Having it here is fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I selected line 584 when I was creating the commit, not my fault that GitHub has... flaws. 😄

I was referring to all the APIs below that were marked as private. I did not check any to be private except CGContextSetCTM()


bool CGContextGetShouldSmoothFonts(CGContextRef ctx);

bool CGContextGetShouldAntialias(CGContextRef ctx);

CGContextType CGContextGetType(CGContextRef ctx);

void CGContextSetCTM(CGContextRef ctx, CGAffineTransform m);
Copy link
Copy Markdown
Member

@fredkiefer fredkiefer Aug 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two are the one functions I cannot find in the Apple header, these should be moved away.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of these, it looks like only CGContextGetShouldAntialias() is public.


CGAffineTransform CGContextGetBaseCTM(CGContextRef);

void CGContextSetBaseCTM(CGContextRef, CGAffineTransform);

CGColorSpaceRef CGContextCopyDeviceColorSpace(CGContextRef);

void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);

bool CGDisplayUsesInvertedPolarity(void);

bool CGDisplayUsesForceToGray(void);

/* Opal Extensions */

// FIXME: Move extensions to a separate header?
Expand All @@ -583,9 +624,6 @@ OPGStateRef OPContextCopyGState(CGContextRef ctx);

void OPContextSetGState(CGContextRef ctx, OPGStateRef gstate);

bool CGContextPathContainsPoint(CGContextRef c,
CGPoint point, CGPathDrawingMode mode);

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 11 additions & 0 deletions Headers/CoreGraphics/CGFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct CGFont* CGFontRef;
#endif

#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGAffineTransform.h>
#include <CoreGraphics/CGGeometry.h>
#include <CoreGraphics/CGDataProvider.h>

Expand Down Expand Up @@ -154,6 +155,16 @@ CGFontRef CGFontRetain(CGFontRef font);

void CGFontRelease(CGFontRef font);

/* Private Functions */

bool CGFontGetGlyphAdvancesForStyle(
CGFontRef,
const CGAffineTransform*,
int,
const CGGlyph[],
size_t count,
CGSize advances[]);

/* Extensions */

#ifndef __MINGW__ // FIXME: proper check for fontconfig
Expand Down
9 changes: 9 additions & 0 deletions Headers/CoreGraphics/CGImageSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const extern CFStringRef kCGImageSourceCreateThumbnailFromImageAlways;
const extern CFStringRef kCGImageSourceThumbnailMaxPixelSize;
const extern CFStringRef kCGImageSourceCreateThumbnailWithTransform;

const extern CFStringRef kCGImageSourceShouldPreferRGB32;
const extern CFStringRef kCGImageSourceSkipMetadata;
const extern CFStringRef kCGImageSourceSubsampleFactor;
const extern CFStringRef kCGImageSourceShouldCacheImmediately;

/* Data Types */

#ifdef INTERNAL_BUILD_OBJC
Expand Down Expand Up @@ -139,6 +144,10 @@ void CGImageSourceUpdateDataProvider(

CFTypeID CGImageSourceGetTypeID();

/* Private APIs */

CFStringRef CGImageSourceGetTypeWithData(CFDataRef, CFStringRef, bool*);

#ifdef __cplusplus
}
#endif
Expand Down
31 changes: 31 additions & 0 deletions Headers/CoreText/CTFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,37 @@ CFTypeID CTFontGetTypeID();
CTFontDescriptorRef CTFontManagerCreateFontDescriptorFromData(
CFDataRef data);

/* Private APIs */

bool CTFontGetVerticalGlyphsForCharacters(
CTFontRef,
const UniChar characters[],
CGGlyph glyphs[],
CFIndex count);

bool CTFontTransformGlyphs(
CTFontRef,
CGGlyph glyphs[],
CGSize advances[],
CFIndex count,
int);

CTFontRef CTFontCreateForCSS(
CFStringRef name,
uint16_t weight,
CTFontSymbolicTraits,
CGFloat size);

CTFontRef CTFontCreateForCharactersWithLanguage(
CTFontRef currentFont,
const UTF16Char *characters,
CFIndex length,
CFStringRef language, CFIndex *coveredLength);

extern const CFStringRef kCTFontReferenceURLAttribute;
extern const CFStringRef kCTFontOpticalSizeAttribute;
extern const CFStringRef kCTFontPostScriptNameAttribute;

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Headers/CoreText/CTFontDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ CFTypeRef CTFontDescriptorCopyLocalizedAttribute(

CFTypeID CTFontDescriptorGetTypeID();

bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions Headers/CoreText/CTLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ CGRect CTLineGetBoundsWithOptions(
CTLineRef line,
CTLineBoundsOptions options);

/* Private APIs */

typedef const UniChar* (*CTUniCharProviderCallback)(
CFIndex stringIndex,
CFIndex* charCount,
CFDictionaryRef* attributes,
void* refCon);
typedef void (*CTUniCharDisposeCallback)(const UniChar* chars, void* refCon);

CTLineRef CTLineCreateWithUniCharProvider(
CTUniCharProviderCallback provide,
CTUniCharDisposeCallback dispose,
void* refCon);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 10 additions & 0 deletions Headers/CoreText/CTRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ void CTRunDraw(

CFTypeID CTRunGetTypeID();

/* Private APIs */

CGSize CTRunGetInitialAdvance(CTRunRef run);

void CTRunGetBaseAdvancesAndOrigins(
CTRunRef,
CFRange,
CGSize baseAdvances[],
CGPoint origins[]);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions Headers/CoreText/CTTypesetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ CFIndex CTTypesetterSuggestLineBreak(

CFTypeID CTTypesetterGetTypeID();

CTTypesetterRef CTTypesetterCreateWithUniCharProviderAndOptions(
CTUniCharProviderCallback provide,
CTUniCharDisposeCallback dispose,
void* refCon,
CFDictionaryRef options);

#ifdef __cplusplus
}
#endif
Expand Down
88 changes: 85 additions & 3 deletions Source/OpalGraphics/CGContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ CGAffineTransform CGContextGetCTM(CGContextRef ctx)
return CGAffineTransformMake(result.xx, result.yx, result.xy, result.yy, result.x0, result.y0);
}

void CGContextSetCTM(CGContextRef ctx, CGAffineTransform m)
{
// FIXME: it looks like we do not need to do anything related to the
// flip transformation here like in GetCTM() above, but we may be wrong
// here.
cairo_matrix_t cairoMatrix;
cairo_matrix_init(&cairoMatrix, m.a, m.b, m.c, m.d, m.tx, m.ty);
cairo_set_matrix(ctx->ct, &cairoMatrix);
}

void OPContextSetCairoDeviceOffset(CGContextRef ctx, CGFloat x, CGFloat y)
{
OPLOGCALL("ctx /*%p*/, %g, %g", ctx, x, y)
Expand Down Expand Up @@ -377,6 +387,11 @@ void CGContextSetShouldAntialias(CGContextRef ctx, int shouldAntialias)
OPRESTORELOGGING()
}

bool CGContextGetShouldAntialias(CGContextRef ctx)
{
return cairo_get_antialias(ctx->ct) != CAIRO_ANTIALIAS_NONE;
}

void CGContextSetLineWidth(CGContextRef ctx, CGFloat width)
{
OPLOGCALL("ctx /*%p*/, %g", ctx, width)
Expand Down Expand Up @@ -480,6 +495,11 @@ void CGContextSetShouldSmoothFonts(CGContextRef ctx, int shouldSmoothFonts)
OPRESTORELOGGING()
}

bool CGContextGetShouldSmoothFonts(CGContextRef ctx)
{
return false;
}

void CGContextSetAllowsFontSmoothing(CGContextRef ctx, bool allowsFontSmoothing)
{
OPLOGCALL("ctx /*%p*/, %s", ctx, allowsFontSmoothing ? "true" : "false")
Expand Down Expand Up @@ -772,7 +792,11 @@ 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,
rect.size.width, rect.size.height)
rect.size.width, rect.size.height);
CGPathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, rect);
CGContextAddPath(ctx, path);
CGPathRelease(path);
OPRESTORELOGGING()
}

Expand Down Expand Up @@ -953,6 +977,20 @@ void CGContextClearRect(CGContextRef ctx, CGRect rect)
OPRESTORELOGGING()
}

void CGContextFillEllipseInRect(CGContextRef ctx, CGRect rect)
{
CGContextBeginPath(ctx);
CGContextAddEllipseInRect(ctx, rect);
CGContextFillPath(ctx);
}

void CGContextStrokeEllipseInRect(CGContextRef ctx, CGRect rect)
{
CGContextBeginPath(ctx);
CGContextAddEllipseInRect(ctx, rect);
CGContextStrokePath(ctx);
}

void CGContextStrokeLineSegments(
CGContextRef ctx,
const CGPoint points[],
Expand Down Expand Up @@ -1526,8 +1564,11 @@ void CGContextDrawRadialGradient(

void CGContextDrawShading(
CGContextRef ctx,
CGShadingRef shading
);
CGShadingRef shading)
{
// FIXME: unimplemented
return;
}

void CGContextSetFont(CGContextRef ctx, CGFontRef font)
{
Expand Down Expand Up @@ -1956,6 +1997,47 @@ CGRect CGContextConvertRectToUserSpace(CGContextRef ctx, CGRect rect)
CGAffineTransformInvert(CGContextGetUserSpaceToDeviceSpaceTransform(ctx)));
}

CGContextType CGContextGetType(CGContextRef ctx)
{
// NOTE: This is not wrong, since Opal does not currently seem to support
// any other context type.
return kCGContextTypeBitmap;
}

CGAffineTransform CGContextGetBaseCTM(CGContextRef ctx)
{
// FIXME: unimplemented
return (CGAffineTransform){0, 0, 0, 0, 0, 0};
}

void CGContextSetBaseCTM(CGContextRef ctx, CGAffineTransform m)
{
// FIXME: unimplemented
}

CGColorSpaceRef CGContextCopyDeviceColorSpace(CGContextRef ctx)
{
// FIXME: unimplemented
return NULL;
}

void CGContextSetShouldAntialiasFonts(CGContextRef ctx, bool shouldAntialiasFonts)
{
// FIXME: unimplemented
}

bool CGDisplayUsesInvertedPolarity(void)
{
// FIXME: unimplemented
return false;
}

bool CGDisplayUsesForceToGray(void)
{
// FIXME: unimplemented
return false;
}

void OpalContextSetScaleFactor(CGContextRef ctx, CGFloat scale)
{
if (scale == 0)
Expand Down
12 changes: 12 additions & 0 deletions Source/OpalGraphics/CGFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,15 @@ CGGlyph OPFontGetGlyphWithCharacter(CGFontRef font, unichar character)
{
return [font glyphWithCharacter: character];
}

bool CGFontGetGlyphAdvancesForStyle(
CGFontRef font,
const CGAffineTransform *m,
int renderingStyle,
const CGGlyph glyphs[],
size_t count,
CGSize advances[])
{
// FIXME: unimplemented
return false;
}
18 changes: 18 additions & 0 deletions Source/OpalGraphics/CGImageSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
const CFStringRef kCGImageSourceThumbnailMaxPixelSize = @"kCGImageSourceThumbnailMaxPixelSize";
const CFStringRef kCGImageSourceCreateThumbnailWithTransform = @"kCGImageSourceCreateThumbnailWithTransform";

const CFStringRef kCGImageSourceShouldPreferRGB32 =
@"kCGImageSourceShouldPreferRGB32";
const CFStringRef kCGImageSourceSkipMetadata =
@"kCGImageSourceSkipMetadata";
const CFStringRef kCGImageSourceSubsampleFactor =
@"kCGImageSourceSubsampleFactor";
const CFStringRef kCGImageSourceShouldCacheImmediately =
@"kCGImageSourceShouldCacheImmediately";


static NSMutableArray *sourceClasses = nil;

Expand Down Expand Up @@ -354,6 +363,15 @@ CFStringRef CGImageSourceGetType(CGImageSourceRef source)
return [source type];
}

CFStringRef CGImageSourceGetTypeWithData(
CFDataRef data,
CFStringRef string,
bool* result)
{
// FIXME: unimplemented
return NULL;
}

void CGImageSourceUpdateData(
CGImageSourceRef source,
CFDataRef data,
Expand Down
Loading