本文整理汇总了C++中SkFloatToScalar函数的典型用法代码示例。如果您正苦于以下问题:C++ SkFloatToScalar函数的具体用法?C++ SkFloatToScalar怎么用?C++ SkFloatToScalar使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SkFloatToScalar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doDraw
static void doDraw(SkCanvas* canvas, SkPaint* paint, const int isrc[],
const int idst[], int count) {
SkMatrix matrix;
SkPoint src[4], dst[4];
for (int i = 0; i < count; i++) {
src[i].set(SkIntToScalar(isrc[2*i+0]), SkIntToScalar(isrc[2*i+1]));
dst[i].set(SkIntToScalar(idst[2*i+0]), SkIntToScalar(idst[2*i+1]));
}
canvas->save();
matrix.setPolyToPoly(src, dst, count);
canvas->concat(matrix);
paint->setColor(SK_ColorGRAY);
paint->setStyle(SkPaint::kStroke_Style);
const SkScalar D = SkIntToScalar(64);
canvas->drawRectCoords(0, 0, D, D, *paint);
canvas->drawLine(0, 0, D, D, *paint);
canvas->drawLine(0, D, D, 0, *paint);
SkPaint::FontMetrics fm;
paint->getFontMetrics(&fm);
paint->setColor(SK_ColorRED);
paint->setStyle(SkPaint::kFill_Style);
SkScalar x = D/2;
float y = D/2 - (fm.fAscent + fm.fDescent)/2;
SkString str;
str.appendS32(count);
canvas->drawText(str.c_str(), str.size(),
x, SkFloatToScalar(y),
*paint);
canvas->restore();
}
示例2: input
PassRefPtr<SkImageFilter> FEOffset::createImageFilter(SkiaImageFilterBuilder* builder)
{
RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
Filter* filter = this->filter();
SkImageFilter::CropRect cropRect = getCropRect(builder->cropOffset());
return adoptRef(SkOffsetImageFilter::Create(SkFloatToScalar(filter->applyHorizontalScale(m_dx)), SkFloatToScalar(filter->applyVerticalScale(m_dy)), input.get(), &cropRect));
}
示例3: _cairo_skia_context_create
cairo_t *
_cairo_skia_context_create (void *target)
{
cairo_skia_surface_t *surface = (cairo_skia_surface_t *) target;
cairo_skia_context_t *cr;
cr = (cairo_skia_context_t *) _freed_pool_get (&context_pool);
if (unlikely (cr == NULL)) {
cr = new cairo_skia_context_t;
if (unlikely (cr == NULL))
return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
cr->path = new SkPath;
cr->paint = new SkPaint;
}
_cairo_init (&cr->base, &_cairo_skia_context_backend);
cr->source = NULL;
cr->source_image = NULL;
cr->paint->setStrokeWidth (SkFloatToScalar (2.0));
cr->target = (cairo_skia_surface_t *) cairo_surface_reference ((cairo_surface_t *) target);
cr->original = (cairo_skia_surface_t *) cairo_surface_reference ((cairo_surface_t *) target);
cr->canvas = new SkCanvas (*surface->bitmap);
cr->canvas->save ();
cairo_matrix_init_identity (&cr->matrix);
return &cr->base;
}
示例4: switch
void FontPlatformData::setupPaint(SkPaint* paint) const
{
const float ts = m_textSize >= 0 ? m_textSize : 12;
paint->setAntiAlias(m_style.useAntiAlias == FontRenderStyle::NoPreference ? isSkiaAntiAlias : m_style.useAntiAlias);
switch (m_style.useHinting) {
case FontRenderStyle::NoPreference:
paint->setHinting(skiaHinting);
break;
case 0:
paint->setHinting(SkPaint::kNo_Hinting);
break;
default:
paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
break;
}
paint->setEmbeddedBitmapText(m_style.useBitmaps);
paint->setTextSize(SkFloatToScalar(ts));
paint->setTypeface(m_typeface);
paint->setFakeBoldText(m_fakeBold);
paint->setTextSkewX(m_fakeItalic ? -SK_Scalar1 / 4 : 0);
paint->setAutohinted(m_style.useAutoHint);
paint->setSubpixelText(m_style.useSubpixelPositioning == FontRenderStyle::NoPreference ? useSkiaSubpixelPositioning : m_style.useSubpixelPositioning);
if (m_style.useAntiAlias == 1 || (m_style.useAntiAlias == FontRenderStyle::NoPreference && isSkiaAntiAlias))
paint->setLCDRenderText(m_style.useSubpixelRendering == FontRenderStyle::NoPreference ? useSkiaSubpixelRendering : m_style.useSubpixelRendering);
}
示例5: setupPaint
void FontPlatformData::setupPaint(SkPaint* paint,
GraphicsContext* context) const {
paint->setAntiAlias(m_style.useAntiAlias);
paint->setHinting(static_cast<SkPaint::Hinting>(m_style.hintStyle));
paint->setEmbeddedBitmapText(m_style.useBitmaps);
paint->setAutohinted(m_style.useAutoHint);
if (m_style.useAntiAlias)
paint->setLCDRenderText(m_style.useSubpixelRendering);
// Do not enable subpixel text on low-dpi if full hinting is requested.
bool useSubpixelText = paint->getHinting() != SkPaint::kFull_Hinting ||
(context && context->deviceScaleFactor() > 1.0f);
// TestRunner specifically toggles the subpixel positioning flag.
if (useSubpixelText)
paint->setSubpixelText(true);
else
paint->setSubpixelText(m_style.useSubpixelPositioning);
const float ts = m_textSize >= 0 ? m_textSize : 12;
paint->setTextSize(SkFloatToScalar(ts));
paint->setTypeface(m_typeface);
paint->setFakeBoldText(m_syntheticBold);
paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0);
}
示例6: get_adjusted_radii
static void get_adjusted_radii(SkScalar passRadius, int *loRadius, int *hiRadius)
{
*loRadius = *hiRadius = SkScalarCeil(passRadius);
if (SkIntToScalar(*hiRadius) - passRadius > SkFloatToScalar(0.5f)) {
*loRadius = *hiRadius - 1;
}
}
示例7: createEmboss
static SkMaskFilter* createEmboss(JNIEnv* env, jobject, jfloatArray dirArray, float ambient, float specular, float radius) {
SkScalar direction[3];
AutoJavaFloatArray autoDir(env, dirArray, 3);
float* values = autoDir.ptr();
for (int i = 0; i < 3; i++) {
direction[i] = SkFloatToScalar(values[i]);
}
SkMaskFilter* filter = SkBlurMaskFilter::CreateEmboss(direction,
SkFloatToScalar(ambient),
SkFloatToScalar(specular),
SkFloatToScalar(radius));
ThrowIAE_IfNull(env, filter);
return filter;
}
示例8: input
sk_sp<SkImageFilter> FEDropShadow::createImageFilter() {
sk_sp<SkImageFilter> input(
SkiaImageFilterBuilder::build(inputEffect(0), operatingColorSpace()));
float dx = getFilter()->applyHorizontalScale(m_dx);
float dy = getFilter()->applyVerticalScale(m_dy);
float stdX = getFilter()->applyHorizontalScale(m_stdX);
float stdY = getFilter()->applyVerticalScale(m_stdY);
Color color = adaptColorToOperatingColorSpace(
m_shadowColor.combineWithAlpha(m_shadowOpacity));
SkImageFilter::CropRect cropRect = getCropRect();
return SkDropShadowImageFilter::Make(
SkFloatToScalar(dx), SkFloatToScalar(dy), SkFloatToScalar(stdX),
SkFloatToScalar(stdY), color.rgb(),
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
std::move(input), &cropRect);
}
示例9: MarkChanged
void
DrawTargetSkia::StrokeLine(const Point &aStart,
const Point &aEnd,
const Pattern &aPattern,
const StrokeOptions &aStrokeOptions,
const DrawOptions &aOptions)
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
return;
}
mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y),
SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y),
paint.mPaint);
}
示例10: SkFloatToScalar
void TextLayout::drawTextOnPath(SkPaint* paint, const Char16* text, Int32 count,
Int32 bidiFlags, Float hOffset, Float vOffset,
SkPath* path, SkCanvas* canvas)
{
SkScalar h_ = SkFloatToScalar(hOffset);
SkScalar v_ = SkFloatToScalar(vOffset);
sp<TextLayoutValue> value = TextLayoutEngine::getInstance().getValue(paint,
text, 0, count, count, bidiFlags);
if (value == NULL) {
return;
}
// Beware: this needs Glyph encoding (already done on the Paint constructor)
canvas->drawTextOnPathHV(value->getGlyphs(), value->getGlyphsCount() * 2, *path, h_, v_, *paint);
}
示例11: SkPathContainsPoint
bool SkPathContainsPoint(const SkPath& originalPath, const FloatPoint& point, SkPath::FillType ft)
{
SkRect bounds = originalPath.getBounds();
// We can immediately return false if the point is outside the bounding
// rect. We don't use bounds.contains() here, since it would exclude
// points on the right and bottom edges of the bounding rect, and we want
// to include them.
SkScalar fX = SkFloatToScalar(point.x());
SkScalar fY = SkFloatToScalar(point.y());
if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > bounds.fBottom)
return false;
// Scale the path to a large size before hit testing for two reasons:
// 1) Skia has trouble with coordinates close to the max signed 16-bit values, so we scale larger paths down.
// TODO: when Skia is patched to work properly with large values, this will not be necessary.
// 2) Skia does not support analytic hit testing, so we scale paths up to do raster hit testing with subpixel accuracy.
// 3) Scale the x/y axis separately so an extreme large/small scale factor on one axis won't
// ruin the resolution of the other axis.
SkScalar biggestCoordX = std::max(bounds.fRight, -bounds.fLeft);
SkScalar biggestCoordY = std::max(bounds.fBottom, -bounds.fTop);
if (SkScalarNearlyZero(biggestCoordX) || SkScalarNearlyZero(biggestCoordY))
return false;
biggestCoordX = std::max(biggestCoordX, std::fabs(fX) + 1);
biggestCoordY = std::max(biggestCoordY, std::fabs(fY) + 1);
const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15);
SkScalar scaleX = kMaxCoordinate / biggestCoordX;
SkScalar scaleY = kMaxCoordinate / biggestCoordY;
SkRegion rgn;
SkRegion clip;
SkMatrix m;
SkPath scaledPath(originalPath);
scaledPath.setFillType(ft);
m.setScale(scaleX, scaleY);
scaledPath.transform(m, 0);
int x = static_cast<int>(floorf(0.5f + point.x() * scaleX));
int y = static_cast<int>(floorf(0.5f + point.y() * scaleY));
clip.setRect(x - 1, y - 1, x + 1, y + 1);
return rgn.setPath(scaledPath, clip);
}
示例12: SkFloatToScalar
void PlatformGraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
{
size_t dashLength = dashes.size();
if (!dashLength)
return;
size_t count = !(dashLength % 2) ? dashLength : dashLength * 2;
SkScalar* intervals = new SkScalar[count];
for (unsigned int i = 0; i < count; i++)
intervals[i] = SkFloatToScalar(dashes[i % dashLength]);
SkPathEffect **effectPtr = &m_state->pathEffect;
SkSafeUnref(*effectPtr);
*effectPtr = new SkDashPathEffect(intervals, count, SkFloatToScalar(dashOffset));
delete[] intervals;
}
示例13: input
PassRefPtr<SkImageFilter> FEConvolveMatrix::createImageFilter(SkiaImageFilterBuilder* builder)
{
RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
SkISize kernelSize(SkISize::Make(m_kernelSize.width(), m_kernelSize.height()));
int numElements = kernelSize.width() * kernelSize.height();
SkScalar gain = SkFloatToScalar(1.0f / m_divisor);
SkScalar bias = SkFloatToScalar(m_bias * 255);
SkIPoint target = SkIPoint::Make(m_targetOffset.x(), m_targetOffset.y());
SkMatrixConvolutionImageFilter::TileMode tileMode = toSkiaTileMode(m_edgeMode);
bool convolveAlpha = !m_preserveAlpha;
OwnPtr<SkScalar[]> kernel = adoptArrayPtr(new SkScalar[numElements]);
for (int i = 0; i < numElements; ++i)
kernel[i] = SkFloatToScalar(m_kernelMatrix[numElements - 1 - i]);
SkImageFilter::CropRect cropRect = getCropRect(builder->cropOffset());
return adoptRef(SkMatrixConvolutionImageFilter::Create(kernelSize, kernel.get(), gain, bias, target, tileMode, convolveAlpha, input.get(), &cropRect));
}
示例14: transformAngle
static inline float transformAngle(const SkMatrix* matrix, float angleRadians) {
// Construct and transform a vector oriented at the specified clockwise angle from vertical.
// Coordinate system: down is increasing Y, right is increasing X.
SkPoint vector;
vector.fX = SkFloatToScalar(sinf(angleRadians));
vector.fY = SkFloatToScalar(-cosf(angleRadians));
matrix->mapVectors(& vector, 1);
// Derive the transformed vector's clockwise angle from vertical.
float result = atan2f(SkScalarToFloat(vector.fX), SkScalarToFloat(-vector.fY));
if (result < - M_PI_2) {
result += M_PI;
} else if (result > M_PI_2) {
result -= M_PI;
}
return result;
}
示例15: SkFloatToScalar
SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) {
SkScalar seconds = SkFloatToScalar(gAnimTime / 1000.0f);
SkScalar value = SkScalarMul(speed, seconds);
if (period) {
value = SkScalarMod(value, period);
}
return value;
}