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 8

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 8 Orka
orgfx_vector_font orgfx_make_vector_font(Glyph *glyphlist,
9
                                         int size,
10
                                         Glyph **glyphindexlist,
11
                                         int glyphindexlistsize)
12 5 maiden
{
13
    orgfx_vector_font font;
14
    font.size = size;
15
    font.glyph = glyphlist;
16
    font.index_list_size = glyphindexlistsize;
17
    font.index_list = glyphindexlist;
18
    return font;
19
}
20
// takes all glyphs and generate a pointer list with correct index to all glyphs.
21
int orgfx_init_vector_font(orgfx_vector_font font)
22
{
23
    int i,j;
24
    // for all in the glyphindex.
25
 
26
    for(i=0; i<font.index_list_size; i++)
27
        font.index_list[i] = 0;
28
 
29
    for(i=0; i<font.size; i++)
30
    {
31
        // if character code is outside our glyph scope, return error
32
        if(font.glyph[i].index >= font.index_list_size)
33
            return 1;
34
 
35
        // match the glyph index with the ascii code i
36
        for(j=0; j<font.index_list_size; j++)
37
            if(j == font.glyph[i].index )
38
            {
39
                font.index_list[j] = &(font.glyph[i]);
40
                break;
41
            }
42
    }
43
    // all went well
44
    return 0;
45
}
46
 
47 8 Orka
void orgfx_put_vector_text(orgfx_vector_font* font,
48
                           orgfx_point3 offset,
49
                           orgfx_point3 scale,
50
                           orgfx_point3 rotation,
51
                           const wchar_t *str,
52
                           unsigned int color)
53 5 maiden
{
54 8 Orka
    int advance = 0;
55
    size_t cIndex = 0;
56 5 maiden
 
57
    orgfx_enable_tex0(0);
58
    orgfx_set_colors(color,color,color);
59 8 Orka
    orgfx_enable_transform(1);
60 5 maiden
 
61
    while(1)
62
    {
63 8 Orka
        wchar_t c = str[cIndex++];
64 5 maiden
        // Break if we reach the end of the string
65
        if(c == 0)
66
            break;
67
 
68 8 Orka
        // Set the transformation matrix
69
        orgfx_point3 glyph_offset = {advance,0,0};
70
        orgfx_matrix m = orgfx3d_identity();
71
 
72
        m = orgfx3d_rotateX(m, -2*rotation.x);
73
        m = orgfx3d_rotateY(m, -2*rotation.y);
74
        m = orgfx3d_rotateZ(m, -2*rotation.z);
75
        m = orgfx3d_translate(m, glyph_offset);
76
        m = orgfx3d_rotateX(m, rotation.x);
77
        m = orgfx3d_rotateY(m, rotation.y);
78
        m = orgfx3d_rotateZ(m, rotation.z);
79
        m = orgfx3d_scale(m, scale);
80
        m = orgfx3d_translate(m, offset);
81
        orgfx3d_set_matrix(m);
82
 
83 5 maiden
        if(c != ' ')
84 8 Orka
            orgfx_put_vector_char(font, c);
85 5 maiden
        else
86 8 Orka
            advance += 400;
87 5 maiden
 
88 8 Orka
        if(font->index_list[c])
89
            advance += font->index_list[c]->advance_x;
90 5 maiden
    }
91 8 Orka
    orgfx_enable_transform(0);
92 5 maiden
}
93
 
94 8 Orka
void orgfx_put_vector_char(orgfx_vector_font* font, wchar_t text)
95 5 maiden
{
96 8 Orka
    Glyph* glyph = font->index_list[text];
97
    if(glyph == 0)
98 5 maiden
        return;
99
    int i;
100
 
101 8 Orka
    for(i=0; i<glyph->triangle_n_writes; i++)
102 5 maiden
    {
103 8 Orka
        orgfx_triangle((glyph->triangle[i].p0.x)*FIXEDW,(glyph->triangle[i].p0.y)*FIXEDW,
104
                       (glyph->triangle[i].p1.x)*FIXEDW,(glyph->triangle[i].p1.y)*FIXEDW,
105
                       (glyph->triangle[i].p2.x)*FIXEDW,(glyph->triangle[i].p2.y)*FIXEDW,
106
                        1);
107 5 maiden
    }
108 8 Orka
    for(i=0; i<glyph->bezier_n_writes; i++)
109 5 maiden
    {
110 8 Orka
        orgfx_curve((glyph->bezier[i].start.x)  *FIXEDW, (glyph->bezier[i].start.y)  *FIXEDW,
111
                    (glyph->bezier[i].control.x)*FIXEDW, (glyph->bezier[i].control.y)*FIXEDW,
112
                    (glyph->bezier[i].end.x)    *FIXEDW, (glyph->bezier[i].end.y)    *FIXEDW,
113
                     glyph->bezier[i].fillInside);
114 5 maiden
    }
115
}

powered by: WebSVN 2.1.0

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