~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to ddd/fonts.C

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2004-07-22 03:49:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040722034937-cysl08t1jvba4jrx
Tags: 1:3.3.9-3
USERINFO has been renamed to USERINFO.txt; adjust debian/rules code
to match, to get correct information on the About DDD dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: fonts.C,v 1.30 2001/01/09 18:15:22 zeller Exp $ -*- C++ -*-
 
1
// $Id$ -*- C++ -*-
2
2
// Setup DDD fonts
3
3
 
4
4
// Copyright (C) 1998 Technische Universitaet Braunschweig, Germany.
27
27
// or send a mail to the DDD developers <ddd@gnu.org>.
28
28
 
29
29
char fonts_rcsid[] = 
30
 
    "$Id: fonts.C,v 1.30 2001/01/09 18:15:22 zeller Exp $";
31
 
 
32
 
#ifdef __GNUG__
33
 
#pragma implementation
34
 
#endif
 
30
    "$Id$";
35
31
 
36
32
#include "fonts.h"
37
33
#include "charsets.h"
100
96
    while (n >= Foundry && (i = name.index('-', i + 1)) >= 0)
101
97
        n--;
102
98
 
103
 
    string w = "";
 
99
    string w;
104
100
    if (i >= 0)
105
101
    {
106
102
        w = name.after(i);
134
130
    }
135
131
 
136
132
    assert(0);
 
133
    ::abort();
137
134
    return "";                  // Never reached
138
135
}
139
136
 
155
152
    }
156
153
 
157
154
    assert(0);
 
155
    ::abort();
158
156
    return "";                  // Never reached
159
157
}
160
158
 
175
173
    }
176
174
 
177
175
    assert(0);
 
176
    ::abort();
178
177
    return "";                  // Never reached
179
178
}
180
179
 
208
207
    }
209
208
 
210
209
    string w = component(userfont(ad, font), n);
211
 
    if (w == "")                // nothing specified
 
210
    if (w.empty())              // nothing specified
212
211
        w = component(fallbackfont(font), n);
213
212
    return w;
214
213
}
222
221
static string override(FontComponent new_n, 
223
222
                       const string& new_value, const string& font = "")
224
223
{
225
 
    string new_font = "";
 
224
    string new_font;
226
225
    for (FontComponent n = Foundry; n <= AllComponents; n++)
227
226
    {
228
 
        string w;
229
 
        if (n == new_n)
230
 
            w = new_value;
231
 
        else
232
 
            w = component(font, n);
233
 
        new_font += "-" + w;
 
227
        new_font += '-';
 
228
        new_font +=
 
229
          (n == new_n) ?
 
230
          new_value :
 
231
          component(font, n);
234
232
    }
235
233
 
236
234
    return new_font;
238
236
 
239
237
string make_font(const AppData& ad, DDDFont base, const string& override)
240
238
{
241
 
    string font = "";
 
239
    string font;
242
240
    for (FontComponent n = Foundry; n <= AllComponents; n++)
243
241
    {
 
242
        font += '-';
244
243
        string w = component(override, n);
245
 
        if (w == "" || w == " ")
 
244
        if (w.empty() || w == " ")
246
245
            w = component(ad, base, n);
247
 
        font += "-" + w;
 
246
        font += w;
248
247
    }
249
248
 
250
249
#if 0
251
 
    clog << "make_font(" << font_type(base) << ", " << quote(override) 
252
 
         << ") = " << quote(font) << "\n";
 
250
    std::clog << "make_font(" << font_type(base) << ", " << quote(override) 
 
251
              << ") = " << quote(font) << "\n";
253
252
#endif
254
253
 
255
254
    return font;
274
273
 
275
274
    if (ad.show_fonts)
276
275
    {
277
 
        string sym;
278
 
        if (name == MSTRING_DEFAULT_CHARSET)
279
 
            sym = "default";
280
 
        else
281
 
            sym = "@" + name;
282
 
        cout << sym << "\t" << font << "\n";
 
276
        const string sym =
 
277
          (name == MSTRING_DEFAULT_CHARSET) ?
 
278
          "default" :
 
279
          "@" + name;
 
280
        std::cout << sym << "\t" << font << "\n";
283
281
    }
284
282
}
285
283
 
293
291
        string s = line;
294
292
        s.gsub(":", ": \\\n   ");
295
293
        s.gsub(",", ",\\\n    ");
296
 
        cout << s << "\n\n";
 
294
        std::cout << s << "\n\n";
297
295
    }
298
296
}
299
297
 
