Example #1
0
void EmfPaintEngine::drawTextItem ( const QPointF & p, const QTextItem & textItem )
{
	setClipping();

	SetBkMode( metaDC, TRANSPARENT );

	QFont f = textItem.font();
	QFontMetrics fm(f);
	HFONT wfont = CreateFontA(fm.height() - 1, fm.averageCharWidth(), 0, 0,
				10*f.weight(), f.italic(), f.underline (), f.strikeOut(),
				DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY, DEFAULT_PITCH, f.family().toAscii().data());
	SelectObject( metaDC, wfont);

	QColor colour = painter()->pen().color();
	SetTextColor( metaDC, RGB(colour.red(), colour.green(), colour.blue()));

	QString text = textItem.text();
	int size = text.size();

	QMatrix m = painter()->worldMatrix();

	XFORM xf;
	xf.eM11 = m.m11();
	xf.eM12 = m.m12();
	xf.eM21 = m.m21();
	xf.eM22 = m.m22();
	xf.eDx = m.dx();
	xf.eDy = m.dy();
	SetWorldTransform(metaDC, &xf);

#ifdef Q_WS_WIN
	wchar_t *wtext = (wchar_t *)malloc(size*sizeof(wchar_t));
	if (!wtext){
		qWarning("EmfEngine: Not enough memory in drawTextItem().");
		return;
	}
	
	size = text.toWCharArray(wtext);
	TextOutW(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), wtext, size);
	free(wtext);
#else
	TextOutA(metaDC, qRound(p.x()), qRound(p.y() - 0.85*fm.height()), text.toLocal8Bit().data(), size);
#endif

	xf.eM11 = 1.0;
	xf.eM12 = 0.0;
	xf.eM21 = 0.0;
	xf.eM22 = 1.0;
	xf.eDx = 0.0;
	xf.eDy = 0.0;
	SetWorldTransform(metaDC, &xf);

	resetClipping();
	DeleteObject(wfont);
}
void UDebugSkelMeshComponent::ConsumeRootMotion(const FVector& FloorMin, const FVector& FloorMax)
{
	if (bPreviewRootMotion)
	{
		if (UAnimInstance* AnimInst = GetAnimInstance())
		{
			FRootMotionMovementParams ExtractedRootMotion = AnimInst->ConsumeExtractedRootMotion();
			if (ExtractedRootMotion.bHasRootMotion)
			{
				AddLocalTransform(ExtractedRootMotion.RootMotionTransform);

				//Handle moving component so that it stays within the editor floor
				FTransform CurrentTransform = GetRelativeTransform();
				FVector Trans = CurrentTransform.GetTranslation();
				Trans.X = WrapInRange(Trans.X, FloorMin.X, FloorMax.X);
				Trans.Y = WrapInRange(Trans.Y, FloorMin.Y, FloorMax.Y);
				CurrentTransform.SetTranslation(Trans);
				SetRelativeTransform(CurrentTransform);
			}
		}
	}
	else
	{
		SetWorldTransform(FTransform());
	}
}
void
_cairo_win32_display_surface_unset_clip (cairo_win32_display_surface_t *surface)
{
    XFORM saved_xform;
    int gm = GetGraphicsMode (surface->win32.dc);
    if (gm == GM_ADVANCED) {
	GetWorldTransform (surface->win32.dc, &saved_xform);
	ModifyWorldTransform (surface->win32.dc, NULL, MWT_IDENTITY);
    }

    /* initial_clip_rgn will either be a real region or NULL (which means reset to no clip region) */
    SelectClipRgn (surface->win32.dc, surface->initial_clip_rgn);

    if (surface->had_simple_clip) {
	/* then if we had a simple clip, intersect */
	IntersectClipRect (surface->win32.dc,
			   surface->win32.extents.x,
			   surface->win32.extents.y,
			   surface->win32.extents.x + surface->win32.extents.width,
			   surface->win32.extents.y + surface->win32.extents.height);
    }

    if (gm == GM_ADVANCED)
	SetWorldTransform (surface->win32.dc, &saved_xform);
}
void
gfxWindowsNativeDrawing::EndNativeDrawing()
{
    if (mRenderState == RENDER_STATE_NATIVE_DRAWING) {
        // we drew directly to the HDC in the context; undo our changes
        SetViewportOrgEx(mDC, mOrigViewportOrigin.x, mOrigViewportOrigin.y, NULL);

        if (mTransformType != TRANSLATION_ONLY)
            SetWorldTransform(mDC, &mOldWorldTransform);

        mWinSurface->MarkDirty();

        mRenderState = RENDER_STATE_NATIVE_DRAWING_DONE;
    } else if (mRenderState == RENDER_STATE_ALPHA_RECOVERY_BLACK) {
        mBlackSurface = mWinSurface;
        mWinSurface = nsnull;

        mRenderState = RENDER_STATE_ALPHA_RECOVERY_BLACK_DONE;
    } else if (mRenderState == RENDER_STATE_ALPHA_RECOVERY_WHITE) {
        mWhiteSurface = mWinSurface;
        mWinSurface = nsnull;

        mRenderState = RENDER_STATE_ALPHA_RECOVERY_WHITE_DONE;
    } else {
        NS_ERROR("Invalid RenderState in gfxWindowsNativeDrawing::EndNativeDrawing");
    }
}
Example #5
0
void GraphicsContextPlatformPrivate::setCTM(const AffineTransform& transform)
{
    if (!m_hdc)
        return;

    XFORM xform = transform.toTransformationMatrix();
    SetWorldTransform(m_hdc, &xform);
}
static cairo_int_status_t
_cairo_win32_save_initial_clip (HDC hdc, cairo_win32_display_surface_t *surface)
{
    RECT rect;
    int clipBoxType;
    int gm;
    XFORM saved_xform;

    /* GetClipBox/GetClipRgn and friends interact badly with a world transform
     * set.  GetClipBox returns values in logical (transformed) coordinates;
     * it's unclear what GetClipRgn returns, because the region is empty in the
     * case of a SIMPLEREGION clip, but I assume device (untransformed) coordinates.
     * Similarly, IntersectClipRect works in logical units, whereas SelectClipRgn
     * works in device units.
     *
     * So, avoid the whole mess and get rid of the world transform
     * while we store our initial data and when we restore initial coordinates.
     *
     * XXX we may need to modify x/y by the ViewportOrg or WindowOrg
     * here in GM_COMPATIBLE; unclear.
     */
    gm = GetGraphicsMode (hdc);
    if (gm == GM_ADVANCED) {
	GetWorldTransform (hdc, &saved_xform);
	ModifyWorldTransform (hdc, NULL, MWT_IDENTITY);
    }

    clipBoxType = GetClipBox (hdc, &rect);
    if (clipBoxType == ERROR) {
	_cairo_win32_print_gdi_error (__FUNCTION__);
	SetGraphicsMode (hdc, gm);
	/* XXX: Can we make a more reasonable guess at the error cause here? */
	return _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
    }

    surface->win32.extents.x = rect.left;
    surface->win32.extents.y = rect.top;
    surface->win32.extents.width = rect.right - rect.left;
    surface->win32.extents.height = rect.bottom - rect.top;

    surface->initial_clip_rgn = NULL;
    surface->had_simple_clip = FALSE;

    if (clipBoxType == COMPLEXREGION) {
	surface->initial_clip_rgn = CreateRectRgn (0, 0, 0, 0);
	if (GetClipRgn (hdc, surface->initial_clip_rgn) <= 0) {
	    DeleteObject(surface->initial_clip_rgn);
	    surface->initial_clip_rgn = NULL;
	}
    } else if (clipBoxType == SIMPLEREGION) {
	surface->had_simple_clip = TRUE;
    }

    if (gm == GM_ADVANCED)
	SetWorldTransform (hdc, &saved_xform);

    return CAIRO_STATUS_SUCCESS;
}
Example #7
0
//-----------------------------------------------------------------------------
// Name: Frame::SetWorldPosition()
//-----------------------------------------------------------------------------
VOID Frame::SetWorldPosition( CONST XMVECTOR &NewPosition )
 {
    UpdateCachedWorldTransformIfNeeded();
    XMMATRIX ModifiedWorldTransform = m_CachedWorldTransform;

    ModifiedWorldTransform.r[3] = NewPosition;

    SetWorldTransform( ModifiedWorldTransform );
}
Example #8
0
void Node::SetParent(Node* parent)
{
    if (parent)
    {
        Vector3 worldPosition;
        Quaternion worldRotation;
        Vector3 worldScale;
        GetWorldTransform().Decompose(worldPosition, worldRotation, worldScale);
        
        parent->AddChild(this);
        SetWorldTransform(worldPosition, worldRotation, worldScale);
    }
}
Example #9
0
//-----------------------------------------------------------------------------
// Name: Frame::DisconnectFromParent
// Desc: Removes parent link from the object, and converts world transform
//       to local transform.  This method is only to be used on clones of
//       scene objects, since the parent is not notified of the disconnection.
//-----------------------------------------------------------------------------
VOID Frame::DisconnectFromParent()
{
    // Debug check to make sure the parent really isn't the parent of this clone
#ifdef _DEBUG
    if( m_pParent != NULL )
    {
        assert( !m_pParent->IsChild( this ) );
    }
#endif

    UpdateCachedWorldTransformIfNeeded();
    m_pParent = NULL;
    SetWorldTransform( m_CachedWorldTransform );
}
Example #10
0
void tFigure::vrash_cord(float tt,int xx,int yy)
        {
                XFORM xform;
                float angle=tt;
                angle = angle * 3.1416 / 180.0;
                xform.eDx = 0.0f;
                xform.eDy = 0.0f;
                xform.eM11 = cos(angle);
                xform.eM12 = sin(angle);
                xform.eM21 = -sin(angle);
                xform.eM22 = cos(angle);
                SetGraphicsMode(imj->Canvas->Handle, GM_ADVANCED);
                SetWorldTransform(imj->Canvas->Handle, &xform);
                SetViewportOrgEx(imj->Canvas->Handle,xx,yy,NULL);
        }
