void ACanvasSkia::_SetPaint_Font() { AFont* pFont = GetFont(); AString sFontName; sFontName = pFont->GetName(); SkTypeface* tf = NULL; std::map<AString,SkTypeface*>::iterator it=m_aFontType.find(sFontName); if( it != m_aFontType.end() ) tf = it->second; //SkTypeface* tf = SkTypeface::CreateFromName(sFontName.ConvertTo(),SkTypeface::kNormal); if( tf == NULL ) { tf = SkTypeface::CreateFromName(sFontName.ConvertTo(),SkTypeface::kNormal); m_aFontType[sFontName] = tf; //tf->ref(); } if( tf ) m_Paint.setTypeface(tf);//->unref(); m_Paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); if( (pFont->GetStyle() & FontStyleBold) == FontStyleBold ) m_Paint.setFakeBoldText(true); if( (pFont->GetStyle() & FontStyleItalic) == FontStyleItalic ) m_Paint.setTextSkewX(0.25); m_Paint.setColor( toSkColor( pFont->GetColor() ) ); m_Paint.setTextSize(SkIntToScalar(pFont->GetSize())); }
void ACanvasSkia::_SetPaint_Draw() { APen* pen = GetPen(); m_Paint.setColor(toSkColor(pen->GetColor())); m_Paint.setStrokeWidth(SkScalar(pen->GetWidth())); m_Paint.setStyle(SkPaint::kStroke_Style); }
void ACanvasSkia::_SetPaint_Fill() { ABrush* br = GetBrush(); m_Paint.setStyle(SkPaint::kFill_Style); if( br->GetType() == BrushTypeSolidColor ) { ASolidBrush* sb = (ASolidBrush *)br; m_Paint.setColor(toSkColor(sb->GetColor())); } else if( br->GetType() == BrushTypeLinearGradient ) { SkPoint pts[2]; ALinearGradientBrush* lgb = (ALinearGradientBrush*)br; SkRect rx = ToSkRect( lgb->GetRect() ); pts[0].set( rx.fLeft,rx.fTop ); if( lgb->IsVert() ) pts[1].set( rx.fLeft,rx.fBottom ); else pts[1].set( rx.fRight,rx.fTop ); SkColor colors[2]; colors[0] = toSkColor( lgb->GetStartColor() ); colors[1] = toSkColor( lgb->GetEndColor() ); SkScalar pos[2]; pos[0] = SkScalar(0.0); pos[1] = SkScalar(1.0); SkShader* pShader = SkGradientShader::CreateLinear(pts,colors,pos,2,SkShader::kClamp_TileMode); m_Paint.setShader(pShader)->unref(); } else if( br->GetType() == BrushTypeRadialGradient ) { ARadialBrush* rb = (ARadialBrush*)br; SkPoint ptCenter; APoint ptCenter0 = rb->GetCenter(); ptCenter.set( SkIntToScalar(ptCenter0.x),SkIntToScalar(ptCenter0.y) ); SkScalar nRadius = SkIntToScalar( rb->GetRadius() ); SkColor colors[2]; colors[0] = toSkColor( rb->GetStartColor() ); colors[1] = toSkColor( rb->GetEndColor() ); SkScalar pos[2]; pos[0] = SkScalar(0.0); pos[1] = SkScalar(1.0); SkShader* pShader = SkGradientShader::CreateRadial(ptCenter,nRadius,colors,pos,2,SkShader::kClamp_TileMode); m_Paint.setShader(pShader)->unref(); } }
void OsmAnd::MapRasterizer_P::rasterize( const AreaI area31, const std::shared_ptr<const MapPrimitiviser::PrimitivisedObjects>& primitivisedObjects, SkCanvas& canvas, const bool fillBackground, const AreaI* const pDestinationArea, MapRasterizer_Metrics::Metric_rasterize* const metric, const std::shared_ptr<const IQueryController>& queryController) { const Stopwatch totalStopwatch(metric != nullptr); const Context context( area31, primitivisedObjects, pDestinationArea ? *pDestinationArea : AreaI(0, 0, canvas.imageInfo().height(), canvas.imageInfo().width())); // Deal with background if (fillBackground) { // Get default background color const auto defaultBackgroundColor = context.env->getDefaultBackgroundColor(context.zoom); if (pDestinationArea) { // If destination area is specified, fill only it with background SkPaint bgPaint; bgPaint.setColor(defaultBackgroundColor.toSkColor()); bgPaint.setStyle(SkPaint::kFill_Style); canvas.drawRectCoords( pDestinationArea->top(), pDestinationArea->left(), pDestinationArea->right(), pDestinationArea->bottom(), bgPaint); } else { // Since destination area is not specified, erase whole canvas with specified color canvas.clear(defaultBackgroundColor.toSkColor()); } } AreaI destinationArea; if (pDestinationArea) { destinationArea = *pDestinationArea; } else { const auto targetSize = canvas.getDeviceSize(); destinationArea = AreaI(0, 0, targetSize.height(), targetSize.width()); } // Rasterize layers of map: rasterizeMapPrimitives(context, canvas, primitivisedObjects->polygons, PrimitivesType::Polygons, queryController); if (context.shadowMode != MapPresentationEnvironment::ShadowMode::NoShadow) rasterizeMapPrimitives(context, canvas, primitivisedObjects->polylines, PrimitivesType::Polylines_ShadowOnly, queryController); rasterizeMapPrimitives(context, canvas, primitivisedObjects->polylines, PrimitivesType::Polylines, queryController); if (metric) metric->elapsedTime += totalStopwatch.elapsed(); }