Thread: Help understanding the openVG api (fonts)

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    5

    Exclamation Help understanding the openVG api (fonts)

    I've been using the OpenVG API (GitHub - ajstarks/openvg: Tools for exploring OpenVG) for a Raspberry Pi project i'm working on but i'm having trouble with adding new fonts.

    As on the documentation. I built the c source file. I linked it and included it and this is were the problem is. It appears to me that you declare a variable (Fontinfo) and the documentation forgot a ; to end. I tried this and i get a segmentation fault I remove the ; and I get a compiler error. Now i'm totally lost and have no idea what to do and i'm not the most experienced so if anyone can grant me some insight that would be great.
    Thank you!

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Your question is incomprehensible.
    What documentation?
    What C source file?
    What do you mean "linked it and include it"? C source files are not "included".
    What Fontinfo and semicolon?

  3. #3
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    yes, i'm sorry. I read that after the fact and now it sounds crazy but its hard to explain my problem without describing the whole library and im not the most knowledgeable but I'll attempt to make some sense.

    The library for openvg by ajstarks is the one i am using and is located at GitHub - ajstarks/openvg: Tools for exploring OpenVG.

    The documentation for installing new fonts is at the bottom of the git hub page (third section from the bottom) titled "Using fonts".

    starting from the top of the instructions, you are told to use a program provided called "font2openvg" witch essentially converts a .ttf file into a c source file witch only contains 8 different variables. The variables somehow combine to give you font data. This is where i believe the problem lies. The instructions say to include the created c source font file (DejaVuSans.inc) like a normal header file. then create a Fontinfo variable (At least i believe thats what he wants because he doesn't ad a semi colon to end the variable declaration... probably a mistake i just added on). one thing that bothers me is that this variable doesn't seam to be writing to, just created and read. the loadfont function mentioned after that doesn't provide much help.

    This is the instructions posted.
    Using fonts

    Also included is the font2openvg program, which turns font information into C source that you can embed in your program. The Makefile makes font code from files found in /usr/share/fonts/truetype/ttf-dejavu/. If you want to use other fonts, adjust the Makefile accordingly, or generate the font code on your own once the font2openvg program is built.
    font2openvg takes three arguments: the TrueType font file, the output file to be included and the prefix for identifiers. For example to use the DejaVu Sans font:

    Code:
    ./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans

    and include the generated code in your program:

    Code:
    #include "DejaVuSans.inc"
    Fontinfo DejaFont

    The loadfont function creates OpenVG paths from the font data:

    Code:
    loadfont(DejaVuSans_glyphPoints, 
            DejaVuSans_glyphPointIndices, 
            DejaVuSans_glyphInstructions,                
            DejaVuSans_glyphInstructionIndices, 
            DejaVuSans_glyphInstructionCounts, 
            DejaVuSans_glyphAdvances,
            DejaVuSans_characterMap, 
            DejaVuSans_glyphCount);
    The unloadfont function releases the path information:

    Code:
    unloadfont(DejaFont.Glyphs, DejaFont.Count);


    Note that the location of the font files may differ. (The current location for Jessie is /usr/share/fonts/truetype/ttf-dejavu) Use the FONTLIB makefile variable to adjust this location.
    this is also the code for what i believe is the Fontinfo variable.

    Code:
    #ifndef OPENVG_FONTINFO_H
    #define OPENVG_FONTINFO_H
    
    
    #if defined(__cplusplus)
    extern "C" {
    #endif
        typedef struct {
            const short *CharacterMap;
            const int *GlyphAdvances;
            int Count;
            int descender_height;
            int font_height;
            VGPath Glyphs[500];
        } Fontinfo;
    
    
        extern Fontinfo SansTypeface, SerifTypeface, MonoTypeface;
    
    
    #if defined(__cplusplus)
    }
    #endif                // OPENVG_FONTINFO_H
    #endif

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    That is an infinitely better description!

    So you're right about the missing semicolon and also about there being a problem with using it before you've set it to anything reasonable. It looks like the loadfont function needs to be called. In libshapes.c it's called like this for SansTypeface variable (of type Fontinfo, of course) :
    Code:
        SansTypeface = loadfont(
            DejaVuSans_glyphPoints,
            DejaVuSans_glyphPointIndices,
            DejaVuSans_glyphInstructions,
            DejaVuSans_glyphInstructionIndices,
            DejaVuSans_glyphInstructionCounts,
            DejaVuSans_glyphAdvances,
            DejaVuSans_characterMap,
            DejaVuSans_glyphCount);
        SansTypeface.descender_height = DejaVuSans_descender_height;
        SansTypeface.font_height = DejaVuSans_font_height;
    Note the two extra assignments after the loadfont call.

    So you need to do that for your font, basically just changing "DejaVuSans" to whatever identifier prefix your font has and "SansTypeface" with whatever variable name you want.
    Last edited by algorism; 12-01-2016 at 12:25 AM.

  5. #5
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    I did as you said and this is the result.

    Code:
    main: libshapes.c: 637: End: Assertion 'vgGetError() == VG_NO_ERROR' failed. 
    (program exited with code: 134)

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    I guess I don't understand what you're trying to do, and I can't see your program from here, so ....

    Can you get the client/hellovg.c program to work?

  7. #7
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    no you understand what i want but the errors are just so left field. I also thought i linked it at the top but i guess it didn't work so here it is.


    the function getkey(012) is my function of i.h. i made it to wait for a key press and return the key.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <linux/input.h>
    #include <i.h>
    #include "VG/openvg.h"
    #include "VG/vgu.h"
    #include "fontinfo.h"
    #include "shapes.h"
    #include "VG/Roboto.h"
    
    
    int main(){
    	
    	int w, h;
    	Fontinfo Roboto;
    	
    Roboto = loadfont(Roboto_glyphPoints, 
            Roboto_glyphPointIndices, 
            Roboto_glyphInstructions,                
            Roboto_glyphInstructionIndices, 
            Roboto_glyphInstructionCounts, 
            Roboto_glyphAdvances,
            Roboto_characterMap, 
            Roboto_glyphCount);
        Roboto.descender_height = Roboto_descender_height;
        Roboto.font_height = Roboto_font_height;
        
        initEvent();
         
        init(&w, &h);
        Start(w, h);
        Background(255,255,255);
        Fill(0,0,0,1);
        TextMid(300, 300, "Hello World", Roboto, 30);
        End();
        getKey(012);
        
        finish();
        
        
        exit(0);
    }

  8. #8
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    What's in Roboto.h? Shouldn't it be called Roboto.inc? Could you check that it has the actual data (C code) in it? In this case you actually are including C code, which is not the norm.

    Try commenting out "initEvent()" (whatever that is) and getKey(012). Replace getKey with:
    Code:
        char s[99];
        fgets(s, sizeof s, stdin);  // wait for Enter key

  9. #9
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    The initEvent() function finds the keyboard file in /dev/input/by-path for getKey() to use and get press events.

    I took your suggestion and it does work but i still get the same error. I'm starting looking though things for what i did wrong when making the file. I no longer believe that the problem is with my code. I think im using a wrong file (Roboto-regular.ttf). I'm thinking something about that file inst normal or compatible. im going to have to do a lot of work with building different files and hopefully i luck apon my problem. thanks for putting up with my incoherent messages.

    Im starting to get frustrated with
    chasing my tail.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to change color,fonts and fonts size on c ..?
    By C beginner2 in forum C Programming
    Replies: 1
    Last Post: 02-25-2011, 08:09 AM
  2. Fonts and SDL help
    By eaane74 in forum Game Programming
    Replies: 12
    Last Post: 09-09-2008, 08:07 PM
  3. Using fonts in C++
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 09-25-2005, 02:16 PM
  4. Fonts
    By PanzTec in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-23-2005, 09:47 PM
  5. Fonts
    By CheesyMoo in forum Game Programming
    Replies: 1
    Last Post: 04-18-2003, 10:07 AM

Tags for this Thread