Example #11
0
//-----------------------------------------------------------------------------
// Name: Frame::SetParent()
//-----------------------------------------------------------------------------
VOID Frame::SetParent( Frame* pParent )
{
    Frame* pSrch, *pLast;

    UpdateCachedWorldTransformIfNeeded();

    if( m_pParent )
    {
        pLast = NULL;
        for( pSrch = m_pParent->m_pFirstChild; pSrch; pSrch = pSrch->m_pNextSibling )
        {
            if( pSrch == this )
                break;
            pLast = pSrch;
        }

        // If we can't find this frame in the old parent's list, assert
        assert( pSrch );

        // Remove us from the list
        if( pLast )
        {
            pLast->m_pNextSibling = m_pNextSibling;
        }
        else // at the beginning of the list
        {
            m_pParent->m_pFirstChild = m_pNextSibling;
        }

        m_pNextSibling = NULL;
        m_pParent = NULL;
    }

    // Add us to the new parent's list               
    if( pParent )
    {
        m_pParent = pParent;
        m_pNextSibling = pParent->m_pFirstChild;
        pParent->m_pFirstChild = this;
    }

    // now we update our local transform to match the old world transform
    // (i.e. move under our new parent's frame with no detectable change)

    XMMATRIX worldMatrix = m_CachedWorldTransform;
    SetWorldTransform( worldMatrix );
}
Example #12
0
    void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override {
        HDC hdc = static_cast<HDC>(handle);

        XFORM xf;
        xf.eM11 = ctm[SkMatrix::kMScaleX];
        xf.eM21 = ctm[SkMatrix::kMSkewX];
        xf.eDx = ctm[SkMatrix::kMTransX];
        xf.eM12 = ctm[SkMatrix::kMSkewY];
        xf.eM22 = ctm[SkMatrix::kMScaleY];
        xf.eDy = ctm[SkMatrix::kMTransY];
        SetWorldTransform(hdc, &xf);

        HRGN hrgn = CreateRectRgnIndirect(&toRECT(clip_bounds));
        int result = SelectClipRgn(hdc, hrgn);
        SkASSERT(result != ERROR);
        result = DeleteObject(hrgn);
        SkASSERT(result != 0);
    }
Example #13
0
void font_instance::InitTheFace()
{
#ifdef USE_PANGO_WIN32
    if ( !theFace ) {
        LOGFONT *lf=pango_win32_font_logfont(pFont);
        g_assert(lf != NULL);
        theFace=pango_win32_font_cache_load(daddy->pangoFontCache,lf);
        g_free(lf);
    }
    XFORM identity = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
    SetWorldTransform(daddy->hScreenDC, &identity);
    SetGraphicsMode(daddy->hScreenDC, GM_COMPATIBLE);
    SelectObject(daddy->hScreenDC,theFace);
#else
    theFace=pango_ft2_font_get_face(pFont); // Deprecated, use pango_fc_font_lock_face() instead
    if ( theFace ) {
        FT_Select_Charmap(theFace,ft_encoding_unicode) && FT_Select_Charmap(theFace,ft_encoding_symbol);
    }
#endif
}
Example #14
0
void CP3DRenderer::EndScene()
{
	P3DXMatrix matvp = g_matViewProj;
	P3DXMatrix matw;
	P3DXMatrix matwvp = matw * matvp;
	matw.SetIdentityMatrix();
	SetWorldTransform(matw);
	vb.Use();
	//effect.SetValue("gWVP", &matwvp, sizeof(P3DXMatrix));
	//effect.Begin("SolidTech");
	vb.Render(P3DPT_TRIANGLELIST, 0, 1);
	//effect.End();
	
	
	Prof(RENDERER_CP3DRenderer__EndScene);

/*
	// FIXME: TODO: debug !!!
	// testovat ci je vyhodne odoslat command buffer na spracovanie
	LPDIRECT3DQUERY9 pEventQuery = NULL;
	if (SUCCEEDED (g_pD3DDevice->CreateQuery(D3DQUERYTYPE_EVENT, &pEventQuery)))
	{
		pEventQuery->Issue(D3DISSUE_END);	// add an end marker to the command buffer queue.
		pEventQuery->GetData (NULL, 0, D3DGETDATA_FLUSH);	// empty the command buffer
		pEventQuery->Release ();
	}
	// FIXME: TODO: debug !!!
*/

	#ifdef _DEBUG
	g_stats.EndNewFrame();
	g_stats.DrawStats(); // STATS
	#endif

	g_pResMgr->RenderStats();

	// End the scene
	g_pD3DDevice->EndScene();
	// KEX: Proc?
}
Example #15
0
void StretchDrawTo(HDC handle,LPRECT rect,float Angle)
        {
        if(Angle==0)
                {
                StretchBlt(handle,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,
                   Canvas->Handle,0,0,Width,Height,SRCCOPY);
                }else
                {
                Angle=Angle*0.017453292;
                Angle=-Angle;
                XFORM Matrix;
                SetGraphicsMode(handle, GM_ADVANCED);
                Matrix.eM11 = 1;
                Matrix.eM12 = 0;
                Matrix.eM21 = 0;
                Matrix.eM22 = 1;
                Matrix.eDx = -rect->left;
                Matrix.eDy = -rect->top;
                SetWorldTransform(handle, &Matrix);
                Matrix.eM11 = cos(Angle);
                Matrix.eM12 = sin(Angle);
                Matrix.eM21 = -sin(Angle);
                Matrix.eM22 = cos(Angle);
                Matrix.eDx = 0;
                Matrix.eDy = 0;
                ModifyWorldTransform(handle, &Matrix, MWT_RIGHTMULTIPLY);
                Matrix.eM11 = 1;
                Matrix.eM12 = 0;
                Matrix.eM21 = 0;
                Matrix.eM22 = 1;
                Matrix.eDx = rect->left;
                Matrix.eDy = rect->top;
                ModifyWorldTransform(handle, &Matrix, MWT_RIGHTMULTIPLY);

                StretchBlt(handle,rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top,
                   Canvas->Handle,0,0,Width,Height,SRCCOPY);
                ModifyWorldTransform(handle, &Matrix, MWT_IDENTITY);
                }
        }
