开发者

Drawing stroked text with True Type Fonts

开发者 https://www.devze.com 2023-02-18 09:51 出处:网络
Right now in my game I\'m drawing true type fonts like this: for(int i = linesSkipped; i <= maxitems + linesSkipped; ++i)

Right now in my game I'm drawing true type fonts like this:

for(int i = linesSkipped; i <= maxitems + linesSkipped; ++i)
    {
        if(i >= (int)textRows.size())
        {
            break;
        }
        paintargs.graphics()->drawText(AguiPoint(textX - 2,
            textY - 2 + (i * getFont().getLineHeight())),
            textRows[i].c_str(),AguiColor(0,0,0),getFont());

        paintargs.graphics()->drawText(AguiPoint(textX + 2,
            textY + 2 + (i * getFont().getLineHeight())),
            textRows[i].c_str(),AguiColor(0,0,0),getFont());

        paintargs.开发者_如何学Pythongraphics()->drawText(AguiPoint(textX,
            textY + (i * getFont().getLineHeight())),
            textRows[i].c_str(),AguiColor(255,128,0),getFont());

    }

So I draw it with an offset of 2, then with an offset of -1 .

It almost does what I want, but the top right and bottom left edges are still unstroked:

Drawing stroked text with True Type Fonts

Is there a way to draw it such that it would look like stroking in Photoshop?

Thanks


Which API are you using? Is that GDI+?

You can draw the outlines at more locations before drawing the inside:

(x-2, y-2) (x, y-2) (x+2,y-2)
(x-2, y  )          (x+2,y  )
(x-2, y+2) (x, y+2) (x+2,y+2)

Or you can see if your graphics API has something like paths. With paths, you tell the graphics library you want to start a path, then draw the text once, then end the path. Once that's done, you tell the graphics library to "stroke and fill" the path. This is the cleanest solution.


You need to draw the text in all corners! What you're doing is drawing in the top-left corner and in the bottom-right corner, which is respectively X=-2, Y=-2 and X=2, Y=2. What you need to do, is to draw them in the bottom-left and the top-right corner too, which would be respectively X=-2, Y=2 and X=2, Y=-2.


If you have no means to influence the text rendering method, draw the text in the first step and the stroke in a second step like so

r=5; //pixel-thickness of stroke 
for ( x = xmin; x<=xmax; x++ )
    for( y = ymin; y=<max; y++ )
       if ( isWhite(x,y) && orangePixelNearby(r,x,y) )
           putPixel(x,y)

Of course there are more efficient ways to do that but this one illustrates best how strokes are rendered.

0

精彩评论

暂无评论...
验证码 换一张
取 消