void drawGlyph (int glyphNumber, const AffineTransform& transform)
    {
        currentState->createBrush();
        currentState->createFont();

        float hScale = currentState->font.getHorizontalScale();

        renderingTarget->SetTransform (transformToMatrix (AffineTransform::scale (hScale, 1.0f)
                                                                          .followedBy (transform)
                                                                          .followedBy (currentState->transform)));

        const UINT16 glyphIndices = (UINT16) glyphNumber;
        const FLOAT glyphAdvances = 0;
        DWRITE_GLYPH_OFFSET offset;
        offset.advanceOffset = 0;
        offset.ascenderOffset = 0;

        DWRITE_GLYPH_RUN glyphRun;
        glyphRun.fontFace = currentState->currentFontFace;
        glyphRun.fontEmSize = (FLOAT) (currentState->font.getHeight() * currentState->fontHeightToEmSizeFactor);
        glyphRun.glyphCount = 1;
        glyphRun.glyphIndices = &glyphIndices;
        glyphRun.glyphAdvances = &glyphAdvances;
        glyphRun.glyphOffsets = &offset;
        glyphRun.isSideways = FALSE;
        glyphRun.bidiLevel = 0;

        renderingTarget->DrawGlyphRun (D2D1::Point2F (0, 0), &glyphRun, currentState->currentBrush);
        renderingTarget->SetTransform (D2D1::IdentityMatrix());
    }
        void clipToImage (const Image& image, const AffineTransform& transform)
        {
            clearImageClip();

            if (bitmapMaskLayer == 0)
                owner.renderingTarget->CreateLayer (bitmapMaskLayer.resetAndGetPointerAddress());

            D2D1_BRUSH_PROPERTIES brushProps;
            brushProps.opacity = 1;
            brushProps.transform = transformToMatrix (transform);

            D2D1_BITMAP_BRUSH_PROPERTIES bmProps = D2D1::BitmapBrushProperties (D2D1_EXTEND_MODE_WRAP, D2D1_EXTEND_MODE_WRAP);

            D2D1_SIZE_U size;
            size.width = image.getWidth();
            size.height = image.getHeight();

            D2D1_BITMAP_PROPERTIES bp = D2D1::BitmapProperties();

            maskImage = image.convertedToFormat (Image::ARGB);
            Image::BitmapData bd (this->image, Image::BitmapData::readOnly); // xxx should be maskImage?
            bp.pixelFormat = owner.renderingTarget->GetPixelFormat();
            bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;

            HRESULT hr = owner.renderingTarget->CreateBitmap (size, bd.data, bd.lineStride, bp, maskBitmap.resetAndGetPointerAddress());
            hr = owner.renderingTarget->CreateBitmapBrush (maskBitmap, bmProps, brushProps, bitmapMaskBrush.resetAndGetPointerAddress());

            imageMaskLayerParams = D2D1::LayerParameters();
            imageMaskLayerParams.opacityBrush = bitmapMaskBrush;

            shouldClipBitmap = true;
            pushClips();
        }
 void fillRect (const Rectangle<float>& r)
 {
     renderingTarget->SetTransform (transformToMatrix (currentState->transform));
     currentState->createBrush();
     renderingTarget->FillRectangle (rectangleToRectF (r), currentState->currentBrush);
     renderingTarget->SetTransform (D2D1::IdentityMatrix());
 }
 void fillRect (const Rectangle<int>& r, bool /*replaceExistingContents*/)
 {
     renderingTarget->SetTransform (transformToMatrix (currentState->transform));
     currentState->createBrush();
     renderingTarget->FillRectangle (rectangleToRectF (r), currentState->currentBrush);
     renderingTarget->SetTransform (D2D1::IdentityMatrix());
 }
bool Direct2DLowLevelGraphicsContext::drawTextLayout (const AttributedString& text, const Rectangle<float>& area)
{
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    const Direct2DFactories& factories = Direct2DFactories::getInstance();
    Rectangle<float>  newArea(area.getX(), area.getY(), area.getWidth(), area.getHeight());
    DirectWriteTypeLayout::drawToD2DContext (text, newArea, renderingTarget, factories.directWriteFactory, factories.d2dFactory, factories.systemFonts);
    return true;
}
void Direct2DLowLevelGraphicsContext::drawHorizontalLine (int y, float left, float right)
{
    // xxx doesn't seem to be correctly aligned, may need nudging by 0.5 to match the software renderer's behaviour
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    currentState->createBrush();

    renderingTarget->DrawLine (D2D1::Point2F (left, (FLOAT) y),
                                D2D1::Point2F (right, (FLOAT) y),
                                currentState->currentBrush);
}
void Direct2DLowLevelGraphicsContext::drawVerticalLine (int x, float top, float bottom)
{
    // xxx doesn't seem to be correctly aligned, may need nudging by 0.5 to match the software renderer's behaviour
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    currentState->createBrush();

    renderingTarget->DrawLine (D2D1::Point2F ((FLOAT) x, top),
                                D2D1::Point2F ((FLOAT) x, bottom),
                                currentState->currentBrush);
}
void Direct2DLowLevelGraphicsContext::drawLine (const Line <float>& line)
{
    // xxx doesn't seem to be correctly aligned, may need nudging by 0.5 to match the software renderer's behaviour
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    currentState->createBrush();

    renderingTarget->DrawLine (D2D1::Point2F (line.getStartX(), line.getStartY()),
                                D2D1::Point2F (line.getEndX(), line.getEndY()),
                                currentState->currentBrush);
}
    bool drawTextLayout (const AttributedString& text, const Rectangle<float>& area)
    {
        renderingTarget->SetTransform (transformToMatrix (currentState->transform));

        DirectWriteTypeLayout::drawToD2DContext (text, area, renderingTarget, factories->directWriteFactory,
                                                 factories->d2dFactory, factories->systemFonts);

        renderingTarget->SetTransform (D2D1::IdentityMatrix());
        return true;
    }