void UDebugSkelMeshComponent::ConsumeRootMotion(const FVector& FloorMin, const FVector& FloorMax)
{
	//Extract root motion regardless of where we use it so that we don't hit
	//problems with it building up in the instance

	FRootMotionMovementParams ExtractedRootMotion;

	if (UAnimInstance* AnimInst = GetAnimInstance())
	{
		ExtractedRootMotion = AnimInst->ConsumeExtractedRootMotion(1.f);
	}

	if (bPreviewRootMotion)
	{
		if (ExtractedRootMotion.bHasRootMotion)
		{
			AddLocalTransform(ExtractedRootMotion.RootMotionTransform);

			//Handle moving component so that it stays within the editor floor
			FTransform CurrentTransform = GetRelativeTransform();
			FVector Trans = CurrentTransform.GetTranslation();
			Trans.X = WrapInRange(Trans.X, FloorMin.X, FloorMax.X);
			Trans.Y = WrapInRange(Trans.Y, FloorMin.Y, FloorMax.Y);
			CurrentTransform.SetTranslation(Trans);
			SetRelativeTransform(CurrentTransform);
		}
	}
	else
	{
		if (TurnTableMode == EPersonaTurnTableMode::Stopped)
		{
			SetWorldTransform(FTransform());
		}
		else
		{
			SetRelativeLocation(FVector::ZeroVector);
		}
	}
}
Example #17
0
static cairo_surface_t *
_cairo_win32_printing_surface_create (HDC hdc)
{
    int x, y, x_dpi, y_dpi, x_off, y_off, depth;
    XFORM xform;
    cairo_surface_t *surface;

    x = GetDeviceCaps (hdc, HORZRES);
    y = GetDeviceCaps (hdc, VERTRES);

    x_dpi = GetDeviceCaps (hdc, LOGPIXELSX);
    y_dpi = GetDeviceCaps (hdc, LOGPIXELSY);

    x_off = GetDeviceCaps (hdc, PHYSICALOFFSETX);
    y_off = GetDeviceCaps (hdc, PHYSICALOFFSETY);

    depth = GetDeviceCaps(hdc, BITSPIXEL);

    SetGraphicsMode (hdc, GM_ADVANCED);
    xform.eM11 = x_dpi/72.0;
    xform.eM12 = 0;
    xform.eM21 = 0;
    xform.eM22 = y_dpi/72.0;
    xform.eDx = -x_off;
    xform.eDy = -y_off;
    SetWorldTransform (hdc, &xform);

    surface = cairo_win32_printing_surface_create (hdc);
    
    /**
		Read fallback dpi from device capabilities. Was a workaround for a bug patched
		in cairo 1.5.14. Without this, fallback defaults to 300dpi, which is quite acceptable.
		Going higher can cause spool size and memory problems.
	*/
    // cairo_surface_set_fallback_resolution (surface, x_dpi, y_dpi);

    return surface;
}
Example #18
0
static cairo_surface_t *
open_emf(int dpi, const char *fname)
{
  HDC hdc;
  cairo_surface_t *surface;
  XFORM xform = {1, 0, 0, 1, 0, 0};
  int disp_dpi;

  hdc = CreateEnhMetaFile(NULL, fname, NULL, NULL);
  if (hdc == NULL) {
    return NULL;
  }

  SetGraphicsMode(hdc, GM_ADVANCED);
  disp_dpi = GetDeviceCaps(hdc, LOGPIXELSX);
  xform.eM11 = xform.eM22 = 1.0 * disp_dpi / dpi;
  SetWorldTransform(hdc, &xform);

  surface = cairo_win32_printing_surface_create(hdc);
  StartPage(hdc);

  return surface;
}
DoubleBuffer::DoubleBuffer(HWND hwnd, RectI rect) :
    hTarget(hwnd), rect(rect), hdcBuffer(NULL), doubleBuffer(NULL)
{
    hdcCanvas = ::GetDC(hwnd);

    if (rect.IsEmpty())
        return;

    doubleBuffer = CreateCompatibleBitmap(hdcCanvas, rect.dx, rect.dy);
    if (!doubleBuffer)
        return;

    hdcBuffer = CreateCompatibleDC(hdcCanvas);
    if (!hdcBuffer)
        return;

    if (rect.x != 0 || rect.y != 0) {
        SetGraphicsMode(hdcBuffer, GM_ADVANCED);
        XFORM ctm = { 1.0, 0, 0, 1.0, (float)-rect.x, (float)-rect.y };
        SetWorldTransform(hdcBuffer, &ctm);
    }
    DeleteObject(SelectObject(hdcBuffer, doubleBuffer));
}
Example #20
0
    HDC CanvasGdiplus::BeginPlatformPaint()
    {
        DCHECK(mem_graphics_.get());

        Gdiplus::Matrix matrix;
        mem_graphics_->GetTransform(&matrix);
        Gdiplus::REAL elem[6];
        matrix.GetElements(elem);

        Gdiplus::Region region;
        mem_graphics_->GetClip(&region);
        HRGN hrgn = region.GetHRGN(mem_graphics_.get());

        HDC hdc = mem_graphics_->GetHDC();
        InitializeDC(hdc);

        XFORM xf = { elem[0], elem[1], elem[2], elem[3], elem[4], elem[5] };
        SetWorldTransform(hdc, &xf);

        SelectClipRgn(hdc, hrgn);
        DeleteObject(hrgn);

        return hdc;
    }
