Esempio n. 1
0
/*******************************************************************************
 * Function Name  : CreatePaths
 * Description    : Create two simple OpenVG paths. One is centred around
 *                  (0.5, 0.25), the other around (0.5, 0.75).
 *                  This function will be called by InitView once.
 *******************************************************************************/
void CTransforms::CreatePaths()
{
	/*
	This is also a simple demonstration of relative path segments. Since
	we want both shapes to be identical, just in different locations, we
	can use the same data for both and just skip the first MOVE_TO_ABS
	when creating the second shape.
	*/
	static VGubyte aui8PathSegments[] = {
		VG_MOVE_TO_ABS,
		VG_MOVE_TO_REL,
		VG_VLINE_TO_REL,
		VG_HLINE_TO_REL,
		VG_VLINE_TO_REL,
		VG_CLOSE_PATH
	};

	static VGfloat afPathCoords[] = {
		0.0f, 0.5f,
		0.4f, 0.15f,
		0.2f,
		0.2f,
		-0.2f,
	};

	// Create a path handle...
	m_avgPaths[0] = vgCreatePath(
		VG_PATH_FORMAT_STANDARD,
		VG_PATH_DATATYPE_F,
		1.0f, 0.0f,
		6,
		7,
		VG_PATH_CAPABILITY_APPEND_TO);

	// ... and populate it with data
	vgAppendPathData(m_avgPaths[0], 6, aui8PathSegments, afPathCoords);

	// Do it a second time...
	m_avgPaths[1] = vgCreatePath(
		VG_PATH_FORMAT_STANDARD,
		VG_PATH_DATATYPE_F,
		1.0f, 0.0f,
		5,
		7,
		VG_PATH_CAPABILITY_APPEND_TO);

	// ... but skip the first MOVE_TO_ABS segment, effectively
	// starting at the origin
	vgAppendPathData(m_avgPaths[1], 5, &aui8PathSegments[1], &afPathCoords[2]);


	/*
	Path capabilities should be removed when no longer needed. The OpenVG
	implementation might work more efficiently if it knows that path data
	will not change.
	*/
	vgRemovePathCapabilities(m_avgPaths[0], VG_PATH_CAPABILITY_APPEND_TO);
	vgRemovePathCapabilities(m_avgPaths[1], VG_PATH_CAPABILITY_APPEND_TO);
}
Esempio n. 2
0
static void append(VGPath path, int numSegments, const VGubyte* segments, int numCoordinates, const VGfloat* coordinates)
{
	MK_ASSERT(numCoordinates <= 26);
	
	VGPathDatatype datatype = (VGPathDatatype)vgGetParameteri(path, VG_PATH_DATATYPE);
	VGfloat scale = vgGetParameterf(path, VG_PATH_SCALE);
	VGfloat bias = vgGetParameterf(path, VG_PATH_BIAS);
	
	switch(datatype)
	{
		case VG_PATH_DATATYPE_S_8:
		{
			
			int8_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int8_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		case VG_PATH_DATATYPE_S_16:
		{
			
			int16_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int16_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		case VG_PATH_DATATYPE_S_32:
		{
			int32_t data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (int32_t)floor((coordinates[i] - bias) / scale + 0.5f);	//add 0.5 for correct rounding
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
			
		default:
		{
			MK_ASSERT(datatype == VG_PATH_DATATYPE_F);
			float data[26];
			for(int i=0;i<numCoordinates;i++)
				data[i] = (float)((coordinates[i] - bias) / scale);
			vgAppendPathData(path, numSegments, segments, data);
			break;
		}
	}
}
Esempio n. 3
0
static void draw_point(VGfloat x, VGfloat y)
{

   static const VGubyte cmds[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS,
                                  VG_LINE_TO_ABS, VG_CLOSE_PATH};
   const VGfloat coords[]   = {  x - 2,  y - 2,
                                 x + 2,  y - 2,
                                 x + 2,  y + 2,
                                 x - 2,  y + 2};
   VGPath path;
   VGPaint fill;

   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
                       VG_PATH_CAPABILITY_ALL);
   vgAppendPathData(path, 5, cmds, coords);

   fill = vgCreatePaint();
   vgSetParameterfv(fill, VG_PAINT_COLOR, 4, black_color);
   vgSetPaint(fill, VG_FILL_PATH);

   vgDrawPath(path, VG_FILL_PATH);

   vgDestroyPath(path);
   vgDestroyPaint(fill);
}
Esempio n. 4
0
void testVlineTo(VGPath p, float y, VGPathAbsRel absrel)
{
  VGubyte seg = VG_VLINE_TO | absrel;
  VGfloat data = y;
  
  vgAppendPathData(p, 1, &seg, &data);
}
Esempio n. 5
0
/*******************************************************************************
 * Function Name  : CreatePath
 * Description    : Code in CreatePath() will be called by InitView() and is
 *					used to set up the path that will be used.
 *******************************************************************************/
void CStrokeStyles::CreatePath()
{
	static VGubyte aui8PathSegments[] = {
		VG_MOVE_TO_ABS,
		VG_VLINE_TO_ABS,
		VG_CUBIC_TO_ABS,
		VG_VLINE_TO_ABS
	};
	static VGfloat afPathCoords[] = {
		0.1f, 0.1f,
		0.5f,
		0.38f, 0.0f, 0.62f, 0.7f, 0.9f, 0.5f,
		0.1f
	};

	m_vgPath = vgCreatePath(
		VG_PATH_FORMAT_STANDARD,
		VG_PATH_DATATYPE_F,
		1.0f, 0.0f,
		4,
		10,
		VG_PATH_CAPABILITY_APPEND_TO);

	vgAppendPathData(
		m_vgPath,
		4,
		aui8PathSegments,
		afPathCoords);

	vgRemovePathCapabilities(m_vgPath, VG_PATH_CAPABILITY_APPEND_TO);
}
Esempio n. 6
0
static void add_char ( VGFont font, FT_Face face, FT_ULong c )
{
  // Pango already provides us with the font index, not the glyph UNICODE
  // point.

  FT_Load_Glyph( face, c, FT_LOAD_DEFAULT );

  FT_Outline *outline = &face->glyph->outline;

  VGPath path;
  path = vgCreatePath( VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
		       1.f, 0.f, 0, 0, VG_PATH_CAPABILITY_ALL );
  // It could be a blank. If any character doesn't have a glyph, though,
  // nothing is drawn by vgDrawGlyphs.
  if ( outline->n_contours > 0 ) {
    convert_outline( outline->points, outline->tags, outline->contours,
		     outline->n_contours, outline->n_points );
    vgAppendPathData( path, segments_count, segments, coords );
  }

  VGfloat origin[] = { 0.f, 0.f };
  VGfloat escapement[] = { float_from_26_6(face->glyph->advance.x),
			   float_from_26_6(face->glyph->advance.y) };

  vgSetGlyphToPath( font, c, path, VG_TRUE, origin, escapement );

  vgDestroyPath( path );
}
Esempio n. 7
0
 void OpenVG_SVGHandler::onPathQuad( float x1, float y1, float x2, float y2) {
     VGubyte seg = VG_QUAD_TO | openVGRelative();
     VGfloat data[4];
     data[0] = x1; data[1] = y1;
     data[2] = x2; data[3] = y2;
     vgAppendPathData(_current_group->current_path->path, 1, &seg, data);
 }
Esempio n. 8
0
	void OpenVG_SVGHandler::onPathArc( float rx, float ry, float x_axis_rotation, int large_arc_flag, int sweep_flag, float x, float y ) {
		
		VGubyte seg = openVGRelative();
		if ( large_arc_flag ) {
			if (sweep_flag) {
				seg |= VG_LCCWARC_TO;
			} else {
				seg |= VG_LCWARC_TO;
			}
		} else {
			if (sweep_flag) {
				seg |= VG_SCCWARC_TO;
			} else {
				seg |= VG_SCWARC_TO;
			}
			
		}
		VGfloat data[5];
		
	
		
		data[0] = rx;
		data[1] = ry;
		data[2] = x_axis_rotation;
		data[3] = x;
		data[4] = y;
		
		vgAppendPathData( _current_group->current_path->path, 1, &seg, data);
		
	}
Esempio n. 9
0
	void OpenVG_SVGHandler::onPathVerticalLine( float y ) {
		VGubyte seg = VG_VLINE_TO | openVGRelative();
		VGfloat data[1];
		data[0] = y; 
		vgAppendPathData( _current_group->current_path->path, 1, &seg, data );
		
	}
Esempio n. 10
0
// loadfont loads font path data
// derived from http://web.archive.org/web/20070808195131/http://developer.hybrid.fi/font2openvg/renderFont.cpp.txt
Fontinfo loadfont(const int *Points,
		  const int *PointIndices,
		  const unsigned char *Instructions,
		  const int *InstructionIndices, const int *InstructionCounts, const int *adv, const short *cmap, int ng) {

	Fontinfo f;
	int i;

	memset(f.Glyphs, 0, MAXFONTPATH * sizeof(VGPath));
	if (ng > MAXFONTPATH) {
		return f;
	}
	for (i = 0; i < ng; i++) {
		const int *p = &Points[PointIndices[i] * 2];
		const unsigned char *instructions = &Instructions[InstructionIndices[i]];
		int ic = InstructionCounts[i];
		VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_S_32,
					   1.0f / 65536.0f, 0.0f, 0, 0,
					   VG_PATH_CAPABILITY_ALL);
		f.Glyphs[i] = path;
		if (ic) {
			vgAppendPathData(path, ic, instructions, p);
		}
	}
	f.CharacterMap = cmap;
	f.GlyphAdvances = adv;
	f.Count = ng;
	f.descender_height = 0;
	f.font_height = 0;
	return f;
}
Esempio n. 11
0
	void OpenVG_SVGHandler::onPathHorizontalLine( float x ) {
		VGubyte seg = VG_HLINE_TO | openVGRelative();
		VGfloat data[1];
		data[0] = x; 
		vgAppendPathData( _current_group->current_path->path, 1, &seg, data );
		
	}
Esempio n. 12
0
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);
}
void Path::addArcTo(const FloatPoint& point1, const FloatPoint& point2, float radius)
{
    // See http://philip.html5.org/tests/canvas/suite/tests/spec.html#arcto.

    const FloatPoint& point0 = m_path->m_currentPoint;
    if (!radius || point0 == point1 || point1 == point2) {
        addLineTo(point1);
        return;
    }

    FloatSize v01 = point0 - point1;
    FloatSize v21 = point2 - point1;

    // sin(A - B) = sin(A) * cos(B) - sin(B) * cos(A)
    double cross = v01.width() * v21.height() - v01.height() * v21.width();

    if (fabs(cross) < 1E-10) {
        // on one line
        addLineTo(point1);
        return;
    }

    double d01 = hypot(v01.width(), v01.height());
    double d21 = hypot(v21.width(), v21.height());
    double angle = (piDouble - fabs(asin(cross / (d01 * d21)))) * 0.5;
    double span = radius * tan(angle);
    double rate = span / d01;
    FloatPoint startPoint = FloatPoint(point1.x() + v01.width() * rate,
                                       point1.y() + v01.height() * rate);
    rate = span / d21;
    FloatPoint endPoint = FloatPoint(point1.x() + v21.width() * rate,
                                     point1.y() + v21.height() * rate);

    // Fa: large arc flag, makes the difference between SCWARC_TO and LCWARC_TO
    //     respectively SCCWARC_TO and LCCWARC_TO arcs. We always use small
    //     arcs for arcTo(), as the arc is defined as the "shortest arc" of the
    //     circle specified in HTML 5.

    // Fs: sweep flag, specifying whether the arc is drawn in increasing (true)
    //     or decreasing (0) direction.
    const bool anticlockwise = cross < 0;

    // Translate the large arc and sweep flags into an OpenVG segment command.
    const VGubyte segmentCommand = anticlockwise ? VG_SCCWARC_TO_ABS : VG_SCWARC_TO_ABS;

    const VGubyte pathSegments[] = {
        VG_LINE_TO_ABS,
        segmentCommand
    };
    const VGfloat pathData[] = {
        startPoint.x(), startPoint.y(),
        radius, radius, 0, endPoint.x(), endPoint.y()
    };

    m_path->makeCompatibleContextCurrent();
    vgAppendPathData(m_path->vgPath(), 2, pathSegments, pathData);
    ASSERT_VG_NO_ERROR();

    m_path->m_currentPoint = endPoint;
}
Esempio n. 14
0
int   	FreeFormDrawing::draw 		(	)
{
	Control::draw();
	list<vector<VGuint>>::iterator   SCiter    = m_stroke_color.begin();
	list<vector<VGufloat>>::iterator SWiter    = m_stroke_widths.begin();
	list<vector<VGubyte>>::iterator  Cmditer   = m_commands.begin();
	list<vector<VGufloat>>::iterator Coorditer = m_coords.begin();

	for ( ; Coorditer!=m_coords.end(); )
	{
		int numCmds   = Cmditer.size();
		int numCoords = Coorditer.size();		
		VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
							VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 		// scale,bias
							numCmds, numCoords,
							VG_PATH_CAPABILITY_ALL);
		StrokeWidth	( *SWiter 	 );
		Stroke_l	( 0xFFFF00FF );

		vgAppendPathData(path, numCmds, commands, Coorditer->data() );
		vgDrawPath		(path, VG_STROKE_PATH			);		

		SCiter++;		SWiter++;
		Cmditer++;		Coorditer++;
	}
}
Esempio n. 15
0
void testLineTo(VGPath p, float x, float y, VGPathAbsRel absrel)
{
  VGubyte seg = VG_LINE_TO | absrel;
  VGfloat data[2];
  
  data[0] = x; data[1] = y;
  vgAppendPathData(p, 1, &seg, data);
}
Esempio n. 16
0
	void OpenVG_SVGHandler::onPathLineTo( float x, float y ) { 
		VGubyte seg = VG_LINE_TO | openVGRelative();
		VGfloat data[2];
		
		data[0] = x; data[1] = y;
		vgAppendPathData( _current_group->current_path->path, 1, &seg, data );
		
	}
