Skip to content

Commit 409ef86

Browse files
committed
Merge branch 'dev'
2 parents a4560a2 + 2d649e0 commit 409ef86

10 files changed

Lines changed: 56 additions & 26 deletions

File tree

Handwriting Generator/Font.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void Load(string path)
115115

116116
foreach (string folder in folders)
117117
{
118-
FChar key = (FChar)int.Parse(Path.GetFileName(folder));
118+
FChar key = (FChar)Enum.Parse(typeof(FChar), Path.GetFileName(folder));
119119
List<Bitmap> value = new List<Bitmap>();
120120
string[] imagePaths = Directory.GetFiles(folder);
121121
foreach (string imagePath in imagePaths)
@@ -169,10 +169,10 @@ public void Save(string path)
169169
foreach (KeyValuePair<FChar, List<Bitmap>> bitmaps in images)
170170
{
171171
int i = 0;
172-
Directory.CreateDirectory("TempFontStorage/" + (int)bitmaps.Key);
172+
Directory.CreateDirectory("TempFontStorage/" + bitmaps.Key.ToString());
173173
foreach (Bitmap image in bitmaps.Value)
174174
{
175-
image.Save("TempFontStorage/" + (int)bitmaps.Key + "/" + i.ToString() + ".png");
175+
image.Save("TempFontStorage/" + bitmaps.Key.ToString() + "/" + i.ToString() + ".png");
176176
i++;
177177
}
178178
}

Handwriting Generator/FontCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public FontCreator()
4848
FChar.rus_25,FChar.rus_26,FChar.rus_27,FChar.rus_28,FChar.rus_29,FChar.rus_30,FChar.rus_31,FChar.rus_32,
4949

5050
FChar.rus_33, FChar.dollar,FChar.ampersand,FChar.backslash,FChar.open_square_bracket,FChar.close_square_bracket,FChar.open_curly_bracket,FChar.close_curly_bracket,
51-
FChar.less_than,FChar.greater_than,FChar.percent,FChar.tilde,FChar.underscore,FChar.comma,FChar.empty,FChar.empty,
51+
FChar.less_than,FChar.greater_than,FChar.percent,FChar.tilde,FChar.underscore,FChar.comma,FChar.colon,FChar.empty,
5252
});
5353

