void SubtitleRenderer:: draw_text(VGFont font, VGFont italic_font, const std::vector<SubtitleRenderer::InternalChar>& text, int x, int y, unsigned int lightness) { VGPaint paint = vgCreatePaint(); assert(paint); vgSetColor(paint, (lightness<<8) | (lightness<<16) | (lightness<<24) | 0xFF); assert(!vgGetError()); vgSetPaint(paint, VG_FILL_PATH); assert(!vgGetError()); vgDestroyPaint(paint); assert(!vgGetError()); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY); assert(!vgGetError()); VGfloat pos[] = {static_cast<VGfloat>(x), static_cast<VGfloat>(y)}; vgSetfv(VG_GLYPH_ORIGIN, 2, pos); assert(!vgGetError()); for (auto c = text.begin(); c != text.end(); ++c) { vgDrawGlyph(c->italic ? italic_font : font, c->codepoint, VG_FILL_PATH, VG_FALSE); assert(!vgGetError()); } }
GLDEF_C TInt E32Main() { RDebug::Printf("testing VG 1.0 function"); VGPath path0 = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); RDebug::Printf("finished testing VG 1.0 function"); #ifdef OPENVG_VERSION_1_1 if(strcmp((const char*)vgGetString(VG_VERSION), "1.1")==0) { RDebug::Printf("testing function introduced in 1.1"); VGFont font = vgCreateFont(245); vgDrawGlyph(font, 2, 256, VG_FALSE); RDebug::Printf("finished testing function introduced in 1.1"); } #endif 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); }