예제 #10
0
        void TransformUtil::transformPointWithParent(DBTransform &transform, DBTransform &parent)
        {
            transformToMatrix(parent, _helpMatrix);
            _helpMatrix = MatrixInvert(_helpMatrix);

            Number x = transform.x;
            Number y = transform.y;

            transform.x = _helpMatrix.a * x + _helpMatrix.c * y + _helpMatrix.tx;
            transform.y = _helpMatrix.b * x + _helpMatrix.d * y + _helpMatrix.ty;

            transform.skewX = formatRadian(transform.skewX - parent.skewX);
            transform.skewY = formatRadian(transform.skewY - parent.skewY);
        }
void Direct2DLowLevelGraphicsContext::drawImage (const Image& image, const AffineTransform& transform)
{
    renderingTarget->SetTransform (transformToMatrix (transform.followedBy (currentState->transform)));

    D2D1_SIZE_U size;
    size.width = image.getWidth();
    size.height = image.getHeight();

    D2D1_BITMAP_PROPERTIES bp = D2D1::BitmapProperties();

    Image img (image.convertedToFormat (Image::ARGB));
    Image::BitmapData bd (img, Image::BitmapData::readOnly);
    bp.pixelFormat = renderingTarget->GetPixelFormat();
    bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;

    {
        ComSmartPtr <ID2D1Bitmap> tempBitmap;
        renderingTarget->CreateBitmap (size, bd.data, bd.lineStride, bp, tempBitmap.resetAndGetPointerAddress());
        if (tempBitmap != nullptr)
            renderingTarget->DrawBitmap (tempBitmap);
    }
}
        void createBrush()
        {
            if (currentBrush == 0)
            {
                if (fillType.isColour())
                {
                    D2D1_COLOR_F colour = colourToD2D (fillType.colour);
                    owner.colourBrush->SetColor (colour);
                    currentBrush = owner.colourBrush;
                }
                else if (fillType.isTiledImage())
                {
                    D2D1_BRUSH_PROPERTIES brushProps;
                    brushProps.opacity = fillType.getOpacity();
                    brushProps.transform = transformToMatrix (fillType.transform);

                    D2D1_BITMAP_BRUSH_PROPERTIES bmProps = D2D1::BitmapBrushProperties (D2D1_EXTEND_MODE_WRAP,D2D1_EXTEND_MODE_WRAP);

                    image = fillType.image;

                    D2D1_SIZE_U size;
                    size.width = image.getWidth();
                    size.height = image.getHeight();

                    D2D1_BITMAP_PROPERTIES bp = D2D1::BitmapProperties();

                    this->image = image.convertedToFormat (Image::ARGB);
                    Image::BitmapData bd (this->image, Image::BitmapData::readOnly);
                    bp.pixelFormat = owner.renderingTarget->GetPixelFormat();
                    bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;

                    HRESULT hr = owner.renderingTarget->CreateBitmap (size, bd.data, bd.lineStride, bp, bitmap.resetAndGetPointerAddress());
                    hr = owner.renderingTarget->CreateBitmapBrush (bitmap, bmProps, brushProps, bitmapBrush.resetAndGetPointerAddress());

                    currentBrush = bitmapBrush;
                }
                else if (fillType.isGradient())
                {
                    gradientStops = 0;

                    D2D1_BRUSH_PROPERTIES brushProps;
                    brushProps.opacity = fillType.getOpacity();
                    brushProps.transform = transformToMatrix (fillType.transform.followedBy (transform));

                    const int numColors = fillType.gradient->getNumColours();

                    HeapBlock<D2D1_GRADIENT_STOP> stops (numColors);

                    for (int i = fillType.gradient->getNumColours(); --i >= 0;)
                    {
                        stops[i].color = colourToD2D (fillType.gradient->getColour(i));
                        stops[i].position = (FLOAT) fillType.gradient->getColourPosition(i);
                    }

                    owner.renderingTarget->CreateGradientStopCollection (stops.getData(), numColors, gradientStops.resetAndGetPointerAddress());

                    if (fillType.gradient->isRadial)
                    {
                        radialGradient = 0;

                        const Point<float> p1 = fillType.gradient->point1;
                        const Point<float> p2 = fillType.gradient->point2;
                        float r = p1.getDistanceFrom (p2);

                        D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES props =
                            D2D1::RadialGradientBrushProperties (D2D1::Point2F (p1.x, p1.y),
                                                                 D2D1::Point2F (0, 0),
                                                                 r, r);

                        owner.renderingTarget->CreateRadialGradientBrush (props, brushProps, gradientStops, radialGradient.resetAndGetPointerAddress());
                        currentBrush = radialGradient;
                    }
                    else
                    {
                        linearGradient = 0;

                        const Point<float> p1 = fillType.gradient->point1;
                        const Point<float> p2 = fillType.gradient->point2;

                        D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES props =
                            D2D1::LinearGradientBrushProperties (D2D1::Point2F (p1.x, p1.y),
                                                                 D2D1::Point2F (p2.x, p2.y));

                        owner.renderingTarget->CreateLinearGradientBrush (props, brushProps, gradientStops, linearGradient.resetAndGetPointerAddress());

                        currentBrush = linearGradient;
                    }
                }
            }
        }
void Direct2DLowLevelGraphicsContext::fillRect (const Rectangle<int>& r, bool /*replaceExistingContents*/)
{
    renderingTarget->SetTransform (transformToMatrix (currentState->transform));
    currentState->createBrush();
    renderingTarget->FillRectangle (rectangleToRectF (r), currentState->currentBrush);
}