static ATSUStyle CreateSizedCopyOfStyle(ATSUStyle inStyle, cairo_matrix_t *scale) { ATSUStyle style; OSStatus err; // Set the style's size CGAffineTransform theTransform = CGAffineTransformMakeWithCairoFontScale(scale); Fixed theSize = FloatToFixed(CGSizeApplyAffineTransform (CGSizeMake(1.0, 1.0), theTransform).height); const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag }; const ByteCount theFontStyleSizes[] = { sizeof(Fixed) }; ATSUAttributeValuePtr theFontStyleValues[] = { &theSize }; err = ATSUCreateAndCopyStyle(inStyle, &style); err = ATSUSetAttributes(style, sizeof(theFontStyleTags) / sizeof(ATSUAttributeTag), theFontStyleTags, theFontStyleSizes, theFontStyleValues); return style; }
//----------------------------------------------------------------------------- void CGDrawContext::drawCGImageRef (CGContextRef context, CGImageRef image, CGLayerRef layer, double bitmapScaleFactor, const CRect& inRect, const CPoint& inOffset, float alpha, CBitmap* bitmap) { CRect rect (inRect); CPoint offset (inOffset); CGContextSetAlpha (context, (CGFloat)alpha*currentState.globalAlpha); CGRect dest; dest.origin.x = static_cast<CGFloat> (rect.left - offset.x); dest.origin.y = static_cast<CGFloat> (-(rect.top) - (bitmap->getHeight () - offset.y)); dest.size.width = static_cast<CGFloat> (bitmap->getWidth ()); dest.size.height = static_cast<CGFloat> (bitmap->getHeight ()); CGRect clipRect; clipRect.origin.x = static_cast<CGFloat> (rect.left); clipRect.origin.y = static_cast<CGFloat> (-(rect.top) - rect.getHeight ()); clipRect.size.width = static_cast<CGFloat> (rect.getWidth ()); clipRect.size.height = static_cast<CGFloat> (rect.getHeight ()); if (bitmapScaleFactor != 1.) { CGContextConcatCTM (context, CGAffineTransformMakeScale (static_cast<CGFloat> (1./bitmapScaleFactor), static_cast<CGFloat> (1./bitmapScaleFactor))); CGAffineTransform transform = CGAffineTransformMakeScale (static_cast<CGFloat> (bitmapScaleFactor), static_cast<CGFloat> (bitmapScaleFactor)); clipRect.origin = CGPointApplyAffineTransform (clipRect.origin, transform); clipRect.size = CGSizeApplyAffineTransform (clipRect.size, transform); dest.origin = CGPointApplyAffineTransform (dest.origin, transform); dest.size = CGSizeApplyAffineTransform (dest.size, transform); } dest = pixelAlligned (dest); clipRect = pixelAlligned (clipRect); CGContextClipToRect (context, clipRect); if (layer) { CGContextDrawLayerInRect (context, dest, layer); } else { CGContextDrawImage (context, dest, image); } }
FX_FLOAT CFX_QuartzDeviceDriver::getLineWidth(const CFX_GraphStateData * graphState, CGAffineTransform ctm) { FX_FLOAT lineWidth = graphState->m_LineWidth; if (graphState->m_LineWidth <= 0.f) { CGSize size; size.width = 1; size.height = 1; CGSize temp = CGSizeApplyAffineTransform(size, ctm); CGFloat x = 1 / temp.width; CGFloat y = 1 / temp.height; lineWidth = x > y ? x : y; } return lineWidth; }
void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, const Color& color, ColorSpace colorSpace) { if (paintingDisabled()) return; CGFloat xOffset = offset.width(); CGFloat yOffset = offset.height(); CGFloat blurRadius = blur; CGContextRef context = platformContext(); if (!m_state.shadowsIgnoreTransforms) { CGAffineTransform userToBaseCTM = wkGetUserToBaseCTM(context); CGFloat A = userToBaseCTM.a * userToBaseCTM.a + userToBaseCTM.b * userToBaseCTM.b; CGFloat B = userToBaseCTM.a * userToBaseCTM.c + userToBaseCTM.b * userToBaseCTM.d; CGFloat C = B; CGFloat D = userToBaseCTM.c * userToBaseCTM.c + userToBaseCTM.d * userToBaseCTM.d; CGFloat smallEigenvalue = narrowPrecisionToCGFloat(sqrt(0.5 * ((A + D) - sqrt(4 * B * C + (A - D) * (A - D))))); // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp blurRadius = min(blur * smallEigenvalue, narrowPrecisionToCGFloat(1000.0)); CGSize offsetInBaseSpace = CGSizeApplyAffineTransform(offset, userToBaseCTM); xOffset = offsetInBaseSpace.width; yOffset = offsetInBaseSpace.height; } // Work around <rdar://problem/5539388> by ensuring that the offsets will get truncated // to the desired integer. static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128); if (xOffset > 0) xOffset += extraShadowOffset; else if (xOffset < 0) xOffset -= extraShadowOffset; if (yOffset > 0) yOffset += extraShadowOffset; else if (yOffset < 0) yOffset -= extraShadowOffset; // Check for an invalid color, as this means that the color was not set for the shadow // and we should therefore just use the default shadow color. if (!color.isValid()) CGContextSetShadow(context, CGSizeMake(xOffset, yOffset), blurRadius); else CGContextSetShadowWithColor(context, CGSizeMake(xOffset, yOffset), blurRadius, cachedCGColor(color, colorSpace)); }
JNIEXPORT void JNICALL OS_NATIVE(CGSizeApplyAffineTransform) (JNIEnv *env, jclass that, jobject arg0, jfloatArray arg1, jobject arg2) { CGSize _arg0, *lparg0=NULL; jfloat *lparg1=NULL; CGSize _arg2, *lparg2=NULL; OS_NATIVE_ENTER(env, that, CGSizeApplyAffineTransform_FUNC); if (arg0) if ((lparg0 = getCGSizeFields(env, arg0, &_arg0)) == NULL) goto fail; if (arg1) if ((lparg1 = (*env)->GetFloatArrayElements(env, arg1, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = getCGSizeFields(env, arg2, &_arg2)) == NULL) goto fail; *(CGSize *)lparg2 = CGSizeApplyAffineTransform(*(CGSize *)lparg0, *(CGAffineTransform *)lparg1); fail: if (arg2 && lparg2) setCGSizeFields(env, arg2, lparg2); if (arg1 && lparg1) (*env)->ReleaseFloatArrayElements(env, arg1, lparg1, 0); OS_NATIVE_EXIT(env, that, CGSizeApplyAffineTransform_FUNC); }