[go: up one dir, main page]

File: fontspec.cpp

package info (click to toggle)
coin3 3.1.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 48,344 kB
  • ctags: 70,042
  • sloc: cpp: 314,328; ansic: 15,927; sh: 13,635; makefile: 8,780; perl: 2,149; lex: 1,302; lisp: 1,247; yacc: 184; xml: 175; sed: 68
file content (128 lines) | stat: -rw-r--r-- 3,845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**************************************************************************\
 *
 *  This file is part of the Coin 3D visualization library.
 *  Copyright (C) by Kongsberg Oil & Gas Technologies.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  ("GPL") version 2 as published by the Free Software Foundation.
 *  See the file LICENSE.GPL at the root directory of this source
 *  distribution for additional information about the GNU GPL.
 *
 *  For using Coin with software that can not be combined with the GNU
 *  GPL, and for taking advantage of the additional benefits of our
 *  support services, please contact Kongsberg Oil & Gas Technologies
 *  about acquiring a Coin Professional Edition License.
 *
 *  See http://www.coin3d.org/ for more information.
 *
 *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
 *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
 *
\**************************************************************************/

#include "fonts/fontspec.h"

#include <string.h>

#include "glue/freetype.h"

void
cc_fontspec_construct(cc_font_specification * spec,
                      const char * name_style, float size, float complexity)
{
  const char * tmpstr, * tmpptr;

  spec->size = size;
  spec->complexity = complexity;

  cc_string_construct(&spec->name);
  cc_string_set_text(&spec->name, name_style);

  cc_string_construct(&spec->style);

  /* handle the previously allowed ':Bold Italic' case for fontconfig */
  /* FIXME: this is an ugly non robust workaround. it would be better
     to agree on an abstract fontname matching schema that is then
     consistently applied upon all font backend
     implementations. 20040929 tamer. */
  if (cc_fcglue_available()) {
    tmpstr = cc_string_get_text(&spec->name);

    if ((tmpptr = strchr(tmpstr, ':'))) {
      char * tmpptrspace;
      if ((tmpptrspace = (char *) strchr(tmpptr, ' '))) {
        *tmpptrspace = ':';
      }
    }

    return;
  }

  /* Check if style is included in the fontname using the
     "family:style" syntax. */
  tmpstr = cc_string_get_text(&spec->name);
  if ((tmpptr = strchr(tmpstr, ':'))) {
    const int pos = (int)(tmpptr - tmpstr);
    const int namelen = cc_string_length(&spec->name);

    int trimstyleend, trimnamestart;
    int trimposstyle = pos + 1;
    int trimposname = pos - 1;

    while (tmpstr[trimposstyle] == ' ') {
      ++trimposstyle;
    }

    while (tmpstr[trimposname] == ' ') {
      --trimposname;
    }

    cc_string_set_text(&spec->style, cc_string_get_text(&spec->name));
    cc_string_remove_substring(&spec->style, 0, trimposstyle - 1);
    cc_string_remove_substring(&spec->name, trimposname + 1, namelen-1);

    trimstyleend = cc_string_length(&spec->style);
    trimposstyle = trimstyleend;
    tmpstr = cc_string_get_text(&spec->style);

    while (tmpstr[trimstyleend-1] == ' ') {
      --trimstyleend;
    }

    if(trimstyleend !=  trimposstyle) {
      cc_string_remove_substring(&spec->style, trimstyleend, cc_string_length(&spec->style) - 1);
    }

    tmpstr = cc_string_get_text(&spec->name);
    trimnamestart = 0;
    while (tmpstr[trimnamestart] == ' ') {
      ++trimnamestart;
    }

    if (trimnamestart != 0) {
      cc_string_remove_substring(&spec->name, 0, trimnamestart-1);
    }

  }
}

void
cc_fontspec_copy(const cc_font_specification * from,
                 cc_font_specification * to)
{
  to->size = from->size;
  to->complexity = from->complexity;

  cc_string_construct(&to->name);
  cc_string_set_string(&to->name, &from->name);
  cc_string_construct(&to->style);
  cc_string_set_string(&to->style, &from->style);
}

void
cc_fontspec_clean(cc_font_specification * spec)
{
  cc_string_clean(&spec->name);
  cc_string_clean(&spec->style);
}