300
298
static string define_default_font(const string& font_def)
301
299
{
302
 
    string s = "";
 
300
    string s;
303
301
 
304
302
    // The canonical way of doing it.
305
303
    s += font_def + "=" + MSTRING_DEFAULT_CHARSET + ",";
309
307
    {
310
308
        // This happens in Motif 1.1 and LessTif.  Ensure
311
309
        // compatibility with other Motif versions.
312
 
        s += font_def + "=charset,";
 
310
        s += font_def;
 
311
        s += "=charset,";
313
312
    }
314
313
 
315
314
    return s;
373
372
    static bool title_seen = false;
374
373
 
375
374
    if (title_seen)
376
 
        cout << "\n\n";
 
375
        std::cout << "\n\n";
377
376
 
378
 
    cout << s << "\n" << replicate(string("-"), s.length()) << "\n\n";
 
377
    std::cout << s << "\n" << replicate('-', s.length()) << "\n\n";
379
378
 
380
379
    title_seen = true;
381
380
}
471
470
//-----------------------------------------------------------------------------
472
471
 
473
472
static void replace_vsl_font(string& defs, const string& func, 
474
 
                             AppData& ad, const string& override = "",
 
473
                             const AppData& ad, const string& override = "",
475
474
                             DDDFont font = DataDDDFont)
476
475
{
477
476
    string fontname = quote(make_font(ad, font, override));
531
530
                     VariableWidthDDDFont);
532
531
 
533
532
    if (ad.show_fonts)
534
 
        cout << defs;
 
533
        std::cout << defs;
535
534
 
536
535
    defs += ad.vsl_base_defs;
537
536
    ad.vsl_base_defs = defs.chars();
556
555
static string simplify_font(const AppData& ad, DDDFont font, 
557
556
                            const string& source)
558
557
{
559
 
    string s = "";
 
558
    string s;
560
559
 
561
560
    for (FontComponent n = AllComponents; n >= Foundry; n--)
562
561
    {
563
562
        string c = component(source, n);
564
 
        if (s == "" && c == component(ad, font, n))
 
563
        if (s.empty() && c == component(ad, font, n))
565
564
        {
566
565
            // Default setting -- ignore
567
566
        }
574
573
    if (s.contains("-*-", 0))
575
574
        s = s.after("-*-");
576
575
 
577
 
    if (s == "")
 
576
    if (s.empty())
578
577
        s = component(ad, font, Family);
579
 
    if (!s.contains('-'))
580
 
        s += "-" + component(ad, font, Weight);
 
578
    if (!s.contains('-')) {
 
579
        s += '-';
 
580
        s += component(ad, font, Weight);
 
581
    }
581
582
 
582
583
#if 0
583
 
    clog << "simplify_font(" << font_type(font) << ", " 
584
 
         << quote(source) << ") = " << quote(s) << "\n";
 
584
    std::clog << "simplify_font(" << font_type(font) << ", " 
 
585
              << quote(source) << ") = " << quote(s) << "\n";
585
586
#endif
586
587
 
587
588
    return s;
622
623
    }
623
624
    default:
624
625
        assert(0);
 
626
        ::abort();
625
627
    }
626
628
}
627
629
 
628
630
// Set a new font resource
629
 
void set_font_size(DDDFont font, int size)
 
631
static void set_font_size(DDDFont font, int size)
630
632
{
631
633
    switch (font)
632
634
    {
644
646
        break;
645
647
    default:
646
648
        assert(0);
 
649
        ::abort();
647
650
    }
648
651
}
649
652
 
697
700
        set_status(output_buffer.before('\n'));
698
701
        output_buffer = output_buffer.after('\n');
699
702
    }
700
 
    if (output_buffer != "")
 
703
    if (!output_buffer.empty())
701
704
        set_status(output_buffer);
702
705
}
703
706
 
713
716
    // Destroy the text
714
717
    DestroyWhenIdle(info->text);
715
718
 
716
 
    if (output_buffer != "")
 
719
    if (!output_buffer.empty())
717
720
        set_status("");
718
721
}
719
722
 
784
787
        process_font(info->font, s);
785
788
    }
786
789
 
787
 
    XmTextSetString(w, CONST_CAST(char*,s.chars()));
 
790
    XmTextSetString(w, XMST(s.chars()));
788
791
 
789
792
    // Get the selection again.
790
793
    // This will fail if we have multiple font selectors (FIXME).
825
828
 
826
829
    // Create a TextField to fetch the selection
827
830
    FontSelectInfo *info = new FontSelectInfo;
828
 
    info->text = XmCreateText(XtParent(w), CONST_CAST(char *,"text"), 0, 0);
 
831
    info->text = XmCreateText(XtParent(w), XMST("text"), 0, 0);
829
832
    info->font = font;
830
833
 
831
834
    XtRealizeWidget(info->text);
832
835
 
833
836
    const string text = "dummy";
834
 
    XmTextSetString(info->text, CONST_CAST(char*,text.chars()));
 
837
    XmTextSetString(info->text, XMST(text.chars()));
835
838
    TextSetSelection(info->text, 0, text.length(), tm);
836
839
    XtAddCallback(info->text, XmNlosePrimaryCallback, 
837
840
                  SelectionLostCB, XtPointer(info));