本文整理汇总了C++中FloatRect类的典型用法代码示例。如果您正苦于以下问题:C++ FloatRect类的具体用法?C++ FloatRect怎么用?C++ FloatRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FloatRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
{
if (!nativeImageForCurrentFrame())
return;
ASSERT(patternTransform.isInvertible());
if (!patternTransform.isInvertible())
// Avoid a hang under CGContextDrawTiledImage on release builds.
return;
CGContextRef context = ctxt->platformContext();
GraphicsContextStateSaver stateSaver(*ctxt);
CGContextClipToRect(context, destRect);
ctxt->setCompositeOperation(op);
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 = 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);
#ifdef BUILDING_ON_LEOPARD
if (w == size().width() && h == size().height() && scaledTileWidth == tileRect.width() && scaledTileHeight == tileRect.height())
#else
if (w == size().width() && h == size().height())
#endif
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, NULL };
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);
RetainPtr<CGPatternRef> pattern(AdoptCF, CGPatternCreate(subImage.get(), CGRectMake(0, 0, tileRect.width(), tileRect.height()),
matrix, tileRect.width(), tileRect.height(),
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).
//wkSetPatternBaseCTM(context, CGAffineTransformIdentity);
CGContextSetPatternPhase(context, CGSizeZero);
CGContextSetFillColorWithColor(context, color.get());
CGContextFillRect(context, CGContextGetClipBoundingBox(context));
}
stateSaver.restore();
if (imageObserver())
imageObserver()->didDraw(this);
}
示例2: clampToInteger
IntRect::IntRect(const FloatRect& r)
: m_location(clampToInteger(r.x()), clampToInteger(r.y()))
, m_size(clampToInteger(r.width()), clampToInteger(r.height()))
{
}
示例3: drawContentIntoMaskImage
bool RenderSVGResourceClipper::drawContentIntoMaskImage(ClipperData* clipperData, const FloatRect& objectBoundingBox)
{
ASSERT(frame());
ASSERT(clipperData);
ASSERT(clipperData->clipMaskImage);
GraphicsContext* maskContext = clipperData->clipMaskImage->context();
ASSERT(maskContext);
AffineTransform maskContentTransformation;
SVGClipPathElement* clipPath = static_cast<SVGClipPathElement*>(node());
if (clipPath->clipPathUnitsCurrentValue() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
maskContentTransformation.translate(objectBoundingBox.x(), objectBoundingBox.y());
maskContentTransformation.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
maskContext->concatCTM(maskContentTransformation);
}
// Switch to a paint behavior where all children of this <clipPath> will be rendered using special constraints:
// - fill-opacity/stroke-opacity/opacity set to 1
// - masker/filter not applied when rendering the children
// - fill is set to the initial fill paint server (solid, black)
// - stroke is set to the initial stroke paint server (none)
PaintBehavior oldBehavior = frame()->view()->paintBehavior();
frame()->view()->setPaintBehavior(oldBehavior | PaintBehaviorRenderingSVGMask);
// Draw all clipPath children into a global mask.
for (Node* childNode = node()->firstChild(); childNode; childNode = childNode->nextSibling()) {
RenderObject* renderer = childNode->renderer();
if (!childNode->isSVGElement() || !renderer)
continue;
if (renderer->needsLayout()) {
frame()->view()->setPaintBehavior(oldBehavior);
return false;
}
RenderStyle* style = renderer->style();
if (!style || style->display() == NONE || style->visibility() != VISIBLE)
continue;
WindRule newClipRule = style->svgStyle()->clipRule();
bool isUseElement = childNode->hasTagName(SVGNames::useTag);
if (isUseElement) {
SVGUseElement* useElement = toSVGUseElement(childNode);
renderer = useElement->rendererClipChild();
if (!renderer)
continue;
if (!useElement->hasAttribute(SVGNames::clip_ruleAttr))
newClipRule = renderer->style()->svgStyle()->clipRule();
}
// Only shapes, paths and texts are allowed for clipping.
if (!renderer->isSVGShape() && !renderer->isSVGText())
continue;
maskContext->setFillRule(newClipRule);
// In the case of a <use> element, we obtained its renderere above, to retrieve its clipRule.
// We have to pass the <use> renderer itself to renderSubtreeToImageBuffer() to apply it's x/y/transform/etc. values when rendering.
// So if isUseElement is true, refetch the childNode->renderer(), as renderer got overriden above.
SVGRenderingContext::renderSubtreeToImageBuffer(clipperData->clipMaskImage.get(), isUseElement ? childNode->renderer() : renderer, maskContentTransformation);
}
frame()->view()->setPaintBehavior(oldBehavior);
return true;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:64,代码来源:RenderSVGResourceClipper.cpp
示例4: m_bb
HaarFeature::HaarFeature(const FloatRect& bb, int type) :
m_bb(bb)
{
assert(type < 6);
switch (type)
{
case 0:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height()/2));
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin()+bb.Height()/2, bb.Width(), bb.Height()/2));
m_weights.push_back(1.f);
m_weights.push_back(-1.f);
m_factor = 255*1.f/2;
break;
}
case 1:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width()/2, bb.Height()));
m_rects.push_back(FloatRect(bb.XMin()+bb.Width()/2, bb.YMin(), bb.Width()/2, bb.Height()));
m_weights.push_back(1.f);
m_weights.push_back(-1.f);
m_factor = 255*1.f/2;
break;
}
case 2:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width()/3, bb.Height()));
m_rects.push_back(FloatRect(bb.XMin()+bb.Width()/3, bb.YMin(), bb.Width()/3, bb.Height()));
m_rects.push_back(FloatRect(bb.XMin()+2*bb.Width()/3, bb.YMin(), bb.Width()/3, bb.Height()));
m_weights.push_back(1.f);
m_weights.push_back(-2.f);
m_weights.push_back(1.f);
m_factor = 255*2.f/3;
break;
}
case 3:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height()/3));
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin()+bb.Height()/3, bb.Width(), bb.Height()/3));
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin()+2*bb.Height()/3, bb.Width(), bb.Height()/3));
m_weights.push_back(1.f);
m_weights.push_back(-2.f);
m_weights.push_back(1.f);
m_factor = 255*2.f/3;
break;
}
case 4:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width()/2, bb.Height()/2));
m_rects.push_back(FloatRect(bb.XMin()+bb.Width()/2, bb.YMin()+bb.Height()/2, bb.Width()/2, bb.Height()/2));
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin()+bb.Height()/2, bb.Width()/2, bb.Height()/2));
m_rects.push_back(FloatRect(bb.XMin()+bb.Width()/2, bb.YMin(), bb.Width()/2, bb.Height()/2));
m_weights.push_back(1.f);
m_weights.push_back(1.f);
m_weights.push_back(-1.f);
m_weights.push_back(-1.f);
m_factor = 255*1.f/2;
break;
}
case 5:
{
m_rects.push_back(FloatRect(bb.XMin(), bb.YMin(), bb.Width(), bb.Height()));
m_rects.push_back(FloatRect(bb.XMin()+bb.Width()/4, bb.YMin()+bb.Height()/4, bb.Width()/2, bb.Height()/2));
m_weights.push_back(1.f);
m_weights.push_back(-4.f);
m_factor = 255*3.f/4;
break;
}
}
}
示例5: PLATFORM
void Image::drawPattern(GraphicsContext* context,
const FloatRect& floatSrcRect,
const AffineTransform& patternTransform,
const FloatPoint& phase,
ColorSpace styleColorSpace,
CompositeOperator compositeOp,
const FloatRect& destRect)
{
#if PLATFORM(CHROMIUM)
TRACE_EVENT("Image::drawPattern", this, 0);
#endif
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);
}
示例6: startAnimation
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace colorSpace, CompositeOperator compositeOp, BlendMode, RespectImageOrientationEnum shouldRespectImageOrientation)
{
// Spin the animation to the correct frame before we try to draw it, so we
// don't draw an old frame and then immediately need to draw a newer one,
// causing flicker and wasting CPU.
startAnimation();
RefPtr<NativeImageSkia> bm = nativeImageForCurrentFrame();
if (!bm)
return; // It's too early and we don't have an image yet.
FloatRect normDstRect = normalizeRect(dstRect);
FloatRect normSrcRect = normalizeRect(srcRect);
normSrcRect.intersect(FloatRect(0, 0, bm->bitmap().width(), bm->bitmap().height()));
if (normSrcRect.isEmpty() || normDstRect.isEmpty())
return; // Nothing to draw.
ImageOrientation orientation = DefaultImageOrientation;
if (shouldRespectImageOrientation == RespectImageOrientation)
orientation = frameOrientationAtIndex(m_currentFrame);
GraphicsContextStateSaver saveContext(*ctxt, false);
if (orientation != DefaultImageOrientation) {
saveContext.save();
// ImageOrientation expects the origin to be at (0, 0)
ctxt->translate(normDstRect.x(), normDstRect.y());
normDstRect.setLocation(FloatPoint());
ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size()));
if (orientation.usesWidthAsHeight()) {
// The destination rect will have it's width and height already reversed for the orientation of
// the image, as it was needed for page layout, so we need to reverse it back here.
normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRect.height(), normDstRect.width());
}
}
paintSkBitmap(ctxt->platformContext(),
*bm,
normSrcRect,
normDstRect,
WebCoreCompositeToSkiaComposite(compositeOp));
if (ImageObserver* observer = imageObserver())
observer->didDraw(this);
}
示例7: drawingContext
void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float /*maxWidth*/, bool /*useMaxWidth*/)
{
GraphicsContext* c = drawingContext();
if (!c)
return;
if (!state().m_invertibleCTM)
return;
const Font& font = accessFont();
// FIXME: Handle maxWidth.
// FIXME: Need to turn off font smoothing.
bool rtl = m_canvas->computedStyle() ? m_canvas->computedStyle()->direction() == RTL : false;
bool override = m_canvas->computedStyle() ? m_canvas->computedStyle()->unicodeBidi() == Override : false;
unsigned length = text.length();
const UChar* string = text.characters();
TextRun textRun(string, length, 0, 0, 0, rtl, override, false, false);
// Draw the item text at the correct point.
FloatPoint location(x, y);
switch (state().m_textBaseline) {
case TopTextBaseline:
case HangingTextBaseline:
location.setY(y + font.ascent());
break;
case BottomTextBaseline:
case IdeographicTextBaseline:
location.setY(y - font.descent());
break;
case MiddleTextBaseline:
location.setY(y - font.descent() + font.height() / 2);
break;
case AlphabeticTextBaseline:
default:
// Do nothing.
break;
}
float width = font.width(TextRun(text, false, 0, 0, rtl, override));
TextAlign align = state().m_textAlign;
if (align == StartTextAlign)
align = rtl ? RightTextAlign : LeftTextAlign;
else if (align == EndTextAlign)
align = rtl ? LeftTextAlign : RightTextAlign;
switch (align) {
case CenterTextAlign:
location.setX(location.x() - width / 2);
break;
case RightTextAlign:
location.setX(location.x() - width);
break;
default:
break;
}
// The slop built in to this mask rect matches the heuristic used in FontCGWin.cpp for GDI text.
FloatRect textRect = FloatRect(location.x() - font.height() / 2, location.y() - font.ascent() - font.lineGap(),
width + font.height(), font.lineSpacing());
if (!fill)
textRect.inflate(c->strokeThickness() / 2);
if (fill)
m_canvas->willDraw(textRect);
else {
// When stroking text, pointy miters can extend outside of textRect, so we
// punt and dirty the whole canvas.
m_canvas->willDraw(FloatRect(0, 0, m_canvas->width(), m_canvas->height()));
}
#if PLATFORM(CG)
CanvasStyle* drawStyle = fill ? state().m_fillStyle.get() : state().m_strokeStyle.get();
if (drawStyle->canvasGradient() || drawStyle->canvasPattern()) {
// FIXME: The rect is not big enough for miters on stroked text.
IntRect maskRect = enclosingIntRect(textRect);
OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size(), false);
GraphicsContext* maskImageContext = maskImage->context();
if (fill)
maskImageContext->setFillColor(Color::black);
else {
maskImageContext->setStrokeColor(Color::black);
maskImageContext->setStrokeThickness(c->strokeThickness());
}
maskImageContext->setTextDrawingMode(fill ? cTextFill : cTextStroke);
maskImageContext->translate(-maskRect.x(), -maskRect.y());
maskImageContext->drawBidiText(font, textRun, location);
c->save();
c->clipToImageBuffer(maskRect, maskImage.get());
drawStyle->applyFillColor(c);
c->fillRect(maskRect);
c->restore();
//.........这里部分代码省略.........
示例8: clip
void GraphicsContext::clip(const FloatRect& r)
{
m_data->context->SetClippingRegion(r.x(), r.y(), r.width(), r.height());
}
示例9: ASSERT
FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect* effect)
{
FloatRect uniteRect;
FloatRect subregionBoundingBox = effect->effectBoundaries();
FloatRect subregion = subregionBoundingBox;
SVGFilter* filter = static_cast<SVGFilter*>(effect->filter());
ASSERT(filter);
if (effect->filterEffectType() != FilterEffectTypeTile) {
// FETurbulence, FEImage and FEFlood don't have input effects, take the filter region as unite rect.
if (unsigned numberOfInputEffects = effect->inputEffects().size()) {
for (unsigned i = 0; i < numberOfInputEffects; ++i)
uniteRect.unite(determineFilterPrimitiveSubregion(effect->inputEffect(i)));
} else
uniteRect = filter->filterRegionInUserSpace();
} else {
determineFilterPrimitiveSubregion(effect->inputEffect(0));
uniteRect = filter->filterRegionInUserSpace();
}
if (filter->effectBoundingBoxMode()) {
subregion = uniteRect;
// Avoid the calling of a virtual method several times.
FloatRect targetBoundingBox = filter->targetBoundingBox();
if (effect->hasX())
subregion.setX(targetBoundingBox.x() + subregionBoundingBox.x() * targetBoundingBox.width());
if (effect->hasY())
subregion.setY(targetBoundingBox.y() + subregionBoundingBox.y() * targetBoundingBox.height());
if (effect->hasWidth())
subregion.setWidth(subregionBoundingBox.width() * targetBoundingBox.width());
if (effect->hasHeight())
subregion.setHeight(subregionBoundingBox.height() * targetBoundingBox.height());
} else {
if (!effect->hasX())
subregion.setX(uniteRect.x());
if (!effect->hasY())
subregion.setY(uniteRect.y());
if (!effect->hasWidth())
subregion.setWidth(uniteRect.width());
if (!effect->hasHeight())
subregion.setHeight(uniteRect.height());
}
effect->setFilterPrimitiveSubregion(subregion);
FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
FloatSize filterResolution = filter->filterResolution();
absoluteSubregion.scale(filterResolution.width(), filterResolution.height());
// FEImage needs the unclipped subregion in absolute coordinates to determine the correct
// destination rect in combination with preserveAspectRatio.
if (effect->filterEffectType() == FilterEffectTypeImage)
static_cast<FEImage*>(effect)->setAbsoluteSubregion(absoluteSubregion);
// Clip every filter effect to the filter region.
FloatRect absoluteScaledFilterRegion = filter->filterRegion();
absoluteScaledFilterRegion.scale(filterResolution.width(), filterResolution.height());
absoluteSubregion.intersect(absoluteScaledFilterRegion);
effect->setMaxEffectRect(enclosingIntRect(absoluteSubregion));
return subregion;
}
示例10: ASSERT
void GradientGeneratedImage::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const FloatSize& scale,
const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& destRect, WebBlendMode blendMode, const IntSize& repeatSpacing)
{
float stepX = srcRect.width() + repeatSpacing.width();
float stepY = srcRect.height() + repeatSpacing.height();
int firstColumn = static_cast<int>(floorf((((destRect.x() - phase.x()) / scale.width()) - srcRect.x()) / srcRect.width()));
int firstRow = static_cast<int>(floorf((((destRect.y() - phase.y()) / scale.height()) - srcRect.y()) / srcRect.height()));
for (int i = firstColumn; ; ++i) {
float dstX = (srcRect.x() + i * stepX) * scale.width() + phase.x();
// assert that first column encroaches left edge of dstRect.
ASSERT(i > firstColumn || dstX <= destRect.x());
ASSERT(i == firstColumn || dstX > destRect.x());
if (dstX >= destRect.maxX())
break;
float dstMaxX = dstX + srcRect.width() * scale.width();
if (dstX < destRect.x())
dstX = destRect.x();
if (dstMaxX > destRect.maxX())
dstMaxX = destRect.maxX();
if (dstX >= dstMaxX)
continue;
FloatRect visibleSrcRect;
FloatRect tileDstRect;
tileDstRect.setX(dstX);
tileDstRect.setWidth(dstMaxX - dstX);
visibleSrcRect.setX((tileDstRect.x() - phase.x()) / scale.width() - i * stepX);
visibleSrcRect.setWidth(tileDstRect.width() / scale.width());
for (int j = firstRow; ; j++) {
float dstY = (srcRect.y() + j * stepY) * scale.height() + phase.y();
// assert that first row encroaches top edge of dstRect.
ASSERT(j > firstRow || dstY <= destRect.y());
ASSERT(j == firstRow || dstY > destRect.y());
if (dstY >= destRect.maxY())
break;
float dstMaxY = dstY + srcRect.height() * scale.height();
if (dstY < destRect.y())
dstY = destRect.y();
if (dstMaxY > destRect.maxY())
dstMaxY = destRect.maxY();
if (dstY >= dstMaxY)
continue;
tileDstRect.setY(dstY);
tileDstRect.setHeight(dstMaxY - dstY);
visibleSrcRect.setY((tileDstRect.y() - phase.y()) / scale.height() - j * stepY);
visibleSrcRect.setHeight(tileDstRect.height() / scale.height());
draw(destContext, tileDstRect, visibleSrcRect, compositeOp, blendMode);
}
}
}
示例11: addBeziersForRoundedRect
void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius)
{
moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y()));
addLineTo(FloatPoint(rect.maxX() - topRightRadius.width(), rect.y()));
if (topRightRadius.width() > 0 || topRightRadius.height() > 0)
addBezierCurveTo(FloatPoint(rect.maxX() - topRightRadius.width() * gCircleControlPoint, rect.y()),
FloatPoint(rect.maxX(), rect.y() + topRightRadius.height() * gCircleControlPoint),
FloatPoint(rect.maxX(), rect.y() + topRightRadius.height()));
addLineTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height()));
if (bottomRightRadius.width() > 0 || bottomRightRadius.height() > 0)
addBezierCurveTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height() * gCircleControlPoint),
FloatPoint(rect.maxX() - bottomRightRadius.width() * gCircleControlPoint, rect.maxY()),
FloatPoint(rect.maxX() - bottomRightRadius.width(), rect.maxY()));
addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.maxY()));
if (bottomLeftRadius.width() > 0 || bottomLeftRadius.height() > 0)
addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.maxY()),
FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height() * gCircleControlPoint),
FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height()));
addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height()));
if (topLeftRadius.width() > 0 || topLeftRadius.height() > 0)
addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint),
FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()),
FloatPoint(rect.x() + topLeftRadius.width(), rect.y()));
closeSubpath();
}
示例12:
LayoutRect::LayoutRect(const FloatRect& r)
: m_location(LayoutPoint(r.location())), m_size(LayoutSize(r.size())) {}
示例13: enclosingLayoutRect
LayoutRect enclosingLayoutRect(const FloatRect& rect) {
LayoutPoint location = flooredLayoutPoint(rect.minXMinYCorner());
LayoutPoint maxPoint = ceiledLayoutPoint(rect.maxXMaxYCorner());
return LayoutRect(location, maxPoint - location);
}
示例14: contains
bool FloatRect::contains(const FloatRect& other) const
{
return x() <= other.x() && right() >= other.right()
&& y() <= other.y() && bottom() >= other.bottom();
}
示例15: bitmap
void NativeImageSkia::drawPattern(
GraphicsContext* context,
const FloatRect& floatSrcRect,
const FloatSize& scale,
const FloatPoint& phase,
CompositeOperator compositeOp,
const FloatRect& destRect,
WebBlendMode blendMode,
const IntSize& repeatSpacing) const
{
FloatRect normSrcRect = floatSrcRect;
normSrcRect.intersect(FloatRect(0, 0, bitmap().width(), bitmap().height()));
if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
SkMatrix totalMatrix = context->getTotalMatrix();
AffineTransform ctm = context->getCTM();
SkScalar ctmScaleX = ctm.xScale();
SkScalar ctmScaleY = ctm.yScale();
totalMatrix.preScale(scale.width(), scale.height());
// 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.
SkRect destRectTarget;
totalMatrix.mapRect(&destRectTarget, normSrcRect);
float destBitmapWidth = SkScalarToFloat(destRectTarget.width());
float destBitmapHeight = SkScalarToFloat(destRectTarget.height());
bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
// Compute the resampling mode.
InterpolationQuality resampling;
if (context->isAccelerated())
resampling = InterpolationLow;
else if (isLazyDecoded)
resampling = InterpolationHigh;
else
resampling = computeInterpolationQuality(totalMatrix, normSrcRect.width(), normSrcRect.height(), destBitmapWidth, destBitmapHeight, isDataComplete());
resampling = limitInterpolationQuality(context, resampling);
SkMatrix localMatrix;
// 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 pattern. If WebKit wants
// a shifted image, it will shift it from there using the localMatrix.
const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjustedY));
sk_sp<SkShader> shader;
SkFilterQuality filterLevel = static_cast<SkFilterQuality>(resampling);
// Bicubic filter is only applied to defer-decoded images, see
// NativeImageSkia::draw for details.
if (resampling == InterpolationHigh && !isLazyDecoded) {
// Do nice resampling.
filterLevel = kNone_SkFilterQuality;
float scaleX = destBitmapWidth / normSrcRect.width();
float scaleY = destBitmapHeight / normSrcRect.height();
SkRect scaledSrcRect;
// Since we are resizing the bitmap, we need to remove the scale
// applied to the pixels in the bitmap shader. This means we need
// CTM * localMatrix to have identity scale. Since we
// can't modify CTM (or the rectangle will be drawn in the wrong
// place), we must set localMatrix's scale to the inverse of
// CTM scale.
localMatrix.preScale(ctmScaleX ? 1 / ctmScaleX : 1, ctmScaleY ? 1 / ctmScaleY : 1);
// The image fragment generated here is not exactly what is
// requested. The scale factor used is approximated and image
// fragment is slightly larger to align to integer
// boundaries.
SkBitmap resampled = extractScaledImageFragment(normSrcRect, scaleX, scaleY, &scaledSrcRect);
if (repeatSpacing.isZero()) {
shader = SkShader::MakeBitmapShader(resampled, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix);
} else {
shader = SkShader::MakeBitmapShader(
createBitmapWithSpace(resampled, repeatSpacing.width() * ctmScaleX, repeatSpacing.height() * ctmScaleY),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix);
}
} else {
// Because no resizing occurred, the shader transform should be
// set to the pattern's transform, which just includes scale.
localMatrix.preScale(scale.width(), scale.height());
// No need to resample before drawing.
SkBitmap srcSubset;
bitmap().extractSubset(&srcSubset, enclosingIntRect(normSrcRect));
if (repeatSpacing.isZero()) {
shader = SkShader::MakeBitmapShader(srcSubset, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix);
} else {
shader = SkShader::MakeBitmapShader(
createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScaleX, repeatSpacing.height() * ctmScaleY),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix);
}
}
//.........这里部分代码省略.........