Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/develop' into github-CGD2D
Browse files Browse the repository at this point in the history
Conflicts:
    Frameworks/CoreGraphics/CGBitmapImage.mm
    Frameworks/CoreGraphics/CGContext.mm
    Frameworks/QuartzCore/CALayer.mm
    Frameworks/UIKit/StarboardXaml/CompositorInterface.mm
    Frameworks/include/CGIWICBitmap.h
  • Loading branch information
DHowett committed Nov 10, 2016
2 parents 6d4e9d0 + 9c92bf2 commit 19715b6
Show file tree
Hide file tree
Showing 1,364 changed files with 38,683 additions and 16,433 deletions.
4 changes: 0 additions & 4 deletions Frameworks/AudioToolbox/CAFDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class CAFDecoder {
int64_t mNumberValidFrames;
int32_t mPrimingFrames;
int32_t mRemainderFrames;

uint8_t mPacketDescriptions[1]; // this is a variable length array of
// mNumberPackets elements
} CAFPacketTableHeader;

typedef struct CAFDataChunk { uint32_t mEditCount; } CAFDataChunk;
Expand All @@ -142,7 +139,6 @@ class CAFDecoder {
CAFAudioDescription cafDesc;
CAFPacketTableHeader cafPacketTbl;


ChannelStateList channelStates;

public:
Expand Down
11 changes: 7 additions & 4 deletions Frameworks/AudioToolbox/CAFDecoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ uint64_t int64Swap(uint64_t val) {
// clamp the number of packets to produce based on what is available in the
// input buffer
UInt32 inputPacketSize = mInputFormat.mBytesPerPacket;
UInt32 numberOfInputPackets = 1;
UInt32 numberOfInputPackets = ([stream hasBytesAvailable] ? 1 : 0);
if (ioNumberPackets < numberOfInputPackets) {
numberOfInputPackets = ioNumberPackets;
} else if (ioNumberPackets > numberOfInputPackets) {
Expand Down Expand Up @@ -267,7 +267,7 @@ uint64_t int64Swap(uint64_t val) {
isPcm = false;

while ([inStream hasBytesAvailable] && !stop) {
CAFChunkHeader chunkHeader;
CAFChunkHeader chunkHeader{};
[inStream read:(uint8_t*)&chunkHeader maxLength:sizeof(CAFChunkHeader)];
chunkHeader.mChunkType = int32Swap(chunkHeader.mChunkType);
chunkHeader.mChunkSize = int64Swap(chunkHeader.mChunkSize);
Expand Down Expand Up @@ -331,13 +331,16 @@ uint64_t int64Swap(uint64_t val) {
break;

default:
bytesToSkip.reserve(chunkHeader.mChunkSize);
bytesLeftUntilChunkEnd -= [inStream read:(uint8_t*)&bytesToSkip[0] maxLength:chunkHeader.mChunkSize];
if (chunkHeader.mChunkSize > 0) {
bytesToSkip.resize(chunkHeader.mChunkSize);
bytesLeftUntilChunkEnd -= [inStream read:(uint8_t*)&bytesToSkip[0] maxLength:chunkHeader.mChunkSize];
}
break;
}

if (!stop) {
if (bytesLeftUntilChunkEnd > 0) {
bytesToSkip.resize(bytesLeftUntilChunkEnd);
[inStream read:(uint8_t*)&bytesToSkip[0] maxLength:bytesLeftUntilChunkEnd];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ bool CGContextIsPointInPath(CGContextRef context, bool eoFill, CGFloat x, CGFloa
return StubReturn();
}

void CGContextDrawGlyphRun(CGContextRef context, const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
void CGContextDrawGlyphRun(CGContextRef context, const DWRITE_GLYPH_RUN* glyphRun) {
NOISY_RETURN_IF_NULL(context);
// TODO(DH) GH#1070 Merge in CGContextCairo.mm's Glyph Run code.
}
Expand Down
43 changes: 18 additions & 25 deletions Frameworks/CoreGraphics/CGContextCairo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@
*
* @parameter glyphRun DWRITE_GLYPH_RUN object to render
*/
void CGContextCairo::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
void CGContextCairo::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun) {
ObtainLock();

CGContextStrokePath();
Expand All @@ -1850,32 +1850,25 @@

// Apply the text transformation (text position, text matrix) in text space rather than user space
// This means flipping the coordinate system,
// and applying the transformation about the center of the glyph run rather than about the baseline
// Flip and translate by the difference between the center and the baseline, apply text transforms, then flip and translate back

// Transform to text space
// Technically there should be a horizontal translation to the center as well,
// but it's to the center of _each individual glyph_, as the reference platform applies the text matrix to each glyph individually
// Uncertain whether it's ever going to be worth it to support this using DWrite, so just ignore it for now
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, -1, 0, lineAscent / 2.0f);

// Apply text transforms
transform = CGAffineTransformConcat(curState->curTextMatrix, transform);
transform = CGAffineTransformTranslate(transform, curState->curTextPosition.x, curState->curTextPosition.y);

// Undo transform to text space
transform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, -lineAscent / 2.0f), transform);

// Apply the context CTM
transform = CGAffineTransformConcat(curState->curTransform, transform);

// Perform translation required to handle scaling.
CGFloat verticalScalingFactor = sqrt((transform.b * transform.b) + (transform.d * transform.d));
// Apply text position, where it will be translated to correct position given text matrix value
CGAffineTransform textTransform =
CGAffineTransformTranslate(curState->curTextMatrix, curState->curTextPosition.x, curState->curTextPosition.y);

// Undo assumed inversion about Y axis
textTransform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, 0), textTransform);

// Find transform that user created by multiplying given transform by necessary transforms to draw with CoreText
// First multiply by inverse scale to get properly scaled values
// Then undo assumed inversion about Y axis
// Finally inverse translate by height
// All of which are rolled into one concatenation
float height = _imgDest->Backing()->Height();
transform = CGAffineTransformTranslate(transform, 0, (height / verticalScalingFactor));
CGAffineTransform userTransform =
CGAffineTransformConcat(curState->curTransform, CGAffineTransformMake(1.0f / _scale, 0, 0, -1.0f / _scale, 0, height / _scale));

// Perform anti-clockwise rotation required to match the reference platform.
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, -transform.b, transform.c, transform.d, transform.tx, transform.ty));
// Apply the two transforms giving us the final result
CGAffineTransform transform = CGAffineTransformConcat(textTransform, userTransform);
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty));

