Skip to content

Commit

Permalink
[16_7] bin/format on src/Graphics/Fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Nov 30, 2023
1 parent 508ed87 commit 67dc8ad
Show file tree
Hide file tree
Showing 34 changed files with 3,993 additions and 4,159 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/clang-format-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
- 'src/Data/Scheme/**.cpp'
- 'src/Scheme/**.cpp'
- 'src/Scheme/**.hpp'
- 'src/Graphics/Fonts/**.hpp'
- 'src/Graphics/Fonts/**.cpp'
- 'src/Graphics/Types/**.hpp'
- 'src/Graphics/Types/**.cpp'
- 'src/Typeset/Boxes/Graphics/**.cpp'
- 'src/Plugins/Pdf/**.cpp'
Expand Down
2 changes: 2 additions & 0 deletions bin/format
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ clang-format -i src/Data/Scheme/**.hpp
clang-format -i src/Data/Scheme/**.cpp
clang-format -i src/Scheme/**.cpp
clang-format -i src/Scheme/**.hpp
clang-format -i src/Graphics/Fonts/**.cpp
clang-format -i src/Graphics/Fonts/**.hpp
clang-format -i src/Graphics/Types/**.cpp
clang-format -i src/Graphics/Types/**.hpp
clang-format -i src/Typeset/Boxes/Graphics/**.cpp
Expand Down
175 changes: 97 additions & 78 deletions src/Graphics/Fonts/charmap.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@

/******************************************************************************
* MODULE : charmap.cpp
* DESCRIPTION: character maps for agglomerated fonts
* COPYRIGHT : (C) 2005 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/
* MODULE : charmap.cpp
* DESCRIPTION: character maps for agglomerated fonts
* COPYRIGHT : (C) 2005 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#include "charmap.hpp"
#include "translator.hpp"
#include "analyze.hpp"
#include "translator.hpp"

RESOURCE_CODE(charmap);
RESOURCE_CODE (charmap);

/******************************************************************************
* The charmap structure for finding the physical font
******************************************************************************/