Example #21
0
static void drawGDIGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* font, const GlyphBuffer& glyphBuffer,
                          int from, int numGlyphs, const FloatPoint& point)
{
    Color fillColor = graphicsContext->fillColor();

    bool drawIntoBitmap = false;
    TextDrawingModeFlags drawingMode = graphicsContext->textDrawingMode();
    if (drawingMode == TextModeFill) {
        if (!fillColor.alpha())
            return;

        drawIntoBitmap = fillColor.alpha() != 255 || graphicsContext->inTransparencyLayer();
        if (!drawIntoBitmap) {
            FloatSize offset;
            float blur;
            Color color;
            ColorSpace shadowColorSpace;

            graphicsContext->getShadow(offset, blur, color, shadowColorSpace);
            drawIntoBitmap = offset.width() || offset.height() || blur;
        }
    }

    // We have to convert CG's two-dimensional floating point advances to just horizontal integer advances.
    Vector<int, 2048> gdiAdvances;
    int totalWidth = 0;
    for (int i = 0; i < numGlyphs; i++) {
        gdiAdvances.append(lroundf(glyphBuffer.advanceAt(from + i)));
        totalWidth += gdiAdvances[i];
    }

    HDC hdc = 0;
    OwnPtr<GraphicsContext::WindowsBitmap> bitmap;
    IntRect textRect;
    if (!drawIntoBitmap)
        hdc = graphicsContext->getWindowsContext(textRect, true, false);
    if (!hdc) {
        drawIntoBitmap = true;
        // We put slop into this rect, since glyphs can overflow the ascent/descent bounds and the left/right edges.
        // FIXME: Can get glyphs' optical bounds (even from CG) to get this right.
        const FontMetrics& fontMetrics = font->fontMetrics();
        int lineGap = fontMetrics.lineGap();
        textRect = IntRect(point.x() - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
                           point.y() - fontMetrics.ascent() - lineGap,
                           totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
                           fontMetrics.lineSpacing());
        bitmap = graphicsContext->createWindowsBitmap(textRect.size());
        memset(bitmap->buffer(), 255, bitmap->bufferLength());
        hdc = bitmap->hdc();

        XFORM xform;
        xform.eM11 = 1.0f;
        xform.eM12 = 0.0f;
        xform.eM21 = 0.0f;
        xform.eM22 = 1.0f;
        xform.eDx = -textRect.x();
        xform.eDy = -textRect.y();
        SetWorldTransform(hdc, &xform);
    }

    SelectObject(hdc, font->platformData().hfont());

    // Set the correct color.
    if (drawIntoBitmap)
        SetTextColor(hdc, RGB(0, 0, 0));
    else
        SetTextColor(hdc, RGB(fillColor.red(), fillColor.green(), fillColor.blue()));

    SetBkMode(hdc, TRANSPARENT);
    SetTextAlign(hdc, TA_LEFT | TA_BASELINE);

    // Uniscribe gives us offsets to help refine the positioning of combining glyphs.
    FloatSize translation = glyphBuffer.offsetAt(from);
    if (translation.width() || translation.height()) {
        XFORM xform;
        xform.eM11 = 1.0;
        xform.eM12 = 0;
        xform.eM21 = 0;
        xform.eM22 = 1.0;
        xform.eDx = translation.width();
        xform.eDy = translation.height();
        ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
    }

    if (drawingMode == TextModeFill) {
        XFORM xform;
        xform.eM11 = 1.0;
        xform.eM12 = 0;
        xform.eM21 = font->platformData().syntheticOblique() ? -tanf(syntheticObliqueAngle * piFloat / 180.0f) : 0;
        xform.eM22 = 1.0;
        xform.eDx = point.x();
        xform.eDy = point.y();
        ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
        ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data());
        if (font->syntheticBoldOffset()) {
            xform.eM21 = 0;
            xform.eDx = font->syntheticBoldOffset();
            xform.eDy = 0;
            ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
            ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data());
        }
    } else {
        XFORM xform;
        GetWorldTransform(hdc, &xform);
        AffineTransform hdcTransform(xform.eM11, xform.eM21, xform.eM12, xform.eM22, xform.eDx, xform.eDy);
        CGAffineTransform initialGlyphTransform = hdcTransform.isInvertible() ? hdcTransform.inverse() : CGAffineTransformIdentity;
        if (font->platformData().syntheticOblique())
            initialGlyphTransform = CGAffineTransformConcat(initialGlyphTransform, CGAffineTransformMake(1, 0, tanf(syntheticObliqueAngle * piFloat / 180.0f), 1, 0, 0));
        initialGlyphTransform.tx = 0;
        initialGlyphTransform.ty = 0;
        CGContextRef cgContext = graphicsContext->platformContext();

        CGContextSaveGState(cgContext);

        BOOL fontSmoothingEnabled = false;
        SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothingEnabled, 0);
        CGContextSetShouldAntialias(cgContext, fontSmoothingEnabled);

        CGContextScaleCTM(cgContext, 1.0, -1.0);
        CGContextTranslateCTM(cgContext, point.x() + glyphBuffer.offsetAt(from).width(), -(point.y() + glyphBuffer.offsetAt(from).height()));

        for (unsigned i = 0; i < numGlyphs; ++i) {
            RetainPtr<CGPathRef> glyphPath(AdoptCF, createPathForGlyph(hdc, glyphBuffer.glyphAt(from + i)));
            CGContextSaveGState(cgContext);
            CGContextConcatCTM(cgContext, initialGlyphTransform);

            if (drawingMode & TextModeFill) {
                CGContextAddPath(cgContext, glyphPath.get());
                CGContextFillPath(cgContext);
                if (font->syntheticBoldOffset()) {
                    CGContextTranslateCTM(cgContext, font->syntheticBoldOffset(), 0);
                    CGContextAddPath(cgContext, glyphPath.get());
                    CGContextFillPath(cgContext);
                    CGContextTranslateCTM(cgContext, -font->syntheticBoldOffset(), 0);
                }
            }
            if (drawingMode & TextModeStroke) {
                CGContextAddPath(cgContext, glyphPath.get());
                CGContextStrokePath(cgContext);
                if (font->syntheticBoldOffset()) {
                    CGContextTranslateCTM(cgContext, font->syntheticBoldOffset(), 0);
                    CGContextAddPath(cgContext, glyphPath.get());
                    CGContextStrokePath(cgContext);
                    CGContextTranslateCTM(cgContext, -font->syntheticBoldOffset(), 0);
                }
            }

            CGContextRestoreGState(cgContext);
            CGContextTranslateCTM(cgContext, gdiAdvances[i], 0);
        }

        CGContextRestoreGState(cgContext);
    }

    if (drawIntoBitmap) {
        UInt8* buffer = bitmap->buffer();
        unsigned bufferLength = bitmap->bufferLength();
        for (unsigned i = 0; i < bufferLength; i += 4) {
            // Use green, which is always in the middle.
            UInt8 alpha = (255 - buffer[i + 1]) * fillColor.alpha() / 255;
            buffer[i] = fillColor.blue();
            buffer[i + 1] = fillColor.green();
            buffer[i + 2] = fillColor.red();
            buffer[i + 3] = alpha;
        }
        graphicsContext->drawWindowsBitmap(bitmap.get(), textRect.location());
    } else
        graphicsContext->releaseWindowsContext(hdc, textRect, true, false);
}
Example #22
0
static void test_world_transform(void)
{
    BOOL is_win9x;
    HDC hdc;
    INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
    XFORM xform;
    SIZE size;

    SetLastError(0xdeadbeef);
    GetWorldTransform(0, NULL);
    is_win9x = GetLastError() == ERROR_CALL_NOT_IMPLEMENTED;

    hdc = CreateCompatibleDC(0);

    xform.eM11 = 1.0f;
    xform.eM12 = 0.0f;
    xform.eM21 = 0.0f;
    xform.eM22 = 1.0f;
    xform.eDx = 0.0f;
    xform.eDy = 0.0f;
    ret = SetWorldTransform(hdc, &xform);
    ok(!ret, "SetWorldTransform should fail in GM_COMPATIBLE mode\n");

    size_cx = GetDeviceCaps(hdc, HORZSIZE);
    size_cy = GetDeviceCaps(hdc, VERTSIZE);
    res_x = GetDeviceCaps(hdc, HORZRES);
    res_y = GetDeviceCaps(hdc, VERTRES);
    dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
    dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
    trace("dc size %d x %d, resolution %d x %d dpi %d x %d\n",
          size_cx, size_cy, res_x, res_y, dpi_x, dpi_y );

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, 1000, 1000);

    SetLastError(0xdeadbeef);
    ret = SetMapMode(hdc, MM_LOMETRIC);
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);

    if (is_win9x)
    {
        expect_viewport_ext(hdc, dpi_x, dpi_y);
        expect_window_ext(hdc, 254, -254);
    }
    else
    {
        expect_viewport_ext(hdc, res_x, -res_y);
        ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
        ok( size.cx == size_cx * 10 ||
            size.cx == MulDiv( res_x, 254, dpi_x ),  /* Vista uses a more precise method */
            "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
        ok( size.cy == size_cy * 10 ||
            size.cy == MulDiv( res_y, 254, dpi_y ),  /* Vista uses a more precise method */
            "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
    }
    expect_world_trasform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, MulDiv(1000 / 10, res_x, size_cx), -MulDiv(1000 / 10, res_y, size_cy));

    SetLastError(0xdeadbeef);
    ret = SetMapMode(hdc, MM_TEXT);
    ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, 1000, 1000);

    ret = SetGraphicsMode(hdc, GM_ADVANCED);
    if (!ret)
    {
        DeleteDC(hdc);
        skip("GM_ADVANCED is not supported on this platform\n");
        return;
    }

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, 1000, 1000);

    /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
    xform.eM11 = 1.0f;
    xform.eM12 = 2.0f;
    xform.eM21 = 1.0f;
    xform.eM22 = 2.0f;
    xform.eDx = 0.0f;
    xform.eDy = 0.0f;
    ret = SetWorldTransform(hdc, &xform);
    ok(!ret ||
       broken(ret), /* NT4 */
       "SetWorldTransform should fail with an invalid xform\n");

    xform.eM11 = 20.0f;
    xform.eM12 = 0.0f;
    xform.eM21 = 0.0f;
    xform.eM22 = 20.0f;
    xform.eDx = 0.0f;
    xform.eDy = 0.0f;
    SetLastError(0xdeadbeef);
    ret = SetWorldTransform(hdc, &xform);
    ok(ret, "SetWorldTransform error %u\n", GetLastError());

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 20.0, 20.0);
    expect_LPtoDP(hdc, 20000, 20000);

    SetLastError(0xdeadbeef);
    ret = SetMapMode(hdc, MM_LOMETRIC);
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);

    expect_viewport_ext(hdc, res_x, -res_y);
    ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
    ok( size.cx == size_cx * 10 ||
        size.cx == MulDiv( res_x, 254, dpi_x ),  /* Vista uses a more precise method */
        "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
    ok( size.cy == size_cy * 10 ||
        size.cy == MulDiv( res_y, 254, dpi_y ),  /* Vista uses a more precise method */
        "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
    expect_world_trasform(hdc, 20.0, 20.0);
    expect_LPtoDP(hdc, MulDiv(20000, res_x, size.cx), -MulDiv(20000, res_y, size.cy));

    SetLastError(0xdeadbeef);
    ret = SetMapMode(hdc, MM_TEXT);
    ok(ret == MM_LOMETRIC, "expected MM_LOMETRIC, got %d\n", ret);

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 20.0, 20.0);
    expect_LPtoDP(hdc, 20000, 20000);

    ret = SetGraphicsMode(hdc, GM_COMPATIBLE);
    ok(ret, "SetGraphicsMode(GM_COMPATIBLE) should not fail if DC has't an identity transform\n");
    ret = GetGraphicsMode(hdc);
    ok(ret == GM_COMPATIBLE, "expected GM_COMPATIBLE, got %d\n", ret);

    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_trasform(hdc, 20.0, 20.0);
    expect_LPtoDP(hdc, 20000, 20000);

    DeleteDC(hdc);
}
Example #23
0
static void test_gettransform(void)
{
    HDC hdc = CreateICA("DISPLAY", NULL, NULL, NULL);
    BOOL (WINAPI *pGetTransform)(HDC, DWORD, XFORM *);
    XFORM xform, expect;
    BOOL r;
    SIZE lometric_vp, lometric_wnd;

    pGetTransform = (void *)GetProcAddress(GetModuleHandleA("gdi32.dll"), "GetTransform");

    if(!pGetTransform)
    {
        win_skip("Don't have GetTransform\n");
        return;
    }

    r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
    ok(r == TRUE, "got %d\n", r);
    expect_identity(__LINE__, &xform);
    r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
    ok(r == TRUE, "got %d\n", r);
    expect_identity(__LINE__, &xform);
    r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
    ok(r == TRUE, "got %d\n", r);
    expect_identity(__LINE__, &xform);
    r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
    ok(r == TRUE, "got %d\n", r);
    expect_identity(__LINE__, &xform);

    SetMapMode(hdc, MM_LOMETRIC);
    GetViewportExtEx(hdc, &lometric_vp);
    GetWindowExtEx(hdc, &lometric_wnd);

    r = pGetTransform(hdc, 0x203, &xform); /* World -> Page */
    ok(r == TRUE, "got %d\n", r);
    expect_identity(__LINE__, &xform);

    r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
    ok(r == TRUE, "got %d\n", r);
    expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
    expect.eM12 = expect.eM21 = 0.0;
    expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
    expect.eDx = expect.eDy = 0.0;
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x204, &xform);  /* World -> Device */
    ok(r == TRUE, "got %d\n", r);
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
    ok(r == TRUE, "got %d\n", r);
    expect.eM11 = (FLOAT) lometric_wnd.cx / lometric_vp.cx;
    expect.eM22 = (FLOAT) lometric_wnd.cy / lometric_vp.cy;
    xform_near_match(__LINE__, &xform, &expect);


    SetGraphicsMode(hdc, GM_ADVANCED);

    expect.eM11 = 10.0;
    expect.eM22 = 20.0;
    SetWorldTransform(hdc, &expect);
    r = pGetTransform(hdc, 0x203, &xform);  /* World -> Page */
    ok(r == TRUE, "got %d\n", r);
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x304, &xform); /* Page -> Device */
    ok(r == TRUE, "got %d\n", r);
    expect.eM11 = (FLOAT) lometric_vp.cx / lometric_wnd.cx;
    expect.eM22 = (FLOAT) lometric_vp.cy / lometric_wnd.cy;
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x204, &xform); /* World -> Device */
    ok(r == TRUE, "got %d\n", r);
    expect.eM11 *= 10.0;
    expect.eM22 *= 20.0;
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x402, &xform); /* Device -> World */
    ok(r == TRUE, "got %d\n", r);
    expect.eM11 = 1 / expect.eM11;
    expect.eM22 = 1 / expect.eM22;
    xform_near_match(__LINE__, &xform, &expect);

    r = pGetTransform(hdc, 0x102, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x103, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x104, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x202, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x302, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x303, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x403, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0x404, &xform);
    ok(r == FALSE, "got %d\n", r);
    r = pGetTransform(hdc, 0xffff, &xform);
    ok(r == FALSE, "got %d\n", r);
}
Example #24
0
void Player::draw(){									

	//±×¸®´Â ºÎºÐ

	HBITMAP hBitmap;									//À̹ÌÁö¸¦ °¡Á®¿À±â À§ÇÑ hBitmap;							//Ãß°¡µÈ º¯¼ö
	BITMAP bmp;											//À̹ÌÁöÀÇ Å©±â¸¦ ¾Ë±â À§ÇÑ bmp;							//Ãß°¡µÈ º¯¼ö
	int mWidth, mHeight;								//À̹ÌÁöÀÇ Å©±â¸¦ ÀúÀåÇϱâ À§ÇÑ  mWidth, mHeight;;		//Ãß°¡µÈ º¯¼ö
	HDC memdc;											//À̹ÌÁö¸¦ ÀÓ½ÃÀúÀåÇϱâ À§ÇÑ memdc;						//Ãß°¡µÈ º¯¼ö
	HBITMAP hRotationBitmap;							//ȸÀüÀ» À§ÇÑ hRotationBitmap							//Ãß°¡µÈ º¯¼ö
	HDC rotationdc;										//ȸÀüÀ» À§ÇÑ rotationdc;								//Ãß°¡µÈ º¯¼ö
	hBitmap = (HBITMAP)LoadBitmap(hInst, MAKEINTRESOURCE(IDB_CHARACTER));		//À̹ÌÁö ¼³Á¤
	static int drawCnt;									//¸î¹ø ºÒ·¯Áø Áö¸¦ üũÇϱâ À§ÇÑ Cnt;
	

	

	memdc=CreateCompatibleDC (bufferdc);
	SelectObject (memdc, hBitmap);												//À̹ÌÁö ·Îµå	

	GetObject(hBitmap, sizeof(BITMAP), &bmp);									//À̹ÌÁö Å©±â °¡Á®¿À±â
	mWidth = bmp.bmWidth;
	mHeight = bmp.bmHeight;


	rotationdc = CreateCompatibleDC(bufferdc);
	hRotationBitmap = CreateCompatibleBitmap(bufferdc, rectView.right, rectView.bottom);
	SelectObject(rotationdc, hRotationBitmap);		//À̹ÌÁö ·Îµå	

	float degree = 0;										//°¢µµ
	XFORM xFormRotate;
	SetGraphicsMode(rotationdc, GM_ADVANCED);					 // ¸ðµå¸¦ ¼³Á¤À™´Ù.
	xFormRotate.eM11 = (float)cos(degree*3.14 / 180);		// Àû¿ëÀš º¯ÃQ °ªÀ» ¼³Á¤À™´Ù.
	xFormRotate.eM12 = (float)sin(degree*3.14 / 180);
	xFormRotate.eM21 = (float)-sin(degree*3.14 / 180);
	xFormRotate.eM22 = (float)cos(degree*3.14 / 180);
	xFormRotate.eDx = 00;
	xFormRotate.eDy = 00;
	SetWorldTransform(rotationdc, &xFormRotate);					// ±×¸± DC¿¡ º¯ÃQÀ» Àû¿ëÀ™´Ù

	if (SpeedXpos >= 0)
		StretchBlt(rotationdc, 0, 0, rectView.right, rectView.bottom, memdc, mWidth / 4 * drawCnt, mHeight / 2, mWidth / 4, mHeight / 2, SRCCOPY);
	else if (SpeedXpos < 0)
		StretchBlt(rotationdc, 0, 0, rectView.right, rectView.bottom, memdc, mWidth / 4 * drawCnt, 0, mWidth / 4, mHeight / 2, SRCCOPY);

	
	TransparentBlt(bufferdc, ObjectRect.left, ObjectRect.top, ObjectSize.cx, ObjectSize.cy, rotationdc, 0, 0, rectView.right, rectView.bottom, RGB(0, 255, 255));
	

	drawCnt++;

	if (drawCnt > 3)
		drawCnt = 0;

	hBitmap = (HBITMAP)LoadBitmap(hInst, MAKEINTRESOURCE(IDB_HPGAGE));      //À̹ÌÁö ¼³Á¤
	memdc = CreateCompatibleDC(bufferdc);
	SelectObject(memdc, hBitmap);

	GetObject(hBitmap, sizeof(BITMAP), &bmp);                           //À̹ÌÁö Å©±â °¡Á®¿À±â
	mWidth = bmp.bmWidth;
	mHeight = bmp.bmHeight;

	TransparentBlt(bufferdc, rectView.right - 140 + cameraView.left, rectView.bottom - 1000 / 4, 40, 1000 / 4, memdc, 0, 0, mWidth / 2, mHeight, RGB(0, 255, 255));
	TransparentBlt(bufferdc, rectView.right - 140 + cameraView.left, rectView.bottom - Hp / 4, 40, Hp / 4, memdc, mWidth / 2, 0, mWidth / 2, mHeight, RGB(0, 255, 255));


	DeleteObject(hBitmap);
	DeleteDC(memdc);

	DeleteObject(hRotationBitmap);
	DeleteDC(rotationdc);
	DeleteObject(hBitmap);
	DeleteDC(memdc);
};
static void
create_printer_dc (win32_target_closure_t *ptc)
{
    char *printer_name;
    DWORD size;
    int x_dpi, y_dpi, left_margin, top_margin, page_height, printable_height;
    XFORM xform;

    ptc->dc = NULL;
    GetDefaultPrinter (NULL, &size);
    printer_name = malloc (size);

    if (printer_name == NULL)
	return;

    if (GetDefaultPrinter (printer_name, &size) == 0) {
	free (printer_name);
	return;
    }

    /* printf("\nPrinting to : %s\n", printer_name); */
    ptc->dc = CreateDC (NULL, printer_name, NULL, NULL);
    free (printer_name);

    if (!printer_is_postscript_level_3 (ptc->dc)) {
	printf("The default printer driver must be a color PostScript level 3 printer\n");
	ptc->dc = NULL;
	return;
    }

    /* The printer device units on win32 are 1 unit == 1 dot and the
     * origin is the start of the printable area. We transform the
     * cordinate space to 1 unit is 1 point as expected by the
     * tests. As the page size is larger than the test surface, the
     * origin is translated down so that the each test is drawn at the
     * bottom left corner of the page. This is because the bottom left
     * corner of the PNG image that ghostscript creates is positioned
     * at origin of the PS coordinates (ie the bottom left of the
     * page).  The left and bottom margins are stored in
     * win32_target_closure as size of the PNG image needs to be
     * increased because the test output is offset from the bottom
     * left by the non printable margins. After the PNG is created the
     * margins will be chopped off so the image matches the reference
     * image.
     */
    printable_height = GetDeviceCaps (ptc->dc, VERTRES);
    x_dpi = GetDeviceCaps (ptc->dc, LOGPIXELSX);
    y_dpi = GetDeviceCaps (ptc->dc, LOGPIXELSY);
    left_margin = GetDeviceCaps (ptc->dc, PHYSICALOFFSETX);
    top_margin = GetDeviceCaps (ptc->dc, PHYSICALOFFSETY);
    page_height = GetDeviceCaps (ptc->dc, PHYSICALHEIGHT);

    SetGraphicsMode (ptc->dc, GM_ADVANCED);
    xform.eM11 = x_dpi/72.0;
    xform.eM12 = 0;
    xform.eM21 = 0;
    xform.eM22 = y_dpi/72.0;
    xform.eDx = 0;
    xform.eDy = printable_height - ptc->height*y_dpi/72.0;
    if (!SetWorldTransform (ptc->dc, &xform)) {
	_cairo_win32_print_gdi_error ("cairo-boilerplate-win32-printing:SetWorldTransform");
	return;
    }

    ptc->left_margin = 72.0*left_margin/x_dpi;
    ptc->bottom_margin = 72.0*(page_height - printable_height - top_margin)/y_dpi;
}
JNIEXPORT void JNICALL Java_org_apache_harmony_awt_gl_windows_GDIBlitter_bltBitmap
  (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, 
  jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, 
  jint compType, jfloat alpha, jdoubleArray matrix, jintArray clip, 
  jint numVertex){

      SURFACE_STRUCTURE *srcSurf = (SURFACE_STRUCTURE *)srcSurfStruct;
      SURFACE_STRUCTURE *dstSurf = (SURFACE_STRUCTURE *)dstSurfStruct;

      UCHAR srca = (UCHAR)(alpha * 255 + 0.5);

      XFORM currentTransform, transform;
      if(matrix != NULL){

          jdouble * mtrx = (jdouble *)env->GetPrimitiveArrayCritical(matrix, 0);
          jdouble * old_mtrx = mtrx;

          transform.eM11 = (FLOAT)(*mtrx++);
          transform.eM12 = (FLOAT)(*mtrx++);
          transform.eM21 = (FLOAT)(*mtrx++);
          transform.eM22 = (FLOAT)(*mtrx++);
          transform.eDx = (FLOAT)(*mtrx++);
          transform.eDy = (FLOAT)(*mtrx);

          env->ReleasePrimitiveArrayCritical(matrix, old_mtrx, 0);

          SetGraphicsMode(dstSurf->gi->hdc, GM_ADVANCED);
          GetWorldTransform(dstSurf->gi->hdc, &currentTransform);
          SetWorldTransform(dstSurf->gi->hdc, &transform);
      }

      HRGN oldClip = setGdiClip(env, dstSurf->gi->hdc, clip, numVertex);

      BLITSTRUCT blitStruct;
      memset(&blitStruct, 0, sizeof(BLITSTRUCT));

      switch(compType){
          case COMPOSITE_CLEAR:
          case COMPOSITE_SRC_OUT:
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;

          case COMPOSITE_SRC:
          case COMPOSITE_SRC_IN:
              blitStruct.blitFunctintType = BIT_BLT;
              if(srca == 0) blitStruct.rastOp = BLACKNESS;
              else blitStruct.rastOp = SRCCOPY;
              break;

          case COMPOSITE_DST:
          case COMPOSITE_DST_OVER:
              return;

          case COMPOSITE_SRC_ATOP:
          case COMPOSITE_SRC_OVER:
              if(srca == 255){
                  blitStruct.blitFunctintType = BIT_BLT;
                  blitStruct.rastOp = SRCCOPY;
              }else{

                  blitStruct.blitFunctintType = ALPHA_BLEND;
                  blitStruct.blendFunc.AlphaFormat = 0;
                  blitStruct.blendFunc.BlendOp = AC_SRC_OVER;
                  blitStruct.blendFunc.BlendFlags = 0;
                  blitStruct.blendFunc.SourceConstantAlpha = srca;
              }
              break;

          case COMPOSITE_DST_IN:
          case COMPOSITE_DST_ATOP:
              if(srca != 0) return;
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;

          case COMPOSITE_DST_OUT:
          case COMPOSITE_XOR:
              if(srca != 255) return;
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;
      }

      switch(blitStruct.blitFunctintType){
          case ALPHA_BLEND:
              AlphaBlend(dstSurf->gi->hdc, dstX, dstY, width, height, srcSurf->gi->hdc,
                      srcX, srcY, width, height, blitStruct.blendFunc);
              break;

          case TRANSPARENT_BLT:
              TransparentBlt(dstSurf->gi->hdc, dstX, dstY, width, height, srcSurf->gi->hdc,
                  srcX, srcY, width, height, srcSurf->rtc);
              break;

          default:
              BitBlt(dstSurf->gi->hdc, dstX, dstY, width, height, srcSurf->gi->hdc,
                  srcX, srcY, blitStruct.rastOp);
              break;
      }
      if(matrix){
          SetWorldTransform(dstSurf->gi->hdc, &currentTransform);
          SetGraphicsMode(dstSurf->gi->hdc, GM_COMPATIBLE);
      }
      restoreGdiClip(dstSurf->gi->hdc, oldClip);
  }
