-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomFont.java
94 lines (81 loc) · 3.34 KB
/
CustomFont.java
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
package postCard;
import java.io.*;
import java.util.regex.*;
import java.util.ArrayList;
/**
* Created by aabzel on 27.01.2018.
*/
public class CustomFont {
// Font number
int fontNum;
int amountOfchars;
// list of chars
ArrayList<CharFigure> listOffigures;
CustomFont(int inFontNum){
amountOfchars=0;
fontNum = inFontNum;
listOffigures = new ArrayList<CharFigure>();
listOffigures.clear();
// init empty list of chars
}
void load_font(String fontNumber) {
System.setProperty("console.encoding","utf-8");
// count the ammount line in file
amountOfchars = 0;
System.out.println("Load indents.");
String inPutFileAdderss = "C:\\!!docs\\1_my_prj\\1_plotter\\3_Fonts\\" + fontNumber + "_vectorFonts\\indents.txt";
String lineStr;
try {
System.setProperty("console.encoding","utf-8");
BufferedReader readerIndents = new BufferedReader(new FileReader(inPutFileAdderss));
do {
lineStr = readerIndents.readLine();
if (null != lineStr) {
amountOfchars++;
System.out.println(lineStr);
// add a char to list
Pattern p = Pattern.compile("\\'.?\\'");
Matcher m = p.matcher(lineStr);
String symbol="0" , indent="0.0";
if(m.find()) {
symbol = m.group().subSequence(1, m.group().length() - 1).toString();
System.out.println("char: "+"<" +symbol.charAt(0) + ">");
} else {
System.out.println("lack of data char");
}
Pattern pDouble = Pattern.compile(" [+-]?(\\d+([.]\\d*)?|[.]\\d+)");
Matcher mDouble = pDouble.matcher(lineStr);
if(mDouble.find()) {
indent = mDouble.group().subSequence(1, mDouble.group().length() ).toString();
System.out.println("intend: "+"<"+ indent+">" );
}else {
System.out.println("lack of data indent");
}
// add to list
CharFigure figuCh = new CharFigure();
figuCh.setChar(Integer.parseInt(fontNumber),
symbol.charAt(0),
Double.parseDouble(indent)
);
listOffigures.add(figuCh);
}
} while (null != lineStr);
readerIndents.close();
} catch(IOException e) {
System.out.println("\n\nError to load indents!");
}
System.out.println("Amount of chars in font: "+amountOfchars +" "+listOffigures.size());
//System.out.println( "d indent: "+calcInterval('d') );
//System.out.println( "й indent: "+calcInterval('й') );
}
public Double calcInterval(char inChar){
System.setProperty("console.encoding","utf-8");
for(int i=0; i<listOffigures.size() ; i++){
if(inChar == listOffigures.get(i).symbol){
return listOffigures.get(i).indent;
}
}
System.out.println( "\n Error Lack of indent for " + inChar );
return 0.0;
}
}