Esempio n. 17
0
void testSquadTo(VGPath p, float x2, float y2,VGPathAbsRel absrel)
{
  VGubyte seg = VG_SQUAD_TO | absrel;
  VGfloat data[2];
  
  data[0] = x2; data[1] = y2;
  vgAppendPathData(p, 1, &seg, data);
}
void simpleVGPath::lineTo(float x, float y)
{
    VGubyte seg = VG_LINE_TO | VG_ABSOLUTE;
    float data[2];
    
    data[0] = x; data[1] = y;
    vgAppendPathData(_path, 1, &seg, data);
}
Esempio n. 19
0
	void OpenVG_SVGHandler::onPathSCubic( float x2, float y2, float x3, float y3 ) {
		VGubyte seg = VG_SCUBIC_TO | openVGRelative();
		VGfloat data[4];
		
		data[0] = x2; data[1] = y2;
		data[2] = x3; data[3] = y3;
		vgAppendPathData( _current_group->current_path->path, 1, &seg, data);
		
	}
void simpleVGPath::quadTo(float controlX, float controlY, float x, float y)
{
    VGubyte seg = VG_QUAD_TO | VG_ABSOLUTE;
    float data[4];
    
    data[0] = controlX; data[1] = controlY;
    data[2] = x; data[3] = y;
    vgAppendPathData(_path, 1, &seg, data);
}
void simpleVGPath::cubicTo(float controlX1, float controlY1, float controlX2, float controlY2, float x, float y)
{
    VGubyte seg = VG_CUBIC_TO | VG_ABSOLUTE;
    float data[6];
    
    data[0] = controlX1; data[1] = controlY1;
    data[2] = controlX2; data[3] = controlY2;
    data[4] = x; data[5] = y;
    vgAppendPathData(_path, 1, &seg, data);
}	
Esempio n. 22
0
void testScubicTo(VGPath p, float x2, float y2, float x3, float y3,
                  VGPathAbsRel absrel)
{
  VGubyte seg = VG_SCUBIC_TO | absrel;
  VGfloat data[4];
  
  data[0] = x2; data[1] = y2;
  data[2] = x3; data[3] = y3;
  vgAppendPathData(p, 1, &seg, data);
}
Esempio n. 23
0
/****************************************************************************
** InitView() is called by PVRShell each time a rendering variable is changed
** in the Shell menu (Z-Buffer On/Off, resolution change, buffering mode...)
** In this function one should initialise all variables that are dependant on
** general rendering variables (screen mode, 3D device, etc...)
****************************************************************************/
bool CIntroducingPVRShell::InitView()
{
	/*
	Initially, the OpenVG coordinate system is based on the output resolution.
	To get a device independent coordinate system, we need to apply a
	transformation. Scaling by the output resolution means that coordinates
	between (0, 0) and (1, 1) will be visible on screen.

	It should be noted, however, that different aspect ratios usually require
	special attention regarding the layout of elements on screen.
	*/
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	/*
	Drawing shapes with OpenVG requires a path which represents a series of
	line and curve segments describing the outline of the shape. The shape
	does not need to be closed, but for now we will start with a simple
	triangle.
	First we create a path object, then we append segment and point data.
	*/
	m_vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 4, 3, (unsigned int)VG_PATH_CAPABILITY_ALL);

	VGubyte aui8PathSegments[4] = {
		VG_MOVE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_CLOSE_PATH,
	};
	VGfloat afPoints[6] = {
			0.3f, 0.3f,
			0.7f, 0.3f,
			0.5f, 0.7f,
	};
	vgAppendPathData(m_vgPath, 4, aui8PathSegments, afPoints);

	/*
	To fill a shape, we need a paint that describes how to fill it: a gradient,
	pattern, or single colour. Here we choose a simple opaque red.
	*/
	m_vgFillPaint = vgCreatePaint();
	vgSetParameteri(m_vgFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_vgFillPaint, PVRTRGBA(255,255,170,255));

	/*
	The clear colour will be used whenever calling vgClear(). The colour is given
	as non-premultiplied sRGBA.
	*/
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	return true;
}
void Path::addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint)
{
    static const VGubyte pathSegments[] = { VG_CUBIC_TO_ABS };
    const VGfloat pathData[] = { controlPoint1.x(), controlPoint1.y(), controlPoint2.x(), controlPoint2.y(), endPoint.x(), endPoint.y() };

    m_path->makeCompatibleContextCurrent();
    vgAppendPathData(m_path->vgPath(), 1, pathSegments, pathData);
    ASSERT_VG_NO_ERROR();

    m_path->m_currentPoint = endPoint;
}
void Path::addLineTo(const FloatPoint& point)
{
    static const VGubyte pathSegments[] = { VG_LINE_TO_ABS };
    const VGfloat pathData[] = { point.x(), point.y() };

    m_path->makeCompatibleContextCurrent();
    vgAppendPathData(m_path->vgPath(), 1, pathSegments, pathData);
    ASSERT_VG_NO_ERROR();

    m_path->m_currentPoint = point;
}
Esempio n. 26
0
void testArcTo(VGPath p, float rx, float ry, float rot, float x, float y,
               VGPathSegment type, VGPathAbsRel absrel)
{
  VGubyte seg = type | absrel;
  VGfloat data[5];
  
  data[0] = rx; data[1] = ry;
  data[2] = rot;
  data[3] = x;  data[4] = y;
  vgAppendPathData(p, 1, &seg, data);
}
Esempio n. 27
0
	// C function:: void vgAppendPathData(VGPath dstPath, VGint numSegments, 
	//              const VGubyte * pathSegments, const void * pathData);
	JNIEXPORT jint JNICALL
	Java_com_example_startvg_VG11_vgAppendPathData( 
		JNIEnv * env, jobject obj, 
		jlong dstPathHandle, jint numSegments, jobject pathSegments, jobject pathData) {
			
		vgAppendPathData(
			(VGPath) dstPathHandle, 
			(VGint) numSegments, 
			(const VGubyte *) pathSegments, 
			(const void *) pathData
		);
	}