HDC
gfxWindowsNativeDrawing::BeginNativeDrawing()
{
    if (mRenderState == RENDER_STATE_INIT) {
        nsRefPtr<gfxASurface> surf;
        
        if (mContext->GetCairo()) {
          surf = mContext->CurrentSurface(&mDeviceOffset.x, &mDeviceOffset.y);
        }

        if (surf && surf->CairoStatus())
            return nsnull;

        gfxMatrix m = mContext->CurrentMatrix();
        if (!m.HasNonTranslation())
            mTransformType = TRANSLATION_ONLY;
        else if (m.HasNonAxisAlignedTransform())
            mTransformType = COMPLEX;
        else
            mTransformType = AXIS_ALIGNED_SCALE;

        // if this is a native win32 surface, we don't have to
        // redirect rendering to our own HDC; in some cases,
        // we may be able to use the HDC from the surface directly.
        if (surf &&
            ((surf->GetType() == gfxASurface::SurfaceTypeWin32 ||
              surf->GetType() == gfxASurface::SurfaceTypeWin32Printing) &&
              (surf->GetContentType() == gfxASurface::CONTENT_COLOR ||
               (surf->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA &&
               (mNativeDrawFlags & CAN_DRAW_TO_COLOR_ALPHA)))))
        {
            // grab the DC. This can fail if there is a complex clipping path,
            // in which case we'll have to fall back.
            mWinSurface = static_cast<gfxWindowsSurface*>(static_cast<gfxASurface*>(surf.get()));
            mDC = mWinSurface->GetDCWithClip(mContext);

            if (mDC) {
                if (mTransformType == TRANSLATION_ONLY) {
                    mRenderState = RENDER_STATE_NATIVE_DRAWING;

                    mTranslation = m.GetTranslation();
                } else if (((mTransformType == AXIS_ALIGNED_SCALE)
                            && (mNativeDrawFlags & CAN_AXIS_ALIGNED_SCALE)) ||
                           (mNativeDrawFlags & CAN_COMPLEX_TRANSFORM))
                {
                    mWorldTransform.eM11 = (FLOAT) m.xx;
                    mWorldTransform.eM12 = (FLOAT) m.yx;
                    mWorldTransform.eM21 = (FLOAT) m.xy;
                    mWorldTransform.eM22 = (FLOAT) m.yy;
                    mWorldTransform.eDx  = (FLOAT) m.x0;
                    mWorldTransform.eDy  = (FLOAT) m.y0;

                    mRenderState = RENDER_STATE_NATIVE_DRAWING;
                }
            }
        }

        // If we couldn't do native drawing, then we have to do two-buffer drawing
        // and do alpha recovery
        if (mRenderState == RENDER_STATE_INIT) {
            mRenderState = RENDER_STATE_ALPHA_RECOVERY_BLACK;

            // We round out our native rect here, that way the snapping will
            // happen correctly.
            mNativeRect.RoundOut();

            // we only do the scale bit if we can do an axis aligned
            // scale; otherwise we scale (if necessary) after
            // rendering with cairo.  Note that if we're doing alpha recovery,
            // we cannot do a full complex transform with win32 (I mean, we could, but
            // it would require more code that's not here.)
            if (mTransformType == TRANSLATION_ONLY || !(mNativeDrawFlags & CAN_AXIS_ALIGNED_SCALE)) {
                mScale = gfxSize(1.0, 1.0);

                // Add 1 to the surface size; it's guaranteed to not be incorrect,
                // and it fixes bug 382458
                // There's probably a better fix, but I haven't figured out
                // the root cause of the problem.
                mTempSurfaceSize =
                    gfxIntSize((PRInt32) ceil(mNativeRect.Width() + 1),
                               (PRInt32) ceil(mNativeRect.Height() + 1));
            } else {
                // figure out the scale factors
                mScale = m.ScaleFactors(true);

                mWorldTransform.eM11 = (FLOAT) mScale.width;
                mWorldTransform.eM12 = 0.0f;
                mWorldTransform.eM21 = 0.0f;
                mWorldTransform.eM22 = (FLOAT) mScale.height;
                mWorldTransform.eDx  = 0.0f;
                mWorldTransform.eDy  = 0.0f;

                // See comment above about "+1"
                mTempSurfaceSize =
                    gfxIntSize((PRInt32) ceil(mNativeRect.Width() * mScale.width + 1),
                               (PRInt32) ceil(mNativeRect.Height() * mScale.height + 1));
            }
        }
    }

    if (mRenderState == RENDER_STATE_NATIVE_DRAWING) {
        // we can just do native drawing directly to the context's surface

        // do we need to use SetWorldTransform?
        if (mTransformType != TRANSLATION_ONLY) {
            SetGraphicsMode(mDC, GM_ADVANCED);
            GetWorldTransform(mDC, &mOldWorldTransform);
            SetWorldTransform(mDC, &mWorldTransform);
        }
        GetViewportOrgEx(mDC, &mOrigViewportOrigin);
        SetViewportOrgEx(mDC,
                         mOrigViewportOrigin.x + (int)mDeviceOffset.x,
                         mOrigViewportOrigin.y + (int)mDeviceOffset.y,
                         NULL);

        return mDC;
    } else if (mRenderState == RENDER_STATE_ALPHA_RECOVERY_BLACK ||
               mRenderState == RENDER_STATE_ALPHA_RECOVERY_WHITE)
    {
        // we're going to use mWinSurface to create our temporary surface here

        // get us a RGB24 DIB; DIB is important, because
        // we can later call GetImageSurface on it.
        mWinSurface = new gfxWindowsSurface(mTempSurfaceSize);
        mDC = mWinSurface->GetDC();

        RECT r = { 0, 0, mTempSurfaceSize.width, mTempSurfaceSize.height };
        if (mRenderState == RENDER_STATE_ALPHA_RECOVERY_BLACK)
            FillRect(mDC, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
        else
            FillRect(mDC, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));

        if ((mTransformType != TRANSLATION_ONLY) &&
            (mNativeDrawFlags & CAN_AXIS_ALIGNED_SCALE))
        {
            SetGraphicsMode(mDC, GM_ADVANCED);
            SetWorldTransform(mDC, &mWorldTransform);
        }

        return mDC;
    } else {
        NS_ERROR("Bogus render state!");
        return nsnull;
    }
}
JNIEXPORT void JNICALL Java_org_apache_harmony_awt_gl_windows_GDIBlitter_xorImage
  (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, jobject srcData, 
  jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, jint xorcolor, 
  jdoubleArray matrix, jintArray clip, jint numVertex, jboolean invalidated, 
  jintArray dirtyRegions, jint regCount){

      SURFACE_STRUCTURE *srcSurf = (SURFACE_STRUCTURE *)srcSurfStruct;
      SURFACE_STRUCTURE *dstSurf = (SURFACE_STRUCTURE *)dstSurfStruct;

      srcSurf->invalidated = invalidated != 0;

      int *regions;
      if(dirtyRegions == 0){
          regCount = 4;
          regions = (int *)malloc(4 * sizeof(int));
          regions[0] = 0;
          regions[1] = 0;
          regions[2] = srcSurf->width - 1;
          regions[3] = srcSurf->height - 1;
      } else {
          regions = (int *)malloc(regCount * sizeof(int));
          env->GetIntArrayRegion(dirtyRegions, 1, regCount, regions);
      }
      if(!initBitmap(srcSurf, env, srcData, false, regions, regCount)) return;

      BYTE r = (BYTE)((xorcolor >> 16) & 0xff);
      BYTE g = (BYTE)((xorcolor >> 8) & 0xff);
      BYTE b = (BYTE)(xorcolor & 0xff);

      HBRUSH brush = CreateSolidBrush(RGB(r, g, b));


      XFORM currentTransform, transform;
      if(matrix != NULL){

          jdouble * mtrx = (jdouble *)env->GetPrimitiveArrayCritical(matrix, 0);
          jdouble * old_mtrx = mtrx;

          transform.eM11 = (FLOAT)(*mtrx++);
          transform.eM12 = (FLOAT)(*mtrx++);
          transform.eM21 = (FLOAT)(*mtrx++);
          transform.eM22 = (FLOAT)(*mtrx++);
          transform.eDx = (FLOAT)(*mtrx++);
          transform.eDy = (FLOAT)(*mtrx);

          env->ReleasePrimitiveArrayCritical(matrix, old_mtrx, 0);

          SetGraphicsMode(dstSurf->gi->hdc, GM_ADVANCED);
          GetWorldTransform(dstSurf->gi->hdc, &currentTransform);
          SetWorldTransform(dstSurf->gi->hdc, &transform);
      }

      HRGN oldClip = setGdiClip(env, dstSurf->gi->hdc, clip, numVertex);

      HGDIOBJ oldBrush = SelectObject(dstSurf->gi->hdc, brush);

      if(srcSurf->has_alpha){

          int scanline_word = srcSurf->width / 16;
          if(srcSurf->width % 16 != 0) scanline_word++;

          BYTE *pm = (BYTE *)calloc(scanline_word * srcSurf->height * 2, 1);

          int byteIdx = 0;
          unsigned int *p = (unsigned int *)srcSurf->bmpData;
          for(int y = 0; y < srcSurf->height; y++){
              for(int x = 0, shift = 7; x < srcSurf->width; x++, shift--, p++){
                  if(shift < 0 ){
                      shift = 7;
                      byteIdx++;
                  } 
                  unsigned int pixel = (*p >> 24) & 0xff;
                  if(pixel > 127) pm[byteIdx] |= 1 << shift;
              }
              if(byteIdx % 2 != 0) byteIdx++;
              else byteIdx += 2;
          }      

          HBITMAP mask = CreateBitmap(srcSurf->width, srcSurf->height, 1, 1, pm);
          free(pm);
          MaskBlt(dstSurf->gi->hdc, dstX, dstY, width, height, srcSurf->srcDC,
                  srcX, srcY, mask, srcX, srcY, MAKEROP4(0x960169, 0xAA0029));
          DeleteObject(mask);
      }else{
Example #29
0
void SpatialNode::SetWorldTransform(const Vector3& newPosition, const Quaternion& newRotation, float newScale)
{
    SetWorldTransform(newPosition, newRotation, Vector3(newScale, newScale, newScale));
}
JNIEXPORT void JNICALL Java_org_apache_harmony_awt_gl_windows_GDIBlitter_bltBGImage
  (JNIEnv *env, jobject obj, jint srcX, jint srcY, jlong srcSurfStruct, jobject srcData, 
  jint dstX, jint dstY, jlong dstSurfStruct, jint width, jint height, 
  jint bgcolor, jint compType, jfloat alpha, jdoubleArray matrix, jintArray clip, 
  jint numVertex, jboolean invalidated, jintArray dirtyRegions, jint regCount){

      SURFACE_STRUCTURE *srcSurf = (SURFACE_STRUCTURE *)srcSurfStruct;
      SURFACE_STRUCTURE *dstSurf = (SURFACE_STRUCTURE *)dstSurfStruct;

      srcSurf->invalidated = invalidated != 0;
      HDC tmpDC = CreateCompatibleDC(dstSurf->gi->hdc);
      int w = srcSurf->width;
      int h = srcSurf->height;
      HBITMAP tmpBmp = CreateCompatibleBitmap(dstSurf->gi->hdc, w, h);
      SelectObject(tmpDC, tmpBmp);

      BYTE a = (BYTE)((bgcolor >> 24) & 0xff);
      BYTE r = (BYTE)((bgcolor >> 16) & 0xff);
      BYTE g = (BYTE)((bgcolor >> 8) & 0xff);
      BYTE b = (BYTE)(bgcolor & 0xff);
      r = MUL(a, r);
      g = MUL(a, g);
      b = MUL(a, b);

      HBRUSH brush = CreateSolidBrush(RGB(r, g, b));
      SelectObject(tmpDC, brush);
      PatBlt(tmpDC, 0, 0, w, h, PATCOPY);
      
      int *regions;
      if(dirtyRegions == 0){
          regCount = 4;
          regions = (int *)malloc(4 * sizeof(int));
          regions[0] = 0;
          regions[1] = 0;
          regions[2] = srcSurf->width - 1;
          regions[3] = srcSurf->height - 1;
      } else {
          regions = (int *)malloc(regCount * sizeof(int));
          env->GetIntArrayRegion(dirtyRegions, 1, regCount, regions);
      }

      if(initBitmap(srcSurf, env, srcData, true, regions, regCount)){
          BLENDFUNCTION bf;
          bf.AlphaFormat = AC_SRC_ALPHA;
          bf.BlendOp = AC_SRC_OVER;
          bf.BlendFlags = 0;
          bf.SourceConstantAlpha = 255;
          AlphaBlend(tmpDC, 0, 0, w, h, srcSurf->srcDC, 0, 0, w, h, bf);
      }

      UCHAR srca = (UCHAR)(alpha * 255 + 0.5);

      XFORM currentTransform, transform;
      if(matrix != NULL){

          jdouble * mtrx = (jdouble *)env->GetPrimitiveArrayCritical(matrix, 0);
          jdouble * old_mtrx = mtrx;

          transform.eM11 = (FLOAT)(*mtrx++);
          transform.eM12 = (FLOAT)(*mtrx++);
          transform.eM21 = (FLOAT)(*mtrx++);
          transform.eM22 = (FLOAT)(*mtrx++);
          transform.eDx = (FLOAT)(*mtrx++);
          transform.eDy = (FLOAT)(*mtrx);

          env->ReleasePrimitiveArrayCritical(matrix, old_mtrx, 0);

          SetGraphicsMode(dstSurf->gi->hdc, GM_ADVANCED);
          GetWorldTransform(dstSurf->gi->hdc, &currentTransform);
          SetWorldTransform(dstSurf->gi->hdc, &transform);
      }

      HRGN oldClip = setGdiClip(env, dstSurf->gi->hdc, clip, numVertex);

      BLITSTRUCT blitStruct;
      memset(&blitStruct, 0, sizeof(BLITSTRUCT));

      switch(compType){
          case COMPOSITE_CLEAR:
          case COMPOSITE_SRC_OUT:
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;

          case COMPOSITE_SRC:
          case COMPOSITE_SRC_IN:
              blitStruct.blitFunctintType = BIT_BLT;
              if(srca == 0) blitStruct.rastOp = BLACKNESS;
              else blitStruct.rastOp = SRCCOPY;
              break;

          case COMPOSITE_DST:
          case COMPOSITE_DST_OVER:
              return;

          case COMPOSITE_SRC_ATOP:
          case COMPOSITE_SRC_OVER:
              if(srca == 255){
                  blitStruct.blitFunctintType = BIT_BLT;
                  blitStruct.rastOp = SRCCOPY;
              }else{

                  blitStruct.blitFunctintType = ALPHA_BLEND;
                  blitStruct.blendFunc.AlphaFormat = 0;
                  blitStruct.blendFunc.BlendOp = AC_SRC_OVER;
                  blitStruct.blendFunc.BlendFlags = 0;
                  blitStruct.blendFunc.SourceConstantAlpha = srca;
              }
              break;

          case COMPOSITE_DST_IN:
          case COMPOSITE_DST_ATOP:
              if(srca != 0) return;
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;

          case COMPOSITE_DST_OUT:
          case COMPOSITE_XOR:
              if(srca != 255) return;
              blitStruct.blitFunctintType = BIT_BLT;
              blitStruct.rastOp = BLACKNESS;
              break;
      }

      switch(blitStruct.blitFunctintType){
          case ALPHA_BLEND:
              AlphaBlend(dstSurf->gi->hdc, dstX, dstY, width, height, tmpDC,
                      srcX, srcY, width, height, blitStruct.blendFunc);
              break;

          case TRANSPARENT_BLT:
              TransparentBlt(dstSurf->gi->hdc, dstX, dstY, width, height, tmpDC,
                  srcX, srcY, width, height, srcSurf->rtc);
              break;

          default:
              BitBlt(dstSurf->gi->hdc, dstX, dstY, width, height, tmpDC,
                  srcX, srcY, blitStruct.rastOp);
              break;
      }
      if(matrix){
          SetWorldTransform(dstSurf->gi->hdc, &currentTransform);
          SetGraphicsMode(dstSurf->gi->hdc, GM_COMPATIBLE);
      }
      restoreGdiClip(dstSurf->gi->hdc, oldClip);

      DeleteObject(brush);
      DeleteObject(tmpBmp);
      DeleteDC(tmpDC);

  }