/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CImage::RenderScene() { //Clear the screen with the current clear colour. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); //Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //Set the current matrix to the identity vgLoadIdentity(); //Translate the image to the desired position vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5); //Draw the first image vgDrawImage(m_avgImage[0]); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the second image... vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f - IMG_SIZE - 5); //...and draw vgDrawImage(m_avgImage[1]); m_PrintVG.DisplayDefaultTitle("Image", "", ePVRTPrint3DLogoIMG); return true; }
void display(float interval) { VGfloat cc[] = {0,0,0,1}; vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); vgLoadIdentity(); vgTranslate(tx, ty); vgScale(sx, sy); vgRotate(a); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY); vgLoadIdentity(); vgSetPaint(patternFill, VG_FILL_PATH); /*vgDrawPath(p, VG_FILL_PATH);*/ vgDrawImage(backImage); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(tx, ty); vgScale(sx, sy); vgRotate(a); vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH); vgDrawPath(org, VG_FILL_PATH); }
void render(int w, int h) { { float clearColor[4] = {1,1,1,1}; float scale = w / (tigerMaxX - tigerMinX); eglSwapBuffers(egldisplay, eglsurface); //force EGL to recognize resize vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0, 0, w, h); vgLoadIdentity(); vgTranslate(w * 0.5f, h * 0.5f); vgRotate(rotateN); vgTranslate(-w * 0.5f, -h * 0.5f); vgScale(scale, scale); vgTranslate(-tigerMinX, -tigerMinY + 0.5f * (h / scale - (tigerMaxY - tigerMinY))); PS_render(tiger); assert(vgGetError() == VG_NO_ERROR); renderWidth = w; renderHeight = h; } }
void display(float interval) { VGfloat cc[] = {0,0,0,1}; vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); vgLoadIdentity(); vgTranslate(tx, ty); vgRotate(ang); vgScale(sx, sy); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSetPaint(radialFill, VG_FILL_PATH); vgDrawPath(p, VG_FILL_PATH); vgTranslate(tx, ty); vgRotate(ang); vgScale(sx, sy); vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH); vgDrawPath(radius, VG_STROKE_PATH); vgDrawPath(center, VG_STROKE_PATH); vgDrawPath(focus, VG_FILL_PATH); }
/******************************************************************************* * Function Name : DoShearCentered * Description : Demonstrate the effect of shearing centred on a * shape. Each path is transformed separately. *******************************************************************************/ void CTransforms::DoShearCentered() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3 * 3]; vgGetMatrix(afUnitMatrix); // turn time(ms) into a clipped periodic triangle function int i32Zigzag1 = m_ui32AbsTime % 2000; if(i32Zigzag1 > 1000) i32Zigzag1 = 2000 - i32Zigzag1; i32Zigzag1 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag1)) - 500; // and again, now with shifted phase int i32Zigzag2 = (m_ui32AbsTime + 500) % 2000; if(i32Zigzag2 > 1000) i32Zigzag2 = 2000 - i32Zigzag2; i32Zigzag2 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag2)) - 500; // Scaling a shape from its center is identical to moving it to the // origin, scaling it there, and moving it back where it was. // // IMPORTANT: // Since OpenVG right-multiplies matrices, you conceptually need to // call the transformation functions in backwards order. vgTranslate(0.5f, 0.75f); vgShear(0.001f * i32Zigzag1, 0); vgTranslate(-0.5f, -0.75f); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // transformation for second path vgTranslate(0.5f, 0.25f); vgShear(0.001f * i32Zigzag2, 0); vgTranslate(-0.5f, -0.25f); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
void CNVGCSIcon::SetRotation() { if (iRotationAngle) { vgTranslate(iRotationX, iRotationY); vgRotate(iRotationAngle); vgTranslate(-iRotationX, -iRotationY); } }
/******************************************************************************* * Function Name : DoTranslate * Description : Demonstrate the effect of translations. Each path is * translated separately *******************************************************************************/ void CTransforms::DoTranslate() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3 * 3]; vgGetMatrix(afUnitMatrix); // turn time(ms) into a clipped periodic triangle function int i32Zigzag1 = m_ui32AbsTime % 2000; if(i32Zigzag1 > 1000) i32Zigzag1 = 2000 - i32Zigzag1; i32Zigzag1 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag1)) - 500; // and again, now with shifted phase int i32Zigzag2 = (m_ui32AbsTime + 500) % 2000; if(i32Zigzag2 > 1000) i32Zigzag2 = 2000 - i32Zigzag2; i32Zigzag2 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag2)) - 250; // translation for first path vgTranslate(-0.001f * i32Zigzag1, -0.001f * i32Zigzag2); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // translation for second path vgTranslate(0.001f * i32Zigzag1, 0.001f * i32Zigzag2); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
void loadTiger() { int i; VGPath temp; temp = testCreatePath(); tigerPaths = (VGPath*)malloc(pathCount * sizeof(VGPath)); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgTranslate(-100,100); vgScale(1,-1); for (i=0; i<pathCount; ++i) { vgClearPath(temp, VG_PATH_CAPABILITY_ALL); vgAppendPathData(temp, commandCounts[i], commandArrays[i], dataArrays[i]); tigerPaths[i] = testCreatePath(); vgTransformPath(tigerPaths[i], temp); } tigerStroke = vgCreatePaint(); tigerFill = vgCreatePaint(); vgSetPaint(tigerStroke, VG_STROKE_PATH); vgSetPaint(tigerFill, VG_FILL_PATH); vgLoadIdentity(); vgDestroyPath(temp); }
//Display functions void display(float interval) { int i; const VGfloat *style; VGfloat clearColor[] = {1,1,1,1}; if (animate) { ang += interval * 360 * 0.1f; if (ang > 360) ang -= 360; } vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(testWidth()/2 + tx,testHeight()/2 + ty); vgScale(sx, sy); vgRotate(ang); for (i=0; i<pathCount; ++i) { style = styleArrays[i]; vgSetParameterfv(tigerStroke, VG_PAINT_COLOR, 4, &style[0]); vgSetParameterfv(tigerFill, VG_PAINT_COLOR, 4, &style[4]); vgSetf(VG_STROKE_LINE_WIDTH, style[8]); vgDrawPath(tigerPaths[i], (VGint)style[9]); // Bingo!!, Draw it!! } vgFlush(); }
static void draw(void) { vgClear(0, 0, width, height); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(width/2, height/2); vgRotate(angle); vgTranslate(-width/2, -height/2); lion_render(lion); ++angle; eglutPostRedisplay(); }
void CTSmallWindowOpenVG::RenderL() { CTWindow::RenderL(); // Make sure that this egl status is active eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG); VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f}; VGfloat scaleFactor = Size().iWidth/200.f; if (Size().iHeight/200.f < scaleFactor) { scaleFactor = Size().iHeight/200.f; } iCurrentRotation = iTime; if (iCurrentRotation >= 360.f) { iCurrentRotation -= 360.f; } vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0, 0, Size().iWidth, Size().iHeight); vgLoadIdentity(); vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2); vgScale(scaleFactor, scaleFactor); vgRotate(iCurrentRotation); vgTranslate(-50.f, -50.f); vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); vgSeti(VG_FILL_RULE, VG_EVEN_ODD); vgSetPaint(iFillPaint, VG_FILL_PATH); vgSetf(VG_STROKE_LINE_WIDTH, 10.f); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); vgSetf(VG_STROKE_MITER_LIMIT, 0.f); vgSetPaint(iStrokePaint, VG_STROKE_PATH); vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH); iTime++; eglSwapBuffers(iDisplay, iSurface); }
void OVGFont::DrawLine(VGFont &vgFont, VGint i32Size, VGuint *pStr, float fHeight, float fScale) { static float fOrigin[] = {0.0f, 0.0f}; /* Everytime vgDrawGlyph(s) is called the glyph(s) are drawn at the position defined by VG_GLYPH_ORIGIN. This value is updated after each call by the escapement vector defined by the glyph. As we don't want our text to follow any of the text previously drawn we're setting the glyph orign to 0,0. */ vgSetfv(VG_GLYPH_ORIGIN, 2, fOrigin); /* Using the matrix mode MATRIX_GLYPH_USER_TO_SURFACE translate and scale the font. */ vgLoadIdentity(); vgTranslate(0.0f, fHeight); vgScale(fScale, fScale); /* Our string is only a few glyphs long so we're going to repeatedly draw it until the x value of the GLYPH_ORIGIN is greater than the scaled width. */ float fGlyphOrigin[2]; fGlyphOrigin[0] = 0.0f; fGlyphOrigin[1] = 0.0f; float fScaledWidth = m_ui32ScreenWidth / fScale; while(fGlyphOrigin[0] < fScaledWidth) { /* Draw i32Size no of glyphs from pStr. The VG_FILL_PATH parameter defines how you would like the glyph (if a path) to be displayed. You can also have it stroked by using VG_STROKE_PATH. This parameter doesn't affect image based glyphs unless it's value is set to 0 in which case no glyph (path or image based) will be drawn. The fourth and fifth parameters are the x and y adjustments for each glyph. These can be set to adjust the position of the glyphs drawn or can be set to NULL. The final parameter (set to VG_TRUE) disables or enables autohinting. If equal to true autohinting may be applied to alter the glyphs slightly to improve the render quality. */ vgDrawGlyphs(vgFont, i32Size, &pStr[0], NULL,NULL, VG_FILL_PATH, VG_TRUE); // Get the updated GLYPH_ORIGIN vgGetfv(VG_GLYPH_ORIGIN, 2, &fGlyphOrigin[0]); } }
static void draw(void) { vgClear(0, 0, window_width(), window_height()); vgLoadIdentity(); vgTranslate(50, 21); vgDrawPath(path, VG_FILL_PATH); vgFlush(); }
// C function:: void vgTranslate(VGfloat tx, VGfloat ty); JNIEXPORT jint JNICALL Java_com_example_startvg_VG11_vgTranslate( JNIEnv* env, jobject obj, jfloat tx, jfloat ty){ vgTranslate( (VGfloat) tx, (VGfloat) ty ); }
/******************************************************************************* * Function Name : DoRotateCentered * Description : Demonstrate the effect of rotating around the centre of a * shape. Each path is transformed separately. *******************************************************************************/ void CTransforms::DoRotateCentered() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3*3]; vgGetMatrix(afUnitMatrix); float fRotationAngle = m_ui32AbsTime * 0.03f; // Scaling a shape from its center is identical to moving it to the // origin, scaling it there, and moving it back where it was. // // IMPORTANT: // Since OpenVG right-multiplies matrices, you conceptually need to // call the transformation functions in backwards order. vgTranslate(0.5f, 0.75f); vgRotate(fRotationAngle); vgTranslate(-0.5f, -0.75f); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // transformation for second path vgTranslate(0.5f, 0.25f); vgRotate(-fRotationAngle); vgTranslate(-0.5f, -0.25f); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
static void draw(EGLmanager *eglman) { VGfloat black[] = {0.f, 0.f, 0.f, 1.f}; // Render 3D scene by GL eglBindAPI(EGL_OPENGL_ES_API); eglMakeCurrent(eglman->dpy, eglman->pbuf_surface, eglman->pbuf_surface, eglman->es_ctx); // Modify GL texture source glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(0.0, 1.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(0.0, 0.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); // Make current to VG content eglBindAPI(EGL_OPENVG_API); eglMakeCurrent(eglman->dpy, eglman->win_surface, eglman->win_surface, eglman->vg_ctx); // Draw VGImage target vgSetfv(VG_CLEAR_COLOR, 4, black); vgClear(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); vgSeti(VG_BLEND_MODE, VG_BLEND_SRC); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(WINDOW_WIDTH/2.0f, WINDOW_HEIGHT/2.0f); vgScale((VGfloat)WINDOW_WIDTH/(VGfloat)TEXTURE_WIDTH * 0.8f, (VGfloat)WINDOW_HEIGHT/(VGfloat)TEXTURE_HEIGHT * 0.8f); vgTranslate(-TEXTURE_WIDTH/2.0f, -TEXTURE_HEIGHT/2.0f); vgDrawImage(eglman->vg_image); // Swap buffer eglSwapBuffers(eglman->dpy, eglman->win_surface); return; }
int render(int width, int height) { static DWORD startTick =0; static DWORD frames = 0; VGImage image; char buf[256]; if((startTick == 0)||(frames > 50)) { if(frames > 50) frames = 0; startTick = GetTickCount(); frames++; } else { sprintf(buf, "fps:%2.2f frames/sec \n", (float)(frames++)*1000/(GetTickCount() - startTick)); OutputDebugString(buf); } if(pReadFile == NULL) { pReadFile = fopen("test.rgb","rb"); if(pReadFile) fseek(pReadFile, 0 , SEEK_SET); } if(pReadFile && (feof(pReadFile))) fseek(pReadFile, 0 , SEEK_SET); if(pReadFile) fread(pBuff, sizeof(BYTE),SRC_WIDTH*SRC_HEIGHT*2,pReadFile); image = vgCreateImage( VG_sRGB_565, SRC_WIDTH, SRC_HEIGHT, VG_IMAGE_QUALITY_BETTER ); if(image == NULL) return -1; vgImageSubData( image, pBuff, SRC_WIDTH*2, VG_sRGB_565, 0, 0, SRC_WIDTH, SRC_HEIGHT); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgScale((VGfloat)width/SRC_WIDTH, (VGfloat)height/SRC_HEIGHT); vgTranslate(SRC_WIDTH, SRC_HEIGHT); vgRotate(180.0f); vgDrawImage( image ); vgDestroyImage( image ); if ( vgGetError() == VG_NO_ERROR ) eglSwapBuffers( egldisplay, eglsurface ); return 0; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CChildImage::RenderScene() { //Clear the screen with the current clear color. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); //Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //Set the current matrix to the identiy vgLoadIdentity(); //Translate the image to the desired position vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5.0f); //Draw the main image vgDrawImage(m_vgImage); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the first child image... int i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 5.0f); //...and draw vgDrawImage(m_avgChildImages[0]); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the second child image... i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT) + vgGetParameteri(m_avgChildImages[1], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 10.0f); //...and draw vgDrawImage(m_avgChildImages[1]); m_PrintVG.DisplayDefaultTitle("ChildImage", "", ePVRTPrint3DLogoIMG); return true; }
void CHuiVg10CanvasGc::DoDrawRenderBuffer(const CHuiCanvasRenderBuffer& aImage, const THuiRealPoint& aDestinationPoint) { const CHuiVg10CanvasRenderBuffer* vg10RenderBuffer = (const CHuiVg10CanvasRenderBuffer*) &aImage; CHuiVg10Gc* vg10Gc = (CHuiVg10Gc *)iGc; if (vg10RenderBuffer->Image()) { vg10Gc->UpdateColor(); iGc->Push(EHuiGcMatrixModel); vgTranslate(aDestinationPoint.iX, aDestinationPoint.iY); vgDrawImage(vg10RenderBuffer->Image()); iGc->Pop(EHuiGcMatrixModel); } }
static void draw(void) { const VGint w = 48; VGImage img1, img2; VGint x, y; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, window_width(), window_height()); img1 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); img2 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); x = 5; y = (window_height() - w) / 2; /* test vgSetPixels */ vgSetfv(VG_CLEAR_COLOR, 4, red); vgClearImage(img1, 0, 0, w, w / 2); vgSetfv(VG_CLEAR_COLOR, 4, black); vgClearImage(img1, 0, w / 2, w, w / 2); vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgDrawImage */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(x, y); vgDrawImage(img1); /* test vgGetPixels */ vgGetPixels(img1, 0, 0, x, y, w, w); x += w + 5; vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgCopyImage */ vgCopyImage(img2, 0, 0, img1, 0, 0, w, w, VG_FALSE); vgSetPixels(x, y, img2, 0, 0, w, w); /* vgCopyPixels */ vgCopyPixels(x + w + 5, y, x, y, w, w); vgDestroyImage(img1); vgDestroyImage(img2); }
static void update_display(setting_render_internal_t* renderer) { // Render it out vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSetfv(VG_CLEAR_COLOR, 4, renderer->definition.background_colour); vgClear(renderer->definition.x, renderer->definition.y, renderer->definition.width, renderer->definition.height); vgSetiv(VG_SCISSOR_RECTS, 4, &renderer->definition.x); vgSeti(VG_SCISSORING, VG_TRUE); vgTranslate(renderer->definition.x, renderer->definition.y); vgSeti(VG_RENDERING_QUALITY, renderer->definition.text_quality); vgSetPaint(renderer->state.text_paint, VG_FILL_PATH); gfx_render_text(renderer->definition.text_x_offset, renderer->definition.text_y_offset, renderer->definition.text, &gfx_font_sans, renderer->definition.text_size); VGfloat text_width = gfx_text_width(renderer->definition.text, &gfx_font_sans, renderer->definition.text_size); const size_t buffer_size = 512; char setting_text_buffer[buffer_size]; setting_t* setting = renderer->definition.setting; switch(setting->type) { case SETTING_TYPE_INT: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_int(setting)); break; } case SETTING_TYPE_FLOAT: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_float(setting)); break; } case SETTING_TYPE_ENUM: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_enum(setting)); break; } default: snprintf(setting_text_buffer, buffer_size - 1, "ILLEGAL SETTING TYPE: %d", (int)setting->type); break; } setting_text_buffer[buffer_size - 1] = 0; gfx_render_text(text_width + 2 + renderer->definition.text_x_offset, renderer->definition.text_y_offset, setting_text_buffer, &gfx_font_sans, renderer->definition.text_size); vgSeti(VG_SCISSORING, VG_FALSE); }
static void draw(void) { VGPath line; VGPaint fillPaint; VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS}; VGfloat lineCoords[] = {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f}; VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */ VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ //VGfloat testRadius = 60.0f; VGfloat testRadius = 10.0f; int WINDSIZEX = window_width(); int WINDSIZEY = window_height(); line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); fillPaint = vgCreatePaint(); vgSetf(VG_STROKE_LINE_WIDTH, 1.0f); //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(60, 60); vgScale(testRadius * 2, testRadius * 2); vgAppendPathData(line, 3, lineCommands, lineCoords); vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgSetPaint(fillPaint, VG_STROKE_PATH); vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor); vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgClear(0, 0, WINDSIZEX, WINDSIZEY); vgDrawPath(line, VG_STROKE_PATH); vgDestroyPath(line); vgDestroyPaint(fillPaint); }
void display(float interval) { VGfloat cc[] = {0,0,0,1}; angle += interval * 0.4 * PI; if (angle > 2*PI) angle -= 2*PI; amount = (sin(angle) + 1) * 0.5f; createMorph(); vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgLoadIdentity(); vgTranslate(testWidth()/2, testHeight()/2); vgScale(1.5, 1.5); vgDrawPath(iMorph, VG_FILL_PATH); }
bool HbSgimageIconProcessor::renderNvg(const QByteArray& byteArray, const QRect& rect, Qt::AspectRatioMode aspectRatioMode, bool mirrored) { QPoint topLeft = rect.topLeft(); QSize size(rect.size()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); if (!topLeft.isNull()) { vgTranslate(topLeft.x(), topLeft.y()); } NvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(aspectRatioMode); sgImageRenderer->nvgEngine()->setPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, settings.type); sgImageRenderer->nvgEngine()->enableMirroring(mirrored); HbNvgEngine::HbNvgErrorType errorType = sgImageRenderer->nvgEngine()->drawNvg(byteArray, size); return errorType == HbNvgEngine::NvgErrNone; }
void display(float interval) { int x,y,p; VGfloat white[] = {1,1,1,1}; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, testWidth(), testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); for (y=0, p=0; y<3; ++y) { for (x=0; x<3; ++x, ++p) { if (p > NUM_PRIMITIVES) break; vgLoadIdentity(); vgTranslate(100 + x*150, 100 + y*150); vgDrawPath(primitives[p], VG_STROKE_PATH); } } }
int main() { int running = GL_TRUE; int width = 640; int height = 480; int x = 50; int y = 50; int w = 10; int h = 10; /* Window *win = check_malloc (sizeof(Window)); win->width = 640; win->height = 480; */ // Initialize GLFW, create a ShivaVG context, open a window if( !glfwInit() ) { return 1; // Couldn't initialize GLFW } int n = glfwOpenWindow(width, height, 0,0,0,0,0,0, GLFW_WINDOW); if (!n) { glfwTerminate(); // Cleanup GLFW return 1; // Couldn't create a window } glfwSetWindowCloseCallback(window_close_callback); glfwSetWindowTitle("Shiva test"); vgCreateContextSH(width, height); // XXX: TODO: handle errors!!!! /* Rect *r = make_rect(0,0,100,100,0,1,1,1); win->rect = r; */ //make color VGPaint paint; VGfloat paint_array[] = {1,0,1,1}; paint = vgCreatePaint(); vgSetParameterfv(paint, VG_PAINT_COLOR, 4, paint_array); //make rect VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1,0,0,0, VG_PATH_CAPABILITY_ALL); vguRect(path, 0, 0, w, h); VGfloat magenta[] = {0.9,0,0,1}; while (running) { vgSetfv(VG_CLEAR_COLOR, 4, magenta); vgClear(0, 0, width, height); vgLoadIdentity(); vgTranslate(x, y); vgSetPaint(paint, VG_FILL_PATH); vgDrawPath(path, VG_FILL_PATH); glfwSwapBuffers(); // Terminate when ESC is pressed or the window is closed running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } // Close the window, clean up the ShivaVG context, and clean up GLFW vgDestroyContextSH(); // Close window and terminate GLFW glfwTerminate(); return 0; }
void text_widget_draw_text ( struct TEXT_WIDGET_HANDLE handle ) { if ( handle.d == NULL || handle.d->layout == NULL ) return; vgSetPaint( handle.d->foreground, VG_FILL_PATH ); vgSeti( VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE ); vgLoadIdentity(); #if 0 // Overscan (in dots, evidently). vgTranslate( 14.f, 8.f ); #endif // Offset in mm. vgScale( handle.d->dpmm_x, handle.d->dpmm_y ); // Move to the corner. vgTranslate( handle.d->x_mm, handle.d->y_mm ); // Back to dots. vgScale( 1.f/handle.d->dpmm_x, 1.f/handle.d->dpmm_y ); int height = PANGO_PIXELS( pango_layout_get_height( handle.d->layout ) ); PangoLayoutIter* li = pango_layout_get_iter( handle.d->layout ); do { PangoLayoutRun* run = pango_layout_iter_get_run( li ); if ( run == NULL ) continue; PangoRectangle logical_rect; int baseline_pango = pango_layout_iter_get_baseline( li ); int baseline_pixel = PANGO_PIXELS( baseline_pango ); pango_layout_iter_get_run_extents( li, NULL, &logical_rect ); int x_pixel = PANGO_PIXELS( logical_rect.x ); PangoFont* pg_font = run->item->analysis.font; FT_Face face = pango_fc_font_lock_face( (PangoFcFont*)pg_font ); if ( face != NULL ) { struct VG_DATA* vg_data = face->size->generic.data; if ( vg_data != NULL ) { // About the only extra attribute we can manage is the foreground // color. But, it might be nice to render a background color // to see just how badly the text is fitted into the widget // box. GSList* attr_item = run->item->analysis.extra_attrs; while ( attr_item ) { PangoAttribute* attr = attr_item->data; switch ( attr->klass->type ) { case PANGO_ATTR_FOREGROUND: { PangoColor color = ((PangoAttrColor*)attr)->color; VGfloat new_color[] = { (float)color.red / 65535.f, (float)color.green / 65535.f, (float)color.blue / 65535.f, 1.f }; VGPaint new_paint = vgCreatePaint(); vgSetParameterfv( new_paint, VG_PAINT_COLOR, 4, new_color ); vgSetPaint( new_paint, VG_FILL_PATH ); vgDestroyPaint( new_paint ); } break; default: printf( "\tHmm. Unknown attribute: %d\n", attr->klass->type ); } attr_item = attr_item->next; } // Note: inverted Y coordinate VGfloat point[2] = { x_pixel, height - baseline_pixel }; vgSetfv( VG_GLYPH_ORIGIN, 2, point ); VGFont vg_font = vg_data->font; int g; for ( g = 0; g < run->glyphs->num_glyphs; g++ ) { vgDrawGlyph( vg_font, run->glyphs->glyphs[g].glyph, VG_FILL_PATH, VG_TRUE ); } if ( vgGetPaint( VG_FILL_PATH ) != handle.d->foreground ) { vgSetPaint( handle.d->foreground, VG_FILL_PATH ); } } pango_fc_font_unlock_face( (PangoFcFont*)pg_font ); } } while ( pango_layout_iter_next_run( li ) ); // Iterators are not free. pango_layout_iter_free( li); }
TInt CNVGCSIcon::DoDrawL(const TSize aSize) { TInt ret = KErrNone; vgSetPaint(iFillPaint, VG_FILL_PATH); vgSetPaint(iStrokePaint, VG_STROKE_PATH); iLastFillPaintColor = 0; iLastStrkePaintColor = 0; iLastFillPaintType = 0; iLastStrokePaintType = 0; VGfloat lCurrentPathMatrix[9]; vgGetMatrix(lCurrentPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadMatrix(lCurrentPathMatrix); SetRotation(); #ifdef __MIRROR_ vgScale(1.0f, -1.0f); vgTranslate(0, (VGfloat)(-aSize.iHeight) ); #endif SetViewBoxToViewTransformationL(aSize); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); VGfloat currentMatrix[9]; vgGetMatrix(currentMatrix); iNVGIconData->BeginRead(); while (!iNVGIconData->EOF()) { switch (iNVGIconData->ReadInt32L()) { case EPath: { VGPath path = (VGPath)iNVGIconData->ReadInt32L(); VGPaintMode paintMode = (VGPaintMode)iNVGIconData->ReadInt32L(); if (path == VG_INVALID_HANDLE) { vgDrawPath(iPath, paintMode); } else { vgDrawPath(path, paintMode); } break; } case EPathData: { if (iPath != VG_INVALID_HANDLE) { VGint numSegments; VGubyte * pathSegments = 0; VGubyte * pathData = 0; numSegments = iNVGIconData->ReadInt32L(); pathSegments = new (ELeave) VGubyte[numSegments]; CleanupStack::PushL(TCleanupItem(CleanupArray, pathSegments)); if (pathSegments) { iNVGIconData->ReadL(pathSegments, numSegments); VGint coordinateCount = iNVGIconData->ReadInt32L(); pathData = new (ELeave) VGubyte[coordinateCount * 4]; if (pathData) { CleanupStack::PushL(TCleanupItem(CleanupArray, pathData)); iNVGIconData->ReadL(pathData, coordinateCount * 4); vgClearPath(iPath, VG_PATH_CAPABILITY_APPEND_TO); vgAppendPathData(iPath, numSegments, pathSegments, pathData); CleanupStack::PopAndDestroy(); } } CleanupStack::PopAndDestroy(); } break; } case EPaint: { DrawPaintL(iFillPaint, VG_MATRIX_FILL_PAINT_TO_USER, iLastFillPaintType, iLastFillPaintColor, VG_FILL_PATH); break; } case EColorRamp: { iNVGIconData->ReadInt32L(); break; } case ETransform: { TInt flag; VGfloat transformMatrix[9]; TPtr8 tmPtr((TUint8 *)transformMatrix, 9 * sizeof(VGfloat)); iNVGIconData->ReadL(tmPtr, 9 * sizeof(VGfloat)); flag = iNVGIconData->ReadInt32L(); vgLoadMatrix(currentMatrix); if (flag) { vgMultMatrix(transformMatrix); } } break; case EStrokeWidth: { VGfloat strokeWidth = iNVGIconData->ReadReal32L(); vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth); break; } case EStrokeMiterLimit: { VGfloat miterLimit = iNVGIconData->ReadReal32L(); vgSetf(VG_STROKE_MITER_LIMIT, miterLimit); break; } case EStrokeLineJoinCap: { VGint lineJoin = iNVGIconData->ReadInt32L(); VGint cap = iNVGIconData->ReadInt32L(); vgSeti(VG_STROKE_JOIN_STYLE, (VGJoinStyle)lineJoin); vgSeti(VG_STROKE_CAP_STYLE, (VGCapStyle)cap); break; } case EStrokePaint: { DrawPaintL(iStrokePaint, VG_MATRIX_STROKE_PAINT_TO_USER, iLastStrokePaintType, iLastStrkePaintColor, VG_STROKE_PATH); break; } case EStrokeColorRamp: { iNVGIconData->ReadInt32L(); break; } default: { User::Leave(KErrCorrupt); break; } } } iNVGIconData->EndRead(); return ret; }
// Translate the coordinate system to x,y void Translate(VGfloat x, VGfloat y) { vgTranslate(x, y); }
// --------------------------------------------------------------------------- // Computation of the viewport to viewbox transformation matrix // --------------------------------------------------------------------------- void CNvgFitToViewBoxImpl::SetWindowViewportTrans(TRect aViewPort, TSize aSize) { //VIEWPORT NUMBERS TReal lViewPortX = aViewPort.iTl.iX; TReal lViewPortY = aViewPort.iTl.iY; TReal lViewPortWidth = aViewPort.Width(); TReal lViewPortHeight = aViewPort.Height(); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgTranslate(lViewPortX, lViewPortY ); /* 2. Scale */ TReal lViewBoxXmin; TReal lViewBoxYmin; TReal lViewBoxWidth; TReal lViewBoxHeight; if ( iViewBoxDefined ) { lViewBoxXmin = ivbX; lViewBoxYmin = ivbY; lViewBoxWidth = ivbW; lViewBoxHeight = ivbH; } else { //this will default viewBox to <svg> element width and height lViewBoxXmin = 0; lViewBoxYmin = 0; lViewBoxWidth = aSize.iWidth; lViewBoxHeight = aSize.iHeight; } if ( lViewBoxWidth == 0.0f || lViewBoxHeight == 0.0f ) { return; } TReal sx = lViewPortWidth / lViewBoxWidth; TReal sy = lViewPortHeight / lViewBoxHeight; if ( sx == 0.0f || sy == 0.0f ) { return; } TReal xtrans = TReal( -1.0f ) * lViewBoxXmin; TReal ytrans = TReal( -1.0f ) * lViewBoxYmin; switch ( iAlign ) { case ENvgPreserveAspectRatio_None: /* Non uniform scaling */ //none - Do not force uniform scaling. //Scale the graphic content of the given element //non-uniformly if necessary such that the element's //bounding box exactly matches the viewport rectangle. //(Note: if <align> is none, then the optional <meetOrSlice> value is ignored.) break; case ENvgPreserveAspectRatio_XminYmin: //Align the <min-x> of the element's viewBox with the smallest X value of the viewport. //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; //no change for xtrans...default above } else // ( sx < sy ) { sy = sx; //no change for ytrans...default above } } else if (iMeetSlice == ENvgSlice) { if (sx > sy) { sy = sx; } else // ( sx < sy ) { sx = sy; } } break; case ENvgPreserveAspectRatio_XmidYmin: //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport. //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport. //Align the <min-x> of the element's viewBox with the smallest X value of the viewport. //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = ( ( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) )\ * 0.5 ) / sx - lViewBoxXmin; } else // ( sx < sy ) { sy = sx; //no change for ytrans...default above } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; } else //( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx; xtrans = xtrans/2.0 - lViewBoxXmin; } } break; case ENvgPreserveAspectRatio_XmaxYmin: //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport. //Align the <min-y> of the element's viewBox with the smallest Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = (( lViewPortWidth - ( ( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx\ - lViewBoxXmin; } else // ( sx < sy ) { sy = sx; //no change for ytrans...default above } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; //no change for ytrans...default above } else // ( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx - lViewBoxXmin; } } break; case ENvgPreserveAspectRatio_XminYmid: //Align the <min-x> of the element's viewBox with the smallest X value of the viewport. //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; //no change for xtrans...default above } else // ( sx < sy ) { sy = sx; ytrans = ( ( TReal ) ( lViewPortHeight - ( ( TReal ) ( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) )\ * TReal(.5) ) /sy - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx; ytrans = ytrans/2.0 - lViewBoxYmin; } else { sx = sy; } } break; case ENvgPreserveAspectRatio_XmidYmid: //(default) case //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport. //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) * \ 0.5 ) / sx - lViewBoxXmin; } else if ( sx < sy ) { sy = sx; ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) * \ 0.5 ) /sy - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx; ytrans = ytrans/2.0 - lViewBoxYmin; } else // ( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx; xtrans = xtrans/2.0 - lViewBoxXmin; } } break; case ENvgPreserveAspectRatio_XmaxYmid: //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport. //Align the midpoint Y value of the element's viewBox with the midpoint Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx \ - lViewBoxXmin; } else //( sx < sy ) { sy = sx; ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) \ * 0.5 ) /sy - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx; ytrans = ytrans/2.0 - lViewBoxYmin; } else //( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx - lViewBoxXmin; } } break; case ENvgPreserveAspectRatio_XminYmax: //Align the <min-x> of the element's viewBox with the smallest X value of the viewport. //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; //no change for xtrans...default above } else //( sx < sy ) { sy = sx; ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \ - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx - lViewBoxYmin; } else //( sx < sy ) { sx = sy; } } break; case ENvgPreserveAspectRatio_XmidYmax: //Align the midpoint X value of the element's viewBox with the midpoint X value of the viewport. //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) \ * 0.5 ) / sx - lViewBoxXmin; } else //( sx < sy ) { sy = sx; ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \ - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx - lViewBoxYmin; } else //( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx; xtrans = xtrans/2.0 - lViewBoxXmin; } } break; case ENvgPreserveAspectRatio_XmaxYmax: //Align the <min-x>+<width> of the element's viewBox with the maximum X value of the viewport. //Align the <min-y>+<height> of the element's viewBox with the maximum Y value of the viewport. if (iMeetSlice == ENvgMeet) { if ( sx > sy ) { sx = sy; xtrans = (( lViewPortWidth - (( lViewBoxWidth / lViewBoxHeight ) * lViewPortHeight ) ) ) / sx\ - lViewBoxXmin; } else //( sx < sy ) { sy = sx; ytrans = (( lViewPortHeight - (( lViewBoxHeight / lViewBoxWidth ) * lViewPortWidth ) ) ) /sy \ - lViewBoxYmin; } } else if (iMeetSlice == ENvgSlice) { if ( sx > sy ) { sy = sx; ytrans = lViewPortHeight - sx*lViewBoxHeight; ytrans = ytrans/sx - lViewBoxYmin; } else //( sx < sy ) { sx = sy; xtrans = lViewPortWidth - sx*lViewBoxWidth; xtrans = xtrans/sx - lViewBoxXmin; } } break; default: break; } vgScale( sx, sy); vgTranslate( xtrans, ytrans ); }