void Path::closeSubpath()
{
    static const VGubyte pathSegments[] = { VG_CLOSE_PATH };
    // pathData must not be 0, but certain compilers also don't create
    // zero-size arrays. So let's use a random aligned value (sizeof(VGfloat)),
    // it won't be accessed anyways as VG_CLOSE_PATH doesn't take coordinates.
    static const VGfloat* pathData = reinterpret_cast<VGfloat*>(sizeof(VGfloat));

    m_path->makeCompatibleContextCurrent();
    vgAppendPathData(m_path->vgPath(), 1, pathSegments, pathData);
    ASSERT_VG_NO_ERROR();

    m_path->m_currentPoint = m_path->m_subpathStartPoint;
}
Esempio n. 29
0
static void
init(void)
{
   VGfloat clearColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */
   VGfloat fillColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */
   static const VGubyte segments[4] = {VG_MOVE_TO_ABS,
                                       VG_SCCWARC_TO_ABS,
                                       VG_SCCWARC_TO_ABS,
                                       VG_CLOSE_PATH};
   VGfloat data[12];
   const VGfloat cx = 0, cy=29, width=80, height=40;
   const VGfloat hw = width * 0.5f;
   const VGfloat hh = height * 0.5f;

   data[0] = cx + hw;
   data[1] = cy;
   data[2] = hw;
   data[3] = hh;
   data[4] = 0;
   data[5] = cx - hw;
   data[6] = cy;
   data[7] = hw;
   data[8] = hh;
   data[9] = 0;
   data[10] = data[0];
   data[11] = cy;

   vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
   vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);


   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                       1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
   if (path == VG_INVALID_HANDLE) {
      return;
   }
   paint = vgCreatePaint();
   if (paint == VG_INVALID_HANDLE) {
      vgDestroyPath(path);
      return;
   }

   vgAppendPathData(path, 4, segments, data);
   vgSetParameterfv(paint, VG_PAINT_COLOR, 4, fillColor);
   vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   vgSetPaint(paint, VG_FILL_PATH);
}
Esempio n. 30
0
VCOS_STATUS_T vgft_font_convert_glyphs(VGFT_FONT_T *font, unsigned int char_height, unsigned int dpi_x, unsigned int dpi_y)
{
   FT_UInt glyph_index;
   FT_ULong ch;

   if (FT_Set_Char_Size(font->ft_face, 0, char_height, dpi_x, dpi_y))
   {
      FT_Done_Face(font->ft_face);
      vgDestroyFont(font->vg_font);
      return VCOS_EINVAL;
   }

   ch = FT_Get_First_Char(font->ft_face, &glyph_index);

   while (ch != 0)
   {
      if (FT_Load_Glyph(font->ft_face, glyph_index, FT_LOAD_DEFAULT)) {
         FT_Done_Face(font->ft_face);
         vgDestroyFont(font->vg_font);
         return VCOS_ENOMEM;
      }

      VGPath vg_path;
      FT_Outline *outline = &font->ft_face->glyph->outline;
      if (outline->n_contours != 0) {
         vg_path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
         assert(vg_path != VG_INVALID_HANDLE);

         convert_outline(outline->points, outline->tags, outline->contours, outline->n_contours, outline->n_points);
         vgAppendPathData(vg_path, segments_count, segments, coords);
      } else {
         vg_path = VG_INVALID_HANDLE;
      }

      VGfloat origin[] = { 0.0f, 0.0f };
      VGfloat escapement[] = { float_from_26_6(font->ft_face->glyph->advance.x), float_from_26_6(font->ft_face->glyph->advance.y) };
      vgSetGlyphToPath(font->vg_font, glyph_index, vg_path, VG_FALSE, origin, escapement);

      if (vg_path != VG_INVALID_HANDLE) {
         vgDestroyPath(vg_path);
      }
      ch = FT_Get_Next_Char(font->ft_face, ch, &glyph_index);
   }

   return VCOS_SUCCESS;
}