本文整理汇总了C++中AffineTransform::a方法的典型用法代码示例。如果您正苦于以下问题:C++ AffineTransform::a方法的具体用法?C++ AffineTransform::a怎么用?C++ AffineTransform::a使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AffineTransform
的用法示例。
在下文中一共展示了AffineTransform::a方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeLineBoundsAndAntialiasingModeForText
FloatRect GraphicsContext::computeLineBoundsAndAntialiasingModeForText(const FloatPoint& point, float width, bool printing, Color& color)
{
FloatPoint origin = point;
float thickness = std::max(strokeThickness(), 0.5f);
if (printing)
return FloatRect(origin, FloatSize(width, thickness));
AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
// Just compute scale in x dimension, assuming x and y scales are equal.
float scale = transform.b() ? sqrtf(transform.a() * transform.a() + transform.b() * transform.b()) : transform.a();
if (scale < 1.0) {
// This code always draws a line that is at least one-pixel line high,
// which tends to visually overwhelm text at small scales. To counter this
// effect, an alpha is applied to the underline color when text is at small scales.
static const float minimumUnderlineAlpha = 0.4f;
float shade = scale > minimumUnderlineAlpha ? scale : minimumUnderlineAlpha;
int alpha = color.alpha() * shade;
color = Color(color.red(), color.green(), color.blue(), alpha);
}
FloatPoint devicePoint = transform.mapPoint(point);
// Visual overflow might occur here due to integral roundf/ceilf. visualOverflowForDecorations adjusts the overflow value for underline decoration.
FloatPoint deviceOrigin = FloatPoint(roundf(devicePoint.x()), ceilf(devicePoint.y()));
if (auto inverse = transform.inverse())
origin = inverse.value().mapPoint(deviceOrigin);
return FloatRect(origin, FloatSize(width, thickness));
}
示例2: computeLineBoundsAndAntialiasingModeForText
FloatRect GraphicsContext::computeLineBoundsAndAntialiasingModeForText(const FloatPoint& point, float width, bool printing, bool& shouldAntialias, Color& color)
{
FloatPoint origin = point;
float thickness = std::max(strokeThickness(), 0.5f);
shouldAntialias = true;
if (!printing) {
AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
if (transform.preservesAxisAlignment())
shouldAntialias = false;
// This code always draws a line that is at least one-pixel line high,
// which tends to visually overwhelm text at small scales. To counter this
// effect, an alpha is applied to the underline color when text is at small scales.
// Just compute scale in x dimension, assuming x and y scales are equal.
float scale = transform.b() ? sqrtf(transform.a() * transform.a() + transform.b() * transform.b()) : transform.a();
if (scale < 1.0) {
static const float minimumUnderlineAlpha = 0.4f;
float shade = scale > minimumUnderlineAlpha ? scale : minimumUnderlineAlpha;
int alpha = color.alpha() * shade;
color = Color(color.red(), color.green(), color.blue(), alpha);
}
FloatPoint devicePoint = transform.mapPoint(point);
FloatPoint deviceOrigin = FloatPoint(roundf(devicePoint.x()), ceilf(devicePoint.y()));
if (auto inverse = transform.inverse())
origin = inverse.value().mapPoint(deviceOrigin);
}
return FloatRect(origin.x(), origin.y(), width, thickness);
}
示例3: applyResultsToTarget
void SVGAnimateMotionElement::applyResultsToTarget()
{
// We accumulate to the target element transform list so there is not much to do here.
SVGElement* targetElement = this->targetElement();
if (!targetElement)
return;
if (RenderObject* renderer = targetElement->renderer())
RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
AffineTransform* t = targetElement->supplementalTransform();
if (!t)
return;
// ...except in case where we have additional instances in <use> trees.
const HashSet<SVGElementInstance*>& instances = targetElement->instancesForElement();
const HashSet<SVGElementInstance*>::const_iterator end = instances.end();
for (HashSet<SVGElementInstance*>::const_iterator it = instances.begin(); it != end; ++it) {
SVGElement* shadowTreeElement = (*it)->shadowTreeElement();
ASSERT(shadowTreeElement);
AffineTransform* transform = shadowTreeElement->supplementalTransform();
if (!transform)
continue;
transform->setMatrix(t->a(), t->b(), t->c(), t->d(), t->e(), t->f());
if (RenderObject* renderer = shadowTreeElement->renderer()) {
renderer->setNeedsTransformUpdate();
RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
}
}
}
示例4: concatCTM
void GraphicsContext::concatCTM(const AffineTransform& affine)
{
if (paintingDisabled())
return;
//platformContext()->canvas()->concat(affine);
nvgTransform(platformContext()->canvas(), affine.a(), affine.b(), affine.c(), affine.d(), affine.e(), affine.f());
}
示例5: aAttrGetter
static v8::Handle<v8::Value> aAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
INC_STATS("DOM.AffineTransform.a._get");
V8SVGPODTypeWrapper<AffineTransform>* impWrapper = V8SVGPODTypeWrapper<AffineTransform>::toNative(info.Holder());
AffineTransform impInstance = *impWrapper;
AffineTransform* imp = &impInstance;
return v8::Number::New(imp->a());
}
示例6: valueAsString
String SVGTransformList::valueAsString() const
{
// TODO: We may want to build a real transform string, instead of concatting to a matrix(...).
SVGTransform transform = concatenate();
if (transform.type() == SVGTransform::SVG_TRANSFORM_MATRIX) {
AffineTransform matrix = transform.matrix();
return String::format("matrix(%f %f %f %f %f %f)", matrix.a(), matrix.b(), matrix.c(), matrix.d(), matrix.e(), matrix.f());
}
return String();
}
示例7:
// static
void Shader::affineTo3x3(const AffineTransform& transform, float mat[9])
{
mat[0] = transform.a();
mat[1] = transform.b();
mat[2] = 0.0f;
mat[3] = transform.c();
mat[4] = transform.d();
mat[5] = 0.0f;
mat[6] = transform.e();
mat[7] = transform.f();
mat[8] = 1.0f;
}
示例8: if
static inline void normalizeTransform(AffineTransform& transform)
{
// Obtain consistent numerical results for the AffineTransform on both 32/64bit platforms.
// Tested with SnowLeopard on Core Duo vs. Core 2 Duo.
static const float s_floatEpsilon = std::numeric_limits<float>::epsilon();
if (fabs(transform.a() - 1) <= s_floatEpsilon)
transform.setA(1);
else if (fabs(transform.a() + 1) <= s_floatEpsilon)
transform.setA(-1);
if (fabs(transform.d() - 1) <= s_floatEpsilon)
transform.setD(1);
else if (fabs(transform.d() + 1) <= s_floatEpsilon)
transform.setD(-1);
if (fabs(transform.e()) <= s_floatEpsilon)
transform.setE(0);
if (fabs(transform.f()) <= s_floatEpsilon)
transform.setF(0);
}
示例9: drawPattern
void Image::drawPattern(GraphicsContext* gc, const FloatRect& srcRect,
const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace,
CompositeOperator compositeOp, const FloatRect& destRect)
{
SkBitmapRef* image = this->nativeImageForCurrentFrame();
if (!image || destRect.isEmpty())
return;
// in case we get called with an incomplete bitmap
const SkBitmap& origBitmap = image->bitmap();
if (origBitmap.getPixels() == NULL && origBitmap.pixelRef() == NULL)
return;
SkIRect srcR;
// we may have to scale if the image has been subsampled (so save RAM)
bool imageIsSubSampled = image->origWidth() != origBitmap.width() ||
image->origHeight() != origBitmap.height();
float scaleX = 1;
float scaleY = 1;
if (imageIsSubSampled) {
scaleX = (float)image->origWidth() / origBitmap.width();
scaleY = (float)image->origHeight() / origBitmap.height();
round_scaled(&srcR, srcRect, 1 / scaleX, 1 / scaleY);
} else
round(&srcR, srcRect);
// now extract the proper subset of the src image
SkBitmap bitmap;
if (!origBitmap.extractSubset(&bitmap, srcR)) {
SkDebugf("--- Image::drawPattern calling extractSubset failed\n");
return;
}
SkMatrix matrix(patternTransform);
if (imageIsSubSampled) {
matrix.preScale(SkFloatToScalar(scaleX), SkFloatToScalar(scaleY));
}
// We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the patter. If WebKit wants
// a shifted image, it will shift it from there using the patternTransform.
float tx = phase.x() + srcRect.x() * patternTransform.a();
float ty = phase.y() + srcRect.y() * patternTransform.d();
matrix.postTranslate(SkFloatToScalar(tx), SkFloatToScalar(ty));
gc->platformContext()->drawBitmapPattern(bitmap, matrix, compositeOp, destRect);
}
示例10: rotationOfCharacterCallback
static bool rotationOfCharacterCallback(QueryData* queryData, const SVGTextFragment& fragment)
{
RotationOfCharacterData* data = static_cast<RotationOfCharacterData*>(queryData);
int startPosition = data->position;
int endPosition = startPosition + 1;
if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
return false;
if (!fragment.isTransformed()) {
data->rotation = 0;
} else {
AffineTransform fragmentTransform = fragment.buildFragmentTransform(SVGTextFragment::TransformIgnoringTextLength);
fragmentTransform.scale(1 / fragmentTransform.xScale(), 1 / fragmentTransform.yScale());
data->rotation = narrowPrecisionToFloat(rad2deg(atan2(fragmentTransform.b(), fragmentTransform.a())));
}
return true;
}
示例11: affineTransformToSkMatrix
SkMatrix affineTransformToSkMatrix(const AffineTransform& source)
{
SkMatrix result;
result.setScaleX(WebCoreDoubleToSkScalar(source.a()));
result.setSkewX(WebCoreDoubleToSkScalar(source.c()));
result.setTranslateX(WebCoreDoubleToSkScalar(source.e()));
result.setScaleY(WebCoreDoubleToSkScalar(source.d()));
result.setSkewY(WebCoreDoubleToSkScalar(source.b()));
result.setTranslateY(WebCoreDoubleToSkScalar(source.f()));
// FIXME: Set perspective properly.
result.setPerspX(0);
result.setPerspY(0);
result.set(SkMatrix::kMPersp2, SK_Scalar1);
return result;
}
示例12: rotationOfCharacterCallback
bool SVGTextQuery::rotationOfCharacterCallback(Data* queryData, const SVGTextFragment& fragment) const
{
RotationOfCharacterData* data = static_cast<RotationOfCharacterData*>(queryData);
unsigned startPosition = data->position;
unsigned endPosition = startPosition + 1;
if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
return false;
AffineTransform fragmentTransform;
fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::TransformIgnoringTextLength);
if (fragmentTransform.isIdentity())
data->rotation = 0;
else {
fragmentTransform.scale(1 / fragmentTransform.xScale(), 1 / fragmentTransform.yScale());
data->rotation = narrowPrecisionToFloat(rad2deg(atan2(fragmentTransform.b(), fragmentTransform.a())));
}
return true;
}
示例13: drawPattern
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
{
if (!nativeImageForCurrentFrame())
return;
if (!patternTransform.isInvertible())
return;
CGContextRef context = ctxt->platformContext();
GraphicsContextStateSaver stateSaver(*ctxt);
CGContextClipToRect(context, destRect);
ctxt->setCompositeOperation(op, blendMode);
CGContextTranslateCTM(context, destRect.x(), destRect.y() + destRect.height());
CGContextScaleCTM(context, 1, -1);
// Compute the scaled tile size.
float scaledTileHeight = tileRect.height() * narrowPrecisionToFloat(patternTransform.d());
// We have to adjust the phase to deal with the fact we're in Cartesian space now (with the bottom left corner of destRect being
// the origin).
float adjustedX = phase.x() - destRect.x() + tileRect.x() * narrowPrecisionToFloat(patternTransform.a()); // We translated the context so that destRect.x() is the origin, so subtract it out.
float adjustedY = destRect.height() - (phase.y() - destRect.y() + tileRect.y() * narrowPrecisionToFloat(patternTransform.d()) + scaledTileHeight);
CGImageRef tileImage = nativeImageForCurrentFrame();
float h = CGImageGetHeight(tileImage);
RetainPtr<CGImageRef> subImage;
if (tileRect.size() == size())
subImage = tileImage;
else {
// Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
// because sub-images are only used for border-image, which only renders when the image is fully decoded.
ASSERT(h == height());
subImage = adoptCF(CGImageCreateWithImageInRect(tileImage, tileRect));
}
// Adjust the color space.
subImage = Image::imageWithColorSpace(subImage.get(), styleColorSpace);
// Leopard has an optimized call for the tiling of image patterns, but we can only use it if the image has been decoded enough that
// its buffer is the same size as the overall image. Because a partially decoded CGImageRef with a smaller width or height than the
// overall image buffer needs to tile with "gaps", we can't use the optimized tiling call in that case.
// FIXME: We cannot use CGContextDrawTiledImage with scaled tiles on Leopard, because it suffers from rounding errors. Snow Leopard is ok.
float scaledTileWidth = tileRect.width() * narrowPrecisionToFloat(patternTransform.a());
float w = CGImageGetWidth(tileImage);
if (w == size().width() && h == size().height() && !spaceSize().width() && !spaceSize().height())
CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage.get());
else {
// On Leopard and newer, this code now only runs for partially decoded images whose buffers do not yet match the overall size of the image.
static const CGPatternCallbacks patternCallbacks = { 0, drawPatternCallback, patternReleaseCallback };
CGAffineTransform matrix = CGAffineTransformMake(narrowPrecisionToCGFloat(patternTransform.a()), 0, 0, narrowPrecisionToCGFloat(patternTransform.d()), adjustedX, adjustedY);
matrix = CGAffineTransformConcat(matrix, CGContextGetCTM(context));
// The top of a partially-decoded image is drawn at the bottom of the tile. Map it to the top.
matrix = CGAffineTransformTranslate(matrix, 0, size().height() - h);
#if PLATFORM(IOS)
matrix = CGAffineTransformScale(matrix, 1, -1);
matrix = CGAffineTransformTranslate(matrix, 0, -h);
#endif
CGImageRef platformImage = CGImageRetain(subImage.get());
RetainPtr<CGPatternRef> pattern = adoptCF(CGPatternCreate(platformImage, CGRectMake(0, 0, tileRect.width(), tileRect.height()), matrix,
tileRect.width() + spaceSize().width() * (1 / narrowPrecisionToFloat(patternTransform.a())),
tileRect.height() + spaceSize().height() * (1 / narrowPrecisionToFloat(patternTransform.d())),
kCGPatternTilingConstantSpacing, true, &patternCallbacks));
if (!pattern)
return;
RetainPtr<CGColorSpaceRef> patternSpace = adoptCF(CGColorSpaceCreatePattern(0));
CGFloat alpha = 1;
RetainPtr<CGColorRef> color = adoptCF(CGColorCreateWithPattern(patternSpace.get(), pattern.get(), &alpha));
CGContextSetFillColorSpace(context, patternSpace.get());
// FIXME: Really want a public API for this. It is just CGContextSetBaseCTM(context, CGAffineTransformIdentiy).
wkSetBaseCTM(context, CGAffineTransformIdentity);
CGContextSetPatternPhase(context, CGSizeZero);
CGContextSetFillColorWithColor(context, color.get());
CGContextFillRect(context, CGContextGetClipBoundingBox(context));
}
stateSaver.restore();
if (imageObserver())
imageObserver()->didDraw(this);
}
示例14: drawPattern
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace, CompositeOperator, const FloatRect& dstRect)
{
#if USE(WXGC)
wxGCDC* context = (wxGCDC*)ctxt->platformContext();
wxGraphicsBitmap* bitmap = nativeImageForCurrentFrame();
#else
wxDC* context = ctxt->platformContext();
wxBitmap* bitmap = nativeImageForCurrentFrame();
#endif
if (!bitmap) // If it's too early we won't have an image yet.
return;
ctxt->save();
ctxt->clip(IntRect(dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height()));
float currentW = 0;
float currentH = 0;
#if USE(WXGC)
wxGraphicsContext* gc = context->GetGraphicsContext();
float adjustedX = phase.x() + srcRect.x() *
narrowPrecisionToFloat(patternTransform.a());
float adjustedY = phase.y() + srcRect.y() *
narrowPrecisionToFloat(patternTransform.d());
gc->ConcatTransform(patternTransform);
#else
float adjustedX = phase.x();
float adjustedY = phase.y();
wxMemoryDC mydc;
mydc.SelectObject(*bitmap);
ctxt->concatCTM(patternTransform);
#endif
//wxPoint origin(context->GetDeviceOrigin());
AffineTransform mat(ctxt->getCTM());
wxPoint origin(mat.mapPoint(IntPoint(0, 0)));
wxSize clientSize(context->GetSize());
wxCoord w = srcRect.width();
wxCoord h = srcRect.height();
wxCoord srcx = srcRect.x();
wxCoord srcy = srcRect.y();
while (currentW < dstRect.right() - phase.x() && origin.x + adjustedX + currentW < clientSize.x) {
while (currentH < dstRect.bottom() - phase.y() && origin.y + adjustedY + currentH < clientSize.y) {
#if USE(WXGC)
#if wxCHECK_VERSION(2,9,0)
gc->DrawBitmap(*bitmap, adjustedX + currentW, adjustedY + currentH, (wxDouble)srcRect.width(), (wxDouble)srcRect.height());
#else
gc->DrawGraphicsBitmap(*bitmap, adjustedX + currentW, adjustedY + currentH, (wxDouble)srcRect.width(), (wxDouble)srcRect.height());
#endif
#else
context->Blit(adjustedX + currentW, adjustedY + currentH,
w, h, &mydc, srcx, srcy, wxCOPY, true);
#endif
currentH += srcRect.height();
}
currentW += srcRect.width();
currentH = 0;
}
ctxt->restore();
#if !USE(WXGC)
mydc.SelectObject(wxNullBitmap);
#endif
// NB: delete is causing crashes during page load, but not during the deletion
// itself. It occurs later on when a valid bitmap created in frameAtIndex
// suddenly becomes invalid after returning. It's possible these errors deal
// with reentrancy and threding problems.
//delete bitmap;
startAnimation();
if (ImageObserver* observer = imageObserver())
observer->didDraw(this);
}
示例15: drawPattern
void Image::drawPattern(GraphicsContext* context,
const FloatRect& floatSrcRect,
const AffineTransform& patternTransform,
const FloatPoint& phase,
ColorSpace styleColorSpace,
CompositeOperator compositeOp,
const FloatRect& destRect)
{
FloatRect normSrcRect = normalizeRect(floatSrcRect);
if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
NativeImageSkia* bitmap = nativeImageForCurrentFrame();
if (!bitmap)
return;
SkIRect srcRect = enclosingIntRect(normSrcRect);
// Figure out what size the bitmap will be in the destination. The
// destination rect is the bounds of the pattern, we need to use the
// matrix to see how big it will be.
float destBitmapWidth, destBitmapHeight;
TransformDimensions(patternTransform, srcRect.width(), srcRect.height(),
&destBitmapWidth, &destBitmapHeight);
// Compute the resampling mode.
ResamplingMode resampling;
if (context->platformContext()->isAccelerated() || context->platformContext()->printing())
resampling = RESAMPLE_LINEAR;
else
resampling = computeResamplingMode(context->platformContext(), *bitmap, srcRect.width(), srcRect.height(), destBitmapWidth, destBitmapHeight);
// Load the transform WebKit requested.
SkMatrix matrix(patternTransform);
SkShader* shader;
if (resampling == RESAMPLE_AWESOME) {
// Do nice resampling.
int width = static_cast<int>(destBitmapWidth);
int height = static_cast<int>(destBitmapHeight);
SkBitmap resampled = bitmap->resizedBitmap(srcRect, width, height);
shader = SkShader::CreateBitmapShader(resampled, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
// Since we just resized the bitmap, we need to undo the scale set in
// the image transform.
matrix.setScaleX(SkIntToScalar(1));
matrix.setScaleY(SkIntToScalar(1));
} else {
// No need to do nice resampling.
SkBitmap srcSubset;
bitmap->bitmap().extractSubset(&srcSubset, srcRect);
shader = SkShader::CreateBitmapShader(srcSubset, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}
// We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the patter. If WebKit wants
// a shifted image, it will shift it from there using the patternTransform.
float adjustedX = phase.x() + normSrcRect.x() *
narrowPrecisionToFloat(patternTransform.a());
float adjustedY = phase.y() + normSrcRect.y() *
narrowPrecisionToFloat(patternTransform.d());
matrix.postTranslate(SkFloatToScalar(adjustedX),
SkFloatToScalar(adjustedY));
shader->setLocalMatrix(matrix);
SkPaint paint;
paint.setShader(shader)->unref();
paint.setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp));
paint.setFilterBitmap(resampling == RESAMPLE_LINEAR);
context->platformContext()->paintSkPaint(destRect, paint);
}