本文整理汇总了C++中AffineTransform::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ AffineTransform::scale方法的具体用法?C++ AffineTransform::scale怎么用?C++ AffineTransform::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AffineTransform
的用法示例。
在下文中一共展示了AffineTransform::scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawDeferredFilter
static void drawDeferredFilter(GraphicsContext* context, FilterData* filterData, SVGFilterElement* filterElement)
{
SkiaImageFilterBuilder builder(context);
SourceGraphic* sourceGraphic = static_cast<SourceGraphic*>(filterData->builder->getEffectById(SourceGraphic::effectName()));
ASSERT(sourceGraphic);
builder.setSourceGraphic(sourceGraphic);
RefPtr<ImageFilter> imageFilter = builder.build(filterData->builder->lastEffect(), ColorSpaceDeviceRGB);
FloatRect boundaries = filterData->boundaries;
context->save();
FloatSize deviceSize = context->getCTM().mapSize(boundaries.size());
float scaledArea = deviceSize.width() * deviceSize.height();
// If area of scaled size is bigger than the upper limit, adjust the scale
// to fit. Note that this only really matters in the non-impl-side painting
// case, since the impl-side case never allocates a full-sized backing
// store, only tile-sized.
// FIXME: remove this once all platforms are using impl-side painting.
// crbug.com/169282.
if (scaledArea > FilterEffect::maxFilterArea()) {
float scale = sqrtf(FilterEffect::maxFilterArea() / scaledArea);
context->scale(scale, scale);
}
// Clip drawing of filtered image to the minimum required paint rect.
FilterEffect* lastEffect = filterData->builder->lastEffect();
context->clipRect(lastEffect->determineAbsolutePaintRect(lastEffect->maxEffectRect()));
if (filterElement->hasAttribute(SVGNames::filterResAttr)) {
// Get boundaries in device coords.
// FIXME: See crbug.com/382491. Is the use of getCTM OK here, given it does not include device
// zoom or High DPI adjustments?
FloatSize size = context->getCTM().mapSize(boundaries.size());
// Compute the scale amount required so that the resulting offscreen is exactly filterResX by filterResY pixels.
float filterResScaleX = filterElement->filterResX()->currentValue()->value() / size.width();
float filterResScaleY = filterElement->filterResY()->currentValue()->value() / size.height();
// Scale the CTM so the primitive is drawn to filterRes.
context->scale(filterResScaleX, filterResScaleY);
// Create a resize filter with the inverse scale.
AffineTransform resizeMatrix;
resizeMatrix.scale(1 / filterResScaleX, 1 / filterResScaleY);
imageFilter = builder.buildTransform(resizeMatrix, imageFilter.get());
}
// If the CTM contains rotation or shearing, apply the filter to
// the unsheared/unrotated matrix, and do the shearing/rotation
// as a final pass.
AffineTransform ctm = context->getCTM();
if (ctm.b() || ctm.c()) {
AffineTransform scaleAndTranslate;
scaleAndTranslate.translate(ctm.e(), ctm.f());
scaleAndTranslate.scale(ctm.xScale(), ctm.yScale());
ASSERT(scaleAndTranslate.isInvertible());
AffineTransform shearAndRotate = scaleAndTranslate.inverse();
shearAndRotate.multiply(ctm);
context->setCTM(scaleAndTranslate);
imageFilter = builder.buildTransform(shearAndRotate, imageFilter.get());
}
context->beginLayer(1, CompositeSourceOver, &boundaries, ColorFilterNone, imageFilter.get());
context->endLayer();
context->restore();
}
示例2: makeMapBetweenRects
AffineTransform makeMapBetweenRects(const FloatRect& source, const FloatRect& dest)
{
AffineTransform transform;
transform.translate(dest.x() - source.x(), dest.y() - source.y());
transform.scale(dest.width() / source.width(), dest.height() / source.height());
return transform;
}
示例3: calculateTransformationToOutermostCoordinateSystem
AffineTransform SVGRenderingContext::calculateTransformationToOutermostCoordinateSystem(const RenderObject& renderer)
{
AffineTransform absoluteTransform = currentContentTransformation();
float deviceScaleFactor = renderer.document().deviceScaleFactor();
// Walk up the render tree, accumulating SVG transforms.
const RenderObject* ancestor = &renderer;
while (ancestor) {
absoluteTransform = ancestor->localToParentTransform() * absoluteTransform;
if (ancestor->isSVGRoot())
break;
ancestor = ancestor->parent();
}
// Continue walking up the layer tree, accumulating CSS transforms.
RenderLayer* layer = ancestor ? ancestor->enclosingLayer() : nullptr;
while (layer) {
if (TransformationMatrix* layerTransform = layer->transform())
absoluteTransform = layerTransform->toAffineTransform() * absoluteTransform;
// We can stop at compositing layers, to match the backing resolution.
if (layer->isComposited())
break;
layer = layer->parent();
}
absoluteTransform.scale(deviceScaleFactor);
return absoluteTransform;
}
示例4: applyClip
void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const
{
if (m_clipData.clipData().isEmpty())
return;
bool heterogenousClipRules = false;
WindRule clipRule = m_clipData.clipData()[0].windRule;
context->beginPath();
for (unsigned x = 0; x < m_clipData.clipData().size(); x++) {
ClipData clipData = m_clipData.clipData()[x];
if (clipData.windRule != clipRule)
heterogenousClipRules = true;
Path clipPath = clipData.path;
if (clipData.bboxUnits) {
AffineTransform transform;
transform.translate(boundingBox.x(), boundingBox.y());
transform.scale(boundingBox.width(), boundingBox.height());
clipPath.transform(transform);
}
context->addPath(clipPath);
}
// FIXME!
// We don't currently allow for heterogenous clip rules.
// we would have to detect such, draw to a mask, and then clip
// to that mask
context->clipPath(clipRule);
}
示例5: drawPattern
void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect, BlendMode)
{
// Allow the generator to provide visually-equivalent tiling parameters for better performance.
IntSize adjustedSize = m_size;
FloatRect adjustedSrcRect = srcRect;
m_gradient->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect);
// Factor in the destination context's scale to generate at the best resolution
AffineTransform destContextCTM = destContext->getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
double xScale = fabs(destContextCTM.xScale());
double yScale = fabs(destContextCTM.yScale());
AffineTransform adjustedPatternCTM = patternTransform;
adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
adjustedSrcRect.scale(xScale, yScale);
unsigned generatorHash = m_gradient->hash();
if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !destContext->isCompatibleWithBuffer(m_cachedImageBuffer.get())) {
m_cachedImageBuffer = destContext->createCompatibleBuffer(adjustedSize, m_gradient->hasAlpha());
if (!m_cachedImageBuffer)
return;
// Fill with the generated image.
m_cachedImageBuffer->context()->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_gradient);
m_cachedGeneratorHash = generatorHash;
m_cachedAdjustedSize = adjustedSize;
}
m_cachedImageBuffer->setSpaceSize(spaceSize());
// Tile the image buffer into the context.
m_cachedImageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
}
示例6: transform
AffineTransform SVGGlyphToPathTranslator::transform()
{
AffineTransform glyphPathTransform;
glyphPathTransform.translate(m_currentPoint.x() + m_glyphOrigin.x(), m_currentPoint.y() + m_glyphOrigin.y());
glyphPathTransform.scale(m_scale, -m_scale);
return glyphPathTransform;
}
示例7: applyClip
void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const
{
cairo_t* cr = context->platformContext();
if (m_clipData.clipData().size() < 1)
return;
cairo_reset_clip(cr);
context->beginPath();
for (unsigned int x = 0; x < m_clipData.clipData().size(); x++) {
ClipData data = m_clipData.clipData()[x];
Path path = data.path;
if (path.isEmpty())
continue;
path.closeSubpath();
if (data.bboxUnits) {
// Make use of the clipping units
AffineTransform transform;
transform.translate(boundingBox.x(), boundingBox.y());
transform.scale(boundingBox.width(), boundingBox.height());
path.transform(transform);
}
cairo_path_t* clipPath = cairo_copy_path(path.platformPath()->m_cr);
cairo_append_path(cr, clipPath);
cairo_set_fill_rule(cr, data.windRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
}
cairo_clip(cr);
}
示例8: drawPattern
void GeneratorGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect)
{
// Allow the generator to provide visually-equivalent tiling parameters for better performance.
IntSize adjustedSize = m_size;
FloatRect adjustedSrcRect = srcRect;
m_generator->adjustParametersForTiledDrawing(adjustedSize, adjustedSrcRect);
// Factor in the destination context's scale to generate at the best resolution
AffineTransform destContextCTM = destContext->getCTM();
double xScale = fabs(destContextCTM.xScale());
double yScale = fabs(destContextCTM.yScale());
AffineTransform adjustedPatternCTM = patternTransform;
adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
adjustedSrcRect.scale(xScale, yScale);
// Create a BitmapImage and call drawPattern on it.
OwnPtr<ImageBuffer> imageBuffer = destContext->createCompatibleBuffer(adjustedSize);
if (!imageBuffer)
return;
// Fill with the generated image.
GraphicsContext* graphicsContext = imageBuffer->context();
graphicsContext->fillRect(FloatRect(FloatPoint(), adjustedSize), *m_generator.get());
// Tile the image buffer into the context.
imageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
}
示例9: drawPattern
void GeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const FloatSize& scale,
const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& destRect,
const IntSize& repeatSpacing)
{
FloatRect tileRect = srcRect;
tileRect.expand(repeatSpacing);
SkPictureBuilder builder(tileRect, nullptr, destContext);
builder.context().beginRecording(tileRect);
drawTile(&builder.context(), srcRect);
RefPtr<const SkPicture> tilePicture = builder.endRecording();
AffineTransform patternTransform;
patternTransform.translate(phase.x(), phase.y());
patternTransform.scale(scale.width(), scale.height());
patternTransform.translate(tileRect.x(), tileRect.y());
RefPtr<Pattern> picturePattern = Pattern::createPicturePattern(tilePicture);
picturePattern->setPatternSpaceTransform(patternTransform);
SkPaint fillPaint = destContext->fillPaint();
picturePattern->applyToPaint(fillPaint);
fillPaint.setColor(SK_ColorBLACK);
fillPaint.setXfermodeMode(compositeOp);
destContext->drawRect(destRect, fillPaint);
}
示例10: paintTextWithShadows
void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
{
RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
ASSERT(textRenderer);
float scalingFactor = textRenderer->scalingFactor();
ASSERT(scalingFactor);
const Font& scaledFont = textRenderer->scaledFont();
const ShadowData* shadow = style->textShadow();
FloatPoint textOrigin(fragment.x, fragment.y);
FloatSize textSize(fragment.width, fragment.height);
if (scalingFactor != 1) {
textOrigin.scale(scalingFactor, scalingFactor);
textSize.scale(scalingFactor);
}
FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - scaledFont.fontMetrics().floatAscent()), textSize);
do {
if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style))
break;
FloatSize extraOffset;
if (shadow)
extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */);
AffineTransform originalTransform;
if (scalingFactor != 1) {
originalTransform = context->getCTM();
AffineTransform newTransform = originalTransform;
newTransform.scale(1 / scalingFactor);
normalizeTransform(newTransform);
context->setCTM(newTransform);
}
scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
if (scalingFactor != 1)
context->setCTM(originalTransform);
restoreGraphicsContextAfterTextPainting(context, textRun);
if (!shadow)
break;
if (shadow->next())
context->restore();
else
context->clearShadow();
shadow = shadow->next();
} while (shadow);
}
示例11: fullBuffer
// Tests scale mode with an additional copy for transparency. This will happen
// if we have a scaled textbox, for example. WebKit will create a new
// transparency layer, draw the text field, then draw the text into it, then
// composite this down with an opacity.
TEST(TransparencyWin, ScaleTransparency)
{
// Create an opaque white buffer.
OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1));
FloatRect fullBuffer(0, 0, 16, 16);
src->context()->fillRect(fullBuffer, Color::white);
// Make another layer (which duplicates how WebKit will make this). We fill
// the top half with red, and have the layer be 50% opaque.
src->context()->beginTransparencyLayer(0.5);
FloatRect topHalf(0, 0, 16, 8);
src->context()->fillRect(topHalf, Color(0xFFFF0000));
// Scale by 2x.
src->context()->save();
AffineTransform scale;
scale.scale(2.0);
src->context()->concatCTM(scale);
// Make a layer inset two pixels (because of scaling, this is 2->14). And
// will it with 50% black.
{
TransparencyWin helper;
helper.init(src->context(),
TransparencyWin::OpaqueCompositeLayer,
TransparencyWin::ScaleTransform,
IntRect(1, 1, 6, 6));
helper.context()->fillRect(helper.drawRect(), Color(0x7f000000));
clearTopLayerAlphaChannel(helper.context());
helper.composite();
}
// Finish the layer.
src->context()->restore();
src->context()->endLayer();
Color redBackground(0xFFFF8080); // 50% red composited on white.
EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0));
EXPECT_EQ(redBackground, getPixelAt(src->context(), 1, 1));
// Top half (minus two pixel border) should be 50% gray atop opaque
// red = 0xFF804141. Then that's composited with 50% transparency on solid
// white = 0xFFC0A1A1.
Color darkRed(0xFFBF8080);
EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2));
EXPECT_EQ(darkRed, getPixelAt(src->context(), 7, 7));
// Bottom half (minus a two pixel border) should be a layer with 5% gray
// with another 50% opacity composited atop white.
Color darkWhite(0xFFBFBFBF);
EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8));
EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13));
Color white(0xFFFFFFFF); // Background in the lower-right.
EXPECT_EQ(white, getPixelAt(src->context(), 14, 14));
EXPECT_EQ(white, getPixelAt(src->context(), 15, 15));
}
示例12: applyClippingToContext
bool SVGClipPainter::applyClippingToContext(const LayoutObject& target, const FloatRect& targetBoundingBox,
const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperState& clipperState)
{
ASSERT(context);
ASSERT(clipperState == ClipperNotApplied);
ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout());
if (paintInvalidationRect.isEmpty() || m_clip.hasCycle())
return false;
SVGClipExpansionCycleHelper inClipExpansionChange(m_clip);
AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element())->calculateAnimatedLocalTransform();
// When drawing a clip for non-SVG elements, the CTM does not include the zoom factor.
// In this case, we need to apply the zoom scale explicitly - but only for clips with
// userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolved lengths).
if (!target.isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
ASSERT(m_clip.style());
animatedLocalTransform.scale(m_clip.style()->effectiveZoom());
}
// First, try to apply the clip as a clipPath.
if (m_clip.tryPathOnlyClipping(target, context, animatedLocalTransform, targetBoundingBox)) {
clipperState = ClipperAppliedPath;
return true;
}
// Fall back to masking.
clipperState = ClipperAppliedMask;
// Begin compositing the clip mask.
CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect);
{
TransformRecorder recorder(*context, target, animatedLocalTransform);
// clipPath can also be clipped by another clipPath.
SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(&m_clip);
LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipper() : 0;
ClipperState clipPathClipperState = ClipperNotApplied;
if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingToContext(m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClipperState)) {
// End the clip mask's compositor.
CompositingRecorder::endCompositing(*context, target);
return false;
}
drawClipMaskContent(context, target, targetBoundingBox);
if (clipPathClipper)
SVGClipPainter(*clipPathClipper).postApplyStatefulResource(m_clip, context, clipPathClipperState);
}
// Masked content layer start.
CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcIn_Mode, 1, &paintInvalidationRect);
return true;
}
示例13: affineTransformCompose
static void affineTransformCompose(AffineTransform& m, const double sr[9])
{
m.setA(sr[3]);
m.setB(sr[4]);
m.setC(sr[5]);
m.setD(sr[6]);
m.setE(sr[7]);
m.setF(sr[8]);
m.rotate(rad2deg(sr[2]));
m.scale(sr[0], sr[1]);
}
示例14: absoluteTransform
AffineTransform RenderSVGContainer::absoluteTransform() const
{
AffineTransform ctm = RenderContainer::absoluteTransform();
if (!parent()->isSVGContainer()) {
SVGSVGElement* svg = static_cast<SVGSVGElement*>(element());
ctm.scale(svg->currentScale());
ctm.translate(svg->currentTranslate().x(), svg->currentTranslate().y());
}
ctm.translate(viewport().x(), viewport().y());
return viewportTransform() * ctm;
}
示例15: drawingRegionOfInputImage
FloatRect FilterEffect::drawingRegionOfInputImage(const IntRect& srcRect) const
{
ASSERT(hasResult());
FloatSize scale;
ImageBuffer::clampedSize(m_absolutePaintRect.size(), scale);
AffineTransform transform;
transform.scale(scale).translate(-m_absolutePaintRect.location());
return transform.mapRect(srcRect);
}