5454
formTranslationTables.Add(new FChar[48]

Handwriting Generator/FormPreparer.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ public Bitmap CreatePrepared()
4444

4545
//get rid of lines. The value has been found exprementally
4646
BitmapUtils.ChangeBrightness(fixedOrientationForm, 1.1);
47-
fixedOrientationForm.Save("DebugOut/brightness.png");
4847
//fix under/overexposed images
4948
BitmapUtils.Autocontrast(fixedOrientationForm);
5049
Bitmap final = BitmapUtils.MakeGrayscale(fixedOrientationForm);
51-
final.Save("DebugOut/final.png");
5250
result = final;
5351

5452
return final;
@@ -227,9 +225,7 @@ private void PrepareData()
227225
private void CreateSmallExpandedBW(Bitmap smallForm)
228226
{
229227
smallBWForm = BitmapUtils.MakeBlackAndWhite(smallForm, BWThreshold);
230-
smallBWForm.Save("DebugOut/blackwhite.png");
231228
smallBWForm = BitmapUtils.ExpandWhite(smallBWForm);
232-
smallBWForm.Save("DebugOut/Expanded.png");
233229
}
234230

235231
/// <summary>
77 Bytes
Binary file not shown.

Handwriting Generator/Resources/newForm1.svg

Lines changed: 26 additions & 4 deletions
Loading

Handwriting Generator/TextConverter.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ namespace Handwriting_Generator
88
{
99
public class TextConverter
1010
{
11-
private class TranslationUnit
12-
{
13-
//Either original text or translated text should contain only one character
14-
public string originalText;
15-
public FChar translatedText;
16-
}
17-
1811
private bool converted = false;
1912

2013
private string origText;
@@ -104,6 +97,7 @@ private class TranslationUnit
10497
{ '(', FChar.open_parenthesis},
10598
{ ')', FChar.close_parenthesis},
10699
{ ';', FChar.semicolon},
100+
{ ':', FChar.colon},
107101
{ '@', FChar.email},
108102
{ '#', FChar.hash},
109103
{ '$', FChar.dollar},

Handwriting Generator/TextRenderer.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ private static Paragraph FillOneParagraph(List<FChar> text, int startPos, out in
146146
paragraph.centered = true;
147147

148148
startPos++;
149+
150+
if (startPos >= text.Count)
151+
break;
149152
}
150153
endPos = startPos - 1;
151154
for (int i = startPos; i < text.Count; i++)
@@ -208,6 +211,7 @@ private static List<RenderUnit> MakeLineRenderSequence(Paragraph text, Font font
208211

209212
if (generatedLine.Count > 0 && generatedLine.Last().rightBorderX >= lineWidth)
210213
{
214+
bool notFirstIteration = false;
211215
while (generatedLine.Last().rightBorderX >= lineWidth)
212216
{
213217
bool needsWrapping;
@@ -229,16 +233,21 @@ private static List<RenderUnit> MakeLineRenderSequence(Paragraph text, Font font
229233
int count = generatedLine.Count - breakPos - 1;
230234
generatedLine.RemoveRange(breakPos + 1, count);
231235
end -= count;
236+
if (notFirstIteration && needsWrapping)
237+
{
238+
end++;//compensate for prev. inserted minus
239+
}
232240

233241
int uselessX;
234242
if (needsWrapping)
235243
InsertRenderUnit(generatedLine, FChar.minus, random, generatedLine.Last().rightBorderX, out uselessX, font);
244+
notFirstIteration = true;
236245
}
237246
break;
238247
}
239248
}
240249

241-
if (text.centered)
250+
if (text.centered && generatedLine.Count > 0)
242251
{
243252
int rightDist = fullWidth - generatedLine.Last().rightBorderX;
244253
foreach (RenderUnit unit in generatedLine)
@@ -254,6 +263,18 @@ private static void InsertRenderUnit(List<RenderUnit> list, FChar character, Ran
254263
{
255264
RenderUnit unit = new RenderUnit();
256265

266+
if (!font.images.ContainsKey(character))
267+
{
268+
unit.x = x;
269+
unit.image = null;
270+
unit.corrCharacter = character;
271+
unit.rightBorderX = unit.x + (int)(0.3 * Font.pixelsPerCmH);
272+
list.Add(unit);
273+
274+
newX = x + (int)(0.3 * Font.pixelsPerCmV);
275+
return;
276+
}
277+
257278
int selectedImageIndex = random.Next(font.images[character].Count());
258279

259280
unit.x = (int)(x - font.leftMargins[character][selectedImageIndex] * Font.pixelsPerCmV);

Handwriting Generator/TextRenderingWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void Render(object sender, RoutedEventArgs e)
145145
string text = TextToRender.Text;
146146
TextConverter textConverter = new TextConverter(text);
147147
renderer = new TextRenderer(textConverter.Convert(), sheets, selectedFont);
148-
148+
curPreviewPage = 0;
149149
UpdatePreview();
150150
}
151151

Handwriting Generator/ToDoList.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
mind the possible exceptions
2-
copy instead of passing a reference
1+
copy instead of passing a reference
32
refactor constants
43
refactor cm/pixel usage
54
dispose bitmaps
65
make a separate cum hist function
76
move form data into a file
87
create debug mode (#define)
98

10-
fix crash on incorrect form order / findcoreregion should consider the situation where small russian characters are absent
11-
fix crash when \n is at the end of a text
12-
fix duplicate character which sometimes occur on line break
139
fix single consonant syllables at word ends
1410
fix single letter syllables

Handwriting Generator/fChar.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public enum FChar
8888
slash,
8989
open_parenthesis,
9090
close_parenthesis,
91+
colon,
9192
semicolon,
9293
email,
9394
hash,

0 commit comments

Comments
 (0)