~israeldahl/jwm-settings-manager/trunk

« back to all changes in this revision

Viewing changes to src/flFont.cpp

  • Committer: Israel Dahl
  • Date: 2014-09-04 13:00:08 UTC
  • Revision ID: israeldahl@gmail.com-20140904130008-zw7a5gv7hq3g6tnd
menu fixup code cleanup

* toriOSmenu
 - localized categories
 - added desktop directories files taken from xdg-menumaker
* flFont
 - some code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    //dtor
11
11
}
12
12
//Font NAME
 
13
std::string flFont::fontTest(const char* whichElement){
 
14
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
 
15
    std::string font ="";
 
16
    const char* fontTester = currentFont->GetText();
 
17
    if(fontTester!=NULL){
 
18
        font=fontTester;
 
19
        return font;
 
20
    }
 
21
    else {
 
22
        missingFont(whichElement);
 
23
    }
 
24
    return NULL;
 
25
}
 
26
void flFont::missingFont(const char* whichElement){
 
27
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
 
28
    std::cout<<"The current Element doesn't have a font name or is missing a size.\n Recovering by rewriting default values\n";
 
29
    currentFont->SetText("ubuntu-12:antialias=true");
 
30
    getFontName(whichElement);//Is this a good Idea??  Is there a case that can make this loop endlessly?
 
31
}
13
32
std::string flFont::getFontName(const char* whichElement){
14
 
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
15
 
    std::string font ="";
16
 
    const char* fontTester = currentFont->GetText();
17
 
    if(fontTester!=NULL){
18
 
        font=fontTester;
 
33
    std::string font =fontTest(whichElement);
 
34
    if (font.c_str() != NULL){
19
35
        std::string fontName ="";
20
36
        std::string::size_type size = font.find_first_of('-');
21
37
        if((font.find_last_of('-')!=std::string::npos)){
23
39
            //if (fontName !=NULL)
24
40
            return fontName;
25
41
        }
26
 
        }
27
 
        else{
28
 
            ///Need to check for the crazy fonts -*-courier-*-*-*-*-17-*-*-*-*-*-* stuff
29
 
        std::cout<<"The current Element doesn't have a font name or is missing a size.\n Recovering by rewriting default values\n";
30
 
        currentFont->SetText("ubuntu-12:antialias=true");
31
 
        getFontName(whichElement);//Is this a good Idea??  Is there a case that can make this loop endlessly?
 
42
    }
 
43
    else{
 
44
        std:: string error = "no font\n";
 
45
        std::cout<<"This is an error, there is "<< error;
 
46
        return error;
32
47
    }
33
48
    std::cout<<"ERROR in getFontName(const char*), this shouldn't happen\n";
34
49
    return "?";
37
52
void flFont::setFontName(const char* name, const char* whichElement){
38
53
    if(name==NULL){return;}
39
54
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
40
 
    std::string font ="";
41
 
    const char* fontTester = currentFont->GetText();
42
 
    if(fontTester!=NULL){
43
 
        font = fontTester;
 
55
    std::string font =fontTest(whichElement);
 
56
    if (font.c_str() != NULL){
44
57
        std::string fontName ="";
45
58
        std::string fontOptions ="";
46
59
        std::string::size_type size = font.find_first_of('-');
52
65
        }
53
66
        }
54
67
        else{
55
 
        std::cout<<"The current Element doesn't have a font name or is missing a size.\n Recovering by rewriting default values NOW\n";
56
 
        currentFont->SetText("ubuntu-12:antialias=true");
 
68
        missingFont(whichElement);
57
69
    }
58
70
    saveChangesTemp();
59
71
}
61
73
 
62
74
//Font SIZE
63
75
unsigned int flFont::getFontSize(const char* whichElement){
64
 
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
65
 
    std::string font="";
66
 
    const char* fontTester = currentFont->GetText();
67
 
    if(fontTester!=NULL){
68
 
        font=fontTester;
 
76
std::string font =fontTest(whichElement);
 
77
    if (font.c_str() != NULL){
69
78
        unsigned int fontSizeInt;
70
79
        std::string fontSize;
71
80
        std::string::size_type position = font.find(':');
78
87
        }
79
88
    }
80
89
    else{
81
 
        std::cout<<"The current Element doesn't have a font name or is missing a size.\n Recovering by rewriting default values NOW\n";
82
 
        currentFont->SetText("ubuntu-12:antialias=true");
 
90
        missingFont(whichElement);
83
91
        getFontSize(whichElement);
84
92
    }
85
93
    std::cout<<"getFontSize had an Error.... abort... size 42\n";
136
144
 
137
145
 
138
146
//AntiAlias
 
147
//This needs to be hooked into the UI eventually, as well as all the multitudes of options... I think I will apply advanced options to ALL fonts.
 
148
// I might also make a checkbox that sets all fonts the same if the user wants.
139
149
bool flFont::getAntialias(const char* whichElement){
140
 
    tinyxml2::XMLElement * currentFont = doc.FirstChildElement("JWM")->FirstChildElement(whichElement)->FirstChildElement("Font");
141
 
    std::string font = currentFont->GetText();
142
 
    bool alias = true;
143
 
    std::string A; //String antialias
144
 
    std::string::size_type antialias = font.find("antialias=");
145
 
    std::string::size_type position = font.find(':');
146
 
    if((font.find(':')!=std::string::npos)){
147
 
                if((font.find("antialias=")!=std::string::npos)){
148
 
                        /*antialias +10 is 10 characters after the beginning of the string
 
150
    std::string font =fontTest(whichElement);
 
151
    if (font.c_str() != NULL){
 
152
        std::string A; //String antialias
 
153
        std::string::size_type antialias = font.find("antialias=");
 
154
        std::string::size_type position = font.find(':');
 
155
        if((font.find(':')!=std::string::npos)){
 
156
            if((font.find("antialias=")!=std::string::npos)){
 
157
            /*antialias +10 is 10 characters after the beginning of the string
149
158
                         * "antialias=" is 10 characters long
150
159
                         */
151
 
                        A = font.substr (antialias+10,std::string::npos);
152
 
                        if (A=="true"){alias =true;}else{alias = false;}
 
160
                A = font.substr (antialias+10,std::string::npos);
 
161
                if (A=="true"){return true;}else{return false;}
153
162
                        //std::cout<<"Antialias = "<< A <<"\n";
154
 
                }
155
 
                else{alias=false;}
156
 
        }
157
 
        else{alias=false;}
158
 
 
159
 
        return alias;
 
163
            }
 
164
            else{return false;}
 
165
        }
 
166
        else{return false;}
 
167
    }
 
168
        return false;
160
169
}
161
170
 
162
171
/// Window STUFF
195
204
    FcPattern* font = fontSet->fonts[i];
196
205
    FcChar8 *family;
197
206
    if (FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch){
198
 
            printf("Font: %s\n", family);
 
207
            //printf("Font: %s\n", family);
199
208
            const char * fontName = reinterpret_cast<const char*>(family);
200
209
            o->add(fontName);
201
210
    }