OpenCores
URL https://opencores.org/ocsvn/orsoc_graphics_accelerator/orsoc_graphics_accelerator/trunk

Subversion Repositories orsoc_graphics_accelerator

[/] [orsoc_graphics_accelerator/] [trunk/] [sw/] [drivers/] [gfx/] [bare/] [orgfx_vector_font.c] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 maiden
 
2
#include "orgfx_vector_font.h"
3
#include "orgfx_3d.h"
4
#include "orgfx.h"
5
 
6
#include <stdio.h>
7
 
8
orgfx_vector_font orgfx_make_vector_font(Glyph *glyphlist,int size, Glyph **glyphindexlist, int glyphindexlistsize)
9
{
10
    orgfx_vector_font font;
11
    font.size = size;
12
    font.glyph = glyphlist;
13
    font.index_list_size = glyphindexlistsize;
14
    font.index_list = glyphindexlist;
15
    return font;
16
}
17
// takes all glyphs and generate a pointer list with correct index to all glyphs.
18
int orgfx_init_vector_font(orgfx_vector_font font)
19
{
20
    int i,j;
21
    // for all in the glyphindex.
22
 
23
    for(i=0; i<font.index_list_size; i++)
24
        font.index_list[i] = 0;
25
 
26
    for(i=0; i<font.size; i++)
27
    {
28
        // if character code is outside our glyph scope, return error
29
        if(font.glyph[i].index >= font.index_list_size)
30
            return 1;
31
 
32
        // match the glyph index with the ascii code i
33
        for(j=0; j<font.index_list_size; j++)
34
            if(j == font.glyph[i].index )
35
            {
36
                font.index_list[j] = &(font.glyph[i]);
37
                break;
38
            }
39
    }
40
    // all went well
41
    return 0;
42
}
43
 
44
void orgfx_vf_write(orgfx_vector_font* glyph, const wchar_t *text, int xoffset, int yoffset, int color)
45
{
46
    int i,j;
47
    int width = 35;
48
    float scale = 0.05;
49
    yoffset += width*1.5;
50
 
51
    orgfx_enable_tex0(0);
52
    orgfx_set_colors(color,color,color);
53
    i = 0;
54
 
55
    while(1)
56
    {
57
        wchar_t c = text[i++];
58
        // Break if we reach the end of the string
59
        if(c == 0)
60
            break;
61
 
62
        if(c != ' ')
63
            orgfx_vf_write_char(glyph,c, xoffset, yoffset, scale);
64
        else
65
            xoffset += 20;
66
 
67
        if(glyph->index_list[c])
68
            xoffset += glyph->index_list[c]->advance_x*scale;
69
    }
70
}
71
 
72
void orgfx_vf_write_char(orgfx_vector_font* glyph, wchar_t text, int xoffset, int yoffset, float scale)
73
{
74
    if(glyph->index_list[text] == 0)
75
        return;
76
 
77
    int i;
78
    orgfx_point3 scaled = {scale,scale,scale};
79
    orgfx_point3 translate = {xoffset,yoffset,0};
80
    orgfx_enable_transform(1);
81
    orgfx_matrix m = orgfx3d_identity();
82
    m = orgfx3d_scale(m, scaled);
83
    m = orgfx3d_translate(m, translate);
84
    orgfx3d_set_matrix(m);
85
 
86
    for(i=0; i<glyph->index_list[text]->triangle_n_writes; i++)
87
    {
88
        orgfx_triangle((glyph->index_list[text]->triangle[i].p0.x)*FIXEDW,(glyph->index_list[text]->triangle[i].p0.y)*FIXEDW,
89
                       (glyph->index_list[text]->triangle[i].p1.x)*FIXEDW,(glyph->index_list[text]->triangle[i].p1.y)*FIXEDW,
90
                       (glyph->index_list[text]->triangle[i].p2.x)*FIXEDW,(glyph->index_list[text]->triangle[i].p2.y)*FIXEDW, 1);
91
    }
92
    for(i=0; i<glyph->index_list[text]->bezier_n_writes; i++)
93
    {
94
        orgfx_curve((glyph->index_list[text]->bezier[i].start.x)*FIXEDW, (glyph->index_list[text]->bezier[i].start.y)*FIXEDW,
95
                    (glyph->index_list[text]->bezier[i].control.x)*FIXEDW, (glyph->index_list[text]->bezier[i].control.y)*FIXEDW,
96
                    (glyph->index_list[text]->bezier[i].end.x)*FIXEDW, (glyph->index_list[text]->bezier[i].end.y)*FIXEDW,
97
                    glyph->index_list[text]->bezier[i].fillInside);
98
    }
99
 
100
    orgfx_enable_transform(0);
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.