charmap_rep::charmap_rep (string name):
rep<charmap> (name), slow_map (-1), slow_subst ("")
{
int ch; string r;
for (int i=0; i<256; i++)
* The charmap structure for finding the physical font
******************************************************************************/

charmap_rep::charmap_rep (string name)
: rep<charmap> (name), slow_map (-1), slow_subst ("") {
int ch;
string r;
for (int i= 0; i < 256; i++)
if (((char) i) == '<' || ((char) i) == '>') fast_map[i]= -1;
else {
string s ((unsigned char) i);
lookup (s, ch, r);
fast_map[i]= (r == s? ch: -1);
fast_map[i]= (r == s ? ch : -1);
}
}

void
charmap_rep::advance (string s, int& pos, string& r, int& ch) {
int n= N(s), start= pos;
int n= N (s), start= pos;
if (s[pos] != '<') {
ch= fast_map [(unsigned char) s[pos++]];
while (pos<n && s[pos] != '<' &&
fast_map [(unsigned char) s[pos]] == ch) pos++;
ch= fast_map[(unsigned char) s[pos++]];
while (pos < n && s[pos] != '<' && fast_map[(unsigned char) s[pos]] == ch)
pos++;
r= s (start, pos);
if (pos == n || s[pos] != '<') return;
}
Expand All @@ -47,61 +47,75 @@ charmap_rep::advance (string s, int& pos, string& r, int& ch) {
tm_char_forwards (s, pos);
cached_lookup (s (start, pos), ch, r);
}
int ch2; string r2;
while (pos<n) {
int ch2;
string r2;
while (pos < n) {
int start= pos;
tm_char_forwards (s, pos);
cached_lookup (s (start, pos), ch2, r2);
if (ch2 != ch) { pos= start; break; }
if (ch2 != ch) {
pos= start;
break;
}
else r << r2;
}
}

charmap
any_charmap () {
if (charmap::instances -> contains ("any"))
return charmap ("any");
if (charmap::instances->contains ("any")) return charmap ("any");
return make (charmap, "any", tm_new<charmap_rep> ("any"));
}

/******************************************************************************
* Explicit charmaps
******************************************************************************/
* Explicit charmaps
******************************************************************************/

struct ec_charmap_rep: public charmap_rep {
ec_charmap_rep (): charmap_rep ("ec") {}
struct ec_charmap_rep : public charmap_rep {
ec_charmap_rep () : charmap_rep ("ec") {}
void lookup (string s, int& ch, string& r) {
if (N(s) == 1 || s == "<less>" || s == "<gtr>") { ch= 0; r= s; }
else { ch= -1; r= ""; }
if (N (s) == 1 || s == "<less>" || s == "<gtr>") {
ch= 0;
r = s;
}
else {
ch= -1;
r = "";
}
}
};

charmap
ec_charmap () {
if (charmap::instances -> contains ("ec"))
return charmap ("ec");
if (charmap::instances->contains ("ec")) return charmap ("ec");
return make (charmap, "ec", tm_new<ec_charmap_rep> ());
}

struct range_charmap_rep: public charmap_rep {
struct range_charmap_rep : public charmap_rep {
int start, end;
range_charmap_rep (int start2, int end2):
charmap_rep (as_hexadecimal (start2) * "--" * as_hexadecimal (end2)),
start (start2), end (end2) {}
range_charmap_rep (int start2, int end2)
: charmap_rep (as_hexadecimal (start2) * "--" * as_hexadecimal (end2)),
start (start2), end (end2) {}
inline bool between (int what, int begin, int end) {
return what >= begin && what <= end;
}
void lookup (string s, int& ch, string& r) {
if (N(s) >= 3 && s[0] == '<' && s[1] == '#' && s[N(s)-1] == '>' &&
between (from_hexadecimal (s (2, N(s)-1)), start, end)) { ch=0; r=s; }
else { ch= -1; r= ""; }
if (N (s) >= 3 && s[0] == '<' && s[1] == '#' && s[N (s) - 1] == '>' &&
between (from_hexadecimal (s (2, N (s) - 1)), start, end)) {
ch= 0;
r = s;
}
else {
ch= -1;
r = "";
}
}
};

charmap
range_charmap (int start, int end) {
string name= as_hexadecimal (start) * "--" * as_hexadecimal (end);
if (charmap::instances -> contains (name)) return charmap (name);
if (charmap::instances->contains (name)) return charmap (name);
return make (charmap, name, tm_new<range_charmap_rep> (start, end));
}

Expand All @@ -120,89 +134,94 @@ oriental_charmap () {
return range_charmap (0x3000, 0xffff);
}

struct explicit_charmap_rep: public charmap_rep {
struct explicit_charmap_rep : public charmap_rep {
translator trl;
explicit_charmap_rep (string name):
charmap_rep (name), trl (load_translator (name)) {}
explicit_charmap_rep (string name)
: charmap_rep (name), trl (load_translator (name)) {}
void lookup (string s, int& ch, string& r) {
if (trl->dict->contains (s)) { ch= 0; r= string ((char) trl->dict[s]); }
else { ch= -1; r= ""; }
if (trl->dict->contains (s)) {
ch= 0;
r = string ((char) trl->dict[s]);
}
else {
ch= -1;
r = "";
}
}
};

charmap
explicit_charmap (string name) {
if (charmap::instances -> contains (name))
return charmap (name);
if (charmap::instances->contains (name)) return charmap (name);
return make (charmap, name, tm_new<explicit_charmap_rep> (name));
}

/******************************************************************************
* Joined charmaps
******************************************************************************/
* Joined charmaps
******************************************************************************/

string
join_name (charmap* a, int n) {
string acc= copy (a[0]->res_name);
for (int i=1; i<n; i++)
for (int i= 1; i < n; i++)
acc << ":" << a[i]->res_name;
return acc;
}

struct join_charmap_rep: public charmap_rep {
struct join_charmap_rep : public charmap_rep {
charmap* ja;
int jn;
join_charmap_rep (charmap* a, int n):
charmap_rep (join_name (a, n)), ja (a), jn (n) {}
join_charmap_rep (charmap* a, int n)
: charmap_rep (join_name (a, n)), ja (a), jn (n) {}
int arity () {
int i, sum= 0;
for (i=0; i<jn; i++)
sum += ja[i] -> arity ();
for (i= 0; i < jn; i++)
sum+= ja[i]->arity ();
return sum;
}
charmap child (int ch) {
int i, sum= 0;
for (i=0; i<jn; i++) {
int p= ja[i] -> arity ();
if (ch >= sum && ch < sum+p) return ja[i] -> child (i-sum);
sum += p;
for (i= 0; i < jn; i++) {
int p= ja[i]->arity ();
if (ch >= sum && ch < sum + p) return ja[i]->child (i - sum);
sum+= p;
}
TM_FAILED ("bad child");
return this;
}
void lookup (string s, int& ch, string& r) {
int i, sum= 0;
for (i=0; i<jn; i++) {
for (i= 0; i < jn; i++) {
ja[i]->lookup (s, ch, r);
//cout << i << "\t" << s << " -> " << ch << ", " << r << "\n";
// cout << i << "\t" << s << " -> " << ch << ", " << r << "\n";
if (ch >= 0) {
ch += sum;
return;
ch+= sum;
return;
}
sum += ja[i] -> arity ();
sum+= ja[i]->arity ();
}
ch= -1; r= "";
}
ch= -1;
r = "";
}
};

charmap
join_charmap (charmap* a, int n) {
string name= join_name (a, n);
if (charmap::instances -> contains (name))
return charmap (name);
if (charmap::instances->contains (name)) return charmap (name);
return make (charmap, name, tm_new<join_charmap_rep> (a, n));
}

/******************************************************************************
* High level interface
******************************************************************************/
* High level interface
******************************************************************************/

charmap
load_charmap (tree def) {
int i, n= N (def);
int i, n= N (def);
charmap* a= tm_new_array<charmap> (n);
for (i=0; i<n; i++) {
//cout << i << "\t" << def[i] << "\n";
for (i= 0; i < n; i++) {
// cout << i << "\t" << def[i] << "\n";
if (def[i] == "any") a[i]= any_charmap ();
else if (def[i] == "ec") a[i]= ec_charmap ();
else if (def[i] == "hangul") a[i]= hangul_charmap ();
Expand Down
42 changes: 23 additions & 19 deletions src/Graphics/Fonts/charmap.hpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@

/******************************************************************************
* MODULE : charmap.hpp
* DESCRIPTION: character maps for compound fonts
* COPYRIGHT : (C) 2005 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/
* MODULE : charmap.hpp
* DESCRIPTION: character maps for compound fonts
* COPYRIGHT : (C) 2005 Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#ifndef CHARMAP_H
#define CHARMAP_H

#include "resource.hpp"
#include "tree.hpp"

RESOURCE(charmap);
RESOURCE (charmap);

/******************************************************************************
* The charmap structure for finding the physical font
******************************************************************************/
* The charmap structure for finding the physical font
******************************************************************************/

struct charmap_rep: rep<charmap> {
int fast_map[256];
hashmap<string,int> slow_map;
hashmap<string,string> slow_subst;
struct charmap_rep : rep<charmap> {
int fast_map[256];
hashmap<string, int> slow_map;
hashmap<string, string> slow_subst;

public:
charmap_rep (string name);

inline virtual int arity () { return 1; }
inline virtual int arity () { return 1; }
inline virtual charmap child (int i) {
ASSERT (i == 0, "bad child");
return this; }
inline virtual void lookup (string s, int& ch, string& r) { ch= 0; r= s; }
return this;
}
inline virtual void lookup (string s, int& ch, string& r) {
ch= 0;
r = s;
}
inline void cached_lookup (string s, int& ch, string& r) {
if (!slow_map->contains (s)) lookup (s, slow_map (s), slow_subst (s));
ch= slow_map (s);
ch= slow_map (s);
r = slow_subst (s);
}

Expand Down
Loading

0 comments on commit 67dc8ad

Please sign in to comment.