// Draw the glyph using ID2D1RenderTarget
ComPtr<ID2D1SolidColorBrush> brush;
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/CoreGraphics/CGContextImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@
return NULL;
}

void CGContextImpl::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun, float lineAscent) {
void CGContextImpl::CGContextDrawGlyphRun(const DWRITE_GLYPH_RUN* glyphRun) {
}

// TODO 1077:: Remove once D2D render target is implemented
Expand Down
8 changes: 8 additions & 0 deletions Frameworks/CoreGraphics/DWriteWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ HRESULT _DWriteCreateFontFaceWithName(CFStringRef name, IDWriteFontFace** outFon
// Eg: Bold, Condensed, Light, Italic
_DWriteFontProperties properties = _DWriteGetFontPropertiesFromName(name);

// TODO: #1250: Need to be able to load fonts from the app's bundle
// For now return a default font to avoid crashes in case of missing fonts
// When #1250 is completed, remove this
if (!properties.familyName) {
name = CFSTR("Segoe UI");
properties = _DWriteGetFontPropertiesFromName(name);
}

RETURN_HR_IF_NULL(E_INVALIDARG, properties.familyName);

ComPtr<IDWriteFontFamily> fontFamily;
Expand Down
67 changes: 49 additions & 18 deletions Frameworks/CoreText/CTFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ CTFontRef CTFontCreateUIFontForLanguage(CTFontUIFontType uiType, CGFloat size, C
@Notes matrix parameter stored but not used
*/
CTFontRef CTFontCreateCopyWithAttributes(CTFontRef font, CGFloat size, const CGAffineTransform* matrix, CTFontDescriptorRef attributes) {
if (!font) {
return nullptr;
}
RETURN_NULL_IF(!font);

CFDictionaryRef originalAttributes = CTFontDescriptorCopyAttributes(font->_descriptor);
CFAutorelease(originalAttributes);
Expand Down Expand Up @@ -352,9 +350,7 @@ CTFontRef CTFontCreateCopyWithSymbolicTraits(
@Notes matrix parameter stored but not used
*/
CTFontRef CTFontCreateCopyWithFamily(CTFontRef font, CGFloat size, const CGAffineTransform* matrix, CFStringRef family) {
if (!font) {
return nullptr;
}
RETURN_NULL_IF(!font);

CFMutableDictionaryRef attributesToUse = __CTFontCopyAutoreleasedMutableAttributes(font);

Expand Down Expand Up @@ -395,9 +391,7 @@ CTFontDescriptorRef CTFontCopyFontDescriptor(CTFontRef font) {
@Notes
*/
CFTypeRef CTFontCopyAttribute(CTFontRef font, CFStringRef attribute) {
if (!font) {
return nullptr;
}
RETURN_NULL_IF(!font);
return CTFontDescriptorCopyAttribute(font->_descriptor, attribute);
}

Expand Down Expand Up @@ -451,9 +445,7 @@ CTFontSymbolicTraits CTFontGetSymbolicTraits(CTFontRef font) {
@Notes
*/
CFDictionaryRef CTFontCopyTraits(CTFontRef font) {
if (!font) {
return nullptr;
}
RETURN_NULL_IF(!font);
return static_cast<CFDictionaryRef>(CTFontDescriptorCopyAttribute(font->_descriptor, kCTFontTraitsAttribute));
}

Expand Down Expand Up @@ -492,9 +484,7 @@ CFStringRef CTFontCopyDisplayName(CTFontRef font) {
@Status Interoperable
*/
CFStringRef CTFontCopyName(CTFontRef font, CFStringRef nameKey) {
if (!font) {
return nullptr;
}
RETURN_NULL_IF(!font);
return _DWriteFontCopyName(font->_dwriteFontFace, nameKey);
}

Expand Down Expand Up @@ -689,12 +679,26 @@ CGFloat CTFontGetXHeight(CTFontRef font) {
}

/**
@Status Stub
@Status Interoperable
@Notes
*/
CGPathRef CTFontCreatePathForGlyph(CTFontRef font, CGGlyph glyph, const CGAffineTransform* matrix) {
UNIMPLEMENTED();
return StubReturn();
RETURN_NULL_IF(!font);

CGAffineTransform fontMatrix = CTFontGetMatrix(font); // Defaults to identity matrix

// Do not apply the translation portions of fontMatrix to the path
fontMatrix.tx = 0;
fontMatrix.ty = 0;

// fontMatrix is applied before the matrix parameter, if one is specified
CGAffineTransform matrixToUse = matrix ? CGAffineTransformConcat(fontMatrix, *matrix) : fontMatrix;

// Pass no transform if matrixToUse ends up being the identity
return _DWriteFontCreatePathForGlyph(font->_dwriteFontFace,
font->_pointSize,
glyph,
CGAffineTransformIsIdentity(matrixToUse) ? nullptr : &matrixToUse);
}

/**
Expand Down Expand Up @@ -902,4 +906,31 @@ CFDataRef CTFontCopyTable(CTFontRef font, CTFontTableTag table, CTFontTableOptio
CFTypeID CTFontGetTypeID() {
static CFTypeID __kCTFontTypeID = _CFRuntimeRegisterClass(&__CTFontClass);
return __kCTFontTypeID;
}

// Private function for getting font weight for XAML
DWRITE_FONT_WEIGHT _CTFontGetDWriteWeight(CTFontRef font) {
ComPtr<IDWriteFontFace3> fontFace3;
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
return fontFace3->GetWeight();
}
return DWRITE_FONT_WEIGHT_NORMAL;
}

// Private function for getting font stretch for XAML
DWRITE_FONT_STRETCH _CTFontGetDWriteStretch(CTFontRef font) {
ComPtr<IDWriteFontFace3> fontFace3;
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
return fontFace3->GetStretch();
}
return DWRITE_FONT_STRETCH_NORMAL;
}

// Private function for getting font style for XAML
DWRITE_FONT_STYLE _CTFontGetDWriteStyle(CTFontRef font) {
ComPtr<IDWriteFontFace3> fontFace3;
if (font && SUCCEEDED(font->_dwriteFontFace.As(&fontFace3))) {
return fontFace3->GetStyle();
}
return DWRITE_FONT_STYLE_NORMAL;
}
12 changes: 7 additions & 5 deletions Frameworks/CoreText/CTFrame.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ CFRange CTFrameGetVisibleStringRange(CTFrameRef frame) {
_CTFrame* framePtr = static_cast<_CTFrame*>(frame);
CFIndex count = 0;
if (framePtr) {
for (_CTLine* line in static_cast<id<NSFastEnumeration>>(framePtr->_lines)) {
if (line->_lineOrigin.y < framePtr->_frameRect.size.height && line->_lineOrigin.y > 0) {
for (size_t i = 0; i < framePtr->_lineOrigins.size(); ++i) {
if (framePtr->_lineOrigins[i].y < framePtr->_frameRect.size.height) {
_CTLine* line = static_cast<_CTLine*>([framePtr->_lines objectAtIndex:i]);
count += line->_strRange.length;
}
}
Expand Down Expand Up @@ -120,9 +121,10 @@ void CTFrameDraw(CTFrameRef frameRef, CGContextRef ctx) {
CGContextSetTextMatrix(ctx, CGAffineTransformScale(textMatrix, 1.0f, -1.0f));
CGContextScaleCTM(ctx, 1.0f, -1.0f);

for (_CTLine* line in static_cast<id<NSFastEnumeration>>(frame->_lines)) {
CGContextSetTextPosition(ctx, line->_lineOrigin.x, line->_lineOrigin.y);
_CTLineDraw(static_cast<CTLineRef>(line), ctx, false);
for (size_t i = 0; i < frame->_lineOrigins.size(); ++i) {
_CTLine* line = static_cast<_CTLine*>([frame->_lines objectAtIndex:i]);
CGContextSetTextPosition(ctx, frame->_lineOrigins[i].x, -frame->_lineOrigins[i].y);
CTLineDraw(static_cast<CTLineRef>(line), ctx);
}

// Restore CTM and Text Matrix to values before we modified them
Expand Down
58 changes: 54 additions & 4 deletions Frameworks/CoreText/CTFramesetter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,66 @@
@implementation _CTFramesetter : NSObject
@end

static _CTFrame* __CreateFrame(_CTFramesetter* framesetter, CGRect frameSize, CFRange range) {
RETURN_NULL_IF(!framesetter);
static _CTFrame* __CreateFrame(_CTFramesetter* framesetter, CGRect frameRect, CFRange range) {
RETURN_NULL_IF(framesetter == nil);

// Call _DWriteWrapper to get _CTLine object list that makes up this frame
_CTTypesetter* typesetter = static_cast<_CTTypesetter*>(framesetter->_typesetter);
if (range.length == 0L) {
range.length = typesetter->_characters.size();
}

return [_DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameSize) retain];
StrongId<_CTFrame> ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameRect);

// Trying to access attributes without any text will throw an error
if (range.length <= 0L) {
return ret.detach();
}

CTParagraphStyleRef settings = static_cast<CTParagraphStyleRef>(
[typesetter->_attributedString attribute:static_cast<NSString*>(kCTParagraphStyleAttributeName) atIndex:0 effectiveRange:nullptr]);

if (settings == nil) {
return ret.detach();
}

// DWrite only gives manual control of lineheight when it is constant through a frame
// We need to shift each line by the difference in lineheight manually
CGFloat lineHeightMultiple = 0.0f;
if (CTParagraphStyleGetValueForSpecifier(settings,
kCTParagraphStyleSpecifierLineHeightMultiple,
sizeof(lineHeightMultiple),
&lineHeightMultiple) &&
lineHeightMultiple > 0) {
// The actual ratio we need to change the line height by is lineHeightMultiple - 1
lineHeightMultiple -= 1.0f;
CGFloat totalShifted = 0.0f;
CGFloat lastOriginY = frameRect.origin.y;
for (size_t i = 0; i < ret->_lineOrigins.size(); ++i) {
totalShifted += lineHeightMultiple * (ret->_lineOrigins[i].y - lastOriginY);
lastOriginY = ret->_lineOrigins[i].y;
ret->_lineOrigins[i].y += totalShifted;
}

// Adjust framesize to account for changes in lineheights
ret->_frameRect.size.height += totalShifted;
}

// CoreText binds the origin of each line to the left for clipped lines no matter the writing direction / alignment
// TODO 1121:: DWrite does not support line breaking by truncation, so we are using clipping, so need to adjust for truncation as well
CTLineBreakMode lineBreakMode;
if (CTParagraphStyleGetValueForSpecifier(settings, kCTParagraphStyleSpecifierLineBreakMode, sizeof(lineBreakMode), &lineBreakMode) &&
(lineBreakMode == kCTLineBreakByClipping || lineBreakMode == kCTLineBreakByTruncatingHead ||
lineBreakMode == kCTLineBreakByTruncatingTail || lineBreakMode == kCTLineBreakByTruncatingMiddle)) {
for (size_t i = 0; i < ret->_lineOrigins.size(); ++i) {
if (CTLineGetTypographicBounds(static_cast<CTLineRef>([ret->_lines objectAtIndex:i]), nullptr, nullptr, nullptr) >
frameRect.size.width) {
ret->_lineOrigins[i].x = frameRect.origin.x;
}
}
}

return ret.detach();
}

/**
Expand Down Expand Up @@ -96,4 +146,4 @@ CGSize CTFramesetterSuggestFrameSizeWithConstraints(
CFTypeID CTFramesetterGetTypeID() {
UNIMPLEMENTED();
return StubReturn();
}
}
Loading

0 comments on commit 19715b6

Please sign in to comment.