Skip to content

Commit

Permalink
user Preference setting added
Browse files Browse the repository at this point in the history
  • Loading branch information
KumnegerH committed Nov 17, 2019
1 parent a632c2b commit b624a3f
Show file tree
Hide file tree
Showing 11 changed files with 1,132 additions and 61 deletions.
26 changes: 19 additions & 7 deletions AmhOCR/AboutPage.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 91 additions & 22 deletions AmhOCR/Controls/ImageEditControl.vb
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,21 @@ Public Class ImageEditControl
Dim hocrword As HocrWord = parag.HocrObject
hocrword.SpellChecked = True
parag.HocrObject = hocrword


End If
Else
parag.Spelled = True
End If

If SpellCheker.UserWords.Count > 0 AndAlso parag.Spelled = True AndAlso parag.isUserText = False Then
Dim txt = parag.text.Trim(" ")

If SpellCheker.UserWords.Contains(txt) Then
parag.isUserText = True
End If

End If

HotHocrObjects(parcnt) = parag

Expand Down Expand Up @@ -367,7 +377,7 @@ Public Class ImageEditControl
HocrParEditor.isinEdit = False

HocrParEditor.Spelled = True

HocrParEditor.isUserText = False
HocrParEditor.alignment = Pars(pr).Alignment
HocrParEditor.Font = Pars(pr).Font

Expand Down Expand Up @@ -660,7 +670,7 @@ Public Class ImageEditControl
End If

Else
If HotParagraph.HocrObject.SpellChecked = False Then
If HotParagraph.Spelled = False Then

Dim txt = HotParagraph.text.Trim(" ".ToArray)

Expand All @@ -676,14 +686,41 @@ Public Class ImageEditControl
ocrword.SpellChecked = True
HotParagraph.HocrObject = ocrword
HotParagraph.Spelled = True

HotParagraph.isUserText = True
End If

End If

Else
Dim txt = HotParagraph.text.Trim(" ")
If SpellCheker.UserWords.Contains(txt) AndAlso Not String.IsNullOrEmpty(SpellCheker._UserPath) Then

Try

Dim Userwrds = SpellCheker.UserWords.ToList
Userwrds.Remove(txt)
SpellCheker.UserWords = Userwrds.ToArray
IO.File.WriteAllLines(SpellCheker._UserPath, SpellCheker.UserWords)
Userwrds = SpellCheker.Words.ToList
Userwrds.Remove(txt)
SpellCheker.Words = Userwrds.ToArray
HotParagraph.isUserText = False
HotParagraph.Spelled = False
Dim ocrword As HocrWord = HotParagraph.HocrObject
ocrword.SpellChecked = False
HotParagraph.HocrObject = ocrword

Catch ex As Exception

End Try

End If

End If




End If


Expand All @@ -703,25 +740,28 @@ Public Class ImageEditControl
If ContextParaId >= 0 Then

Dim HotParagraph = HotHocrObjects(ContextParaId)
Dim txt = HotParagraph.text.Trim(" ".ToArray)

If txt.Length > 0 Then
Dim wrds = txt.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
wrds = wrds.Where(Function(X) Not SpellCheker.UserWords.Contains(X)).ToArray
If HotParagraph.Spelled = False Then

If wrds.Count > 0 Then
SpellCheker.UserWords = SpellCheker.UserWords.Union(wrds).ToArray
SpellCheker.Words = SpellCheker.Words.Union(wrds).ToArray
Dim txt = HotParagraph.text.Trim(" ".ToArray)

Dim ocrword As HocrWord = HotParagraph.HocrObject
ocrword.SpellChecked = True
HotParagraph.HocrObject = ocrword
If txt.Length > 0 Then
Dim wrds = txt.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
wrds = wrds.Where(Function(X) Not SpellCheker.Words.Contains(X)).ToArray

If wrds.Count > 0 Then

End If
SpellCheker.Words = SpellCheker.Words.Union(wrds).ToArray

End If

End If
End If


Dim ocrword As HocrWord = HotParagraph.HocrObject
ocrword.SpellChecked = True
HotParagraph.HocrObject = ocrword
HotParagraph.Spelled = True
HotHocrObjects(ContextParaId) = HotParagraph
Invalidate()
Expand Down Expand Up @@ -901,8 +941,11 @@ Public Class ImageEditControl
State = controlState.None
Else
GroupSelectionList.Clear()
LockContext.Enabled = True

If HotHocrObjects(HighlightedHocrID).EditMode = ocrEditMode.PageEdit Then


If HotHocrObjects(HighlightedHocrID).isLocked = False Then
For Each stripi In MenuStripHocrOptions.Items
stripi.Enabled = True
Expand All @@ -929,10 +972,14 @@ Public Class ImageEditControl

LockContext.Text = "Add to User Dictionary "

If HotHocrObjects(HighlightedHocrID).Spelled = False Then
LockContext.Checked = False
Else
If HotHocrObjects(HighlightedHocrID).Spelled Then
LockContext.Checked = True
If HotHocrObjects(HighlightedHocrID).isUserText = True Then
LockContext.Text = "Remove From User Dictionary "
Else
LockContext.Enabled = False
End If

End If

End If
Expand Down Expand Up @@ -1197,6 +1244,9 @@ Public Class ImageEditControl
Dim penselected = New Pen(Color.LimeGreen, 2 / _zoom)
Dim penHighlit = New Pen(Color.Red, 2 / _zoom)

Dim userSpellBrush As New Pen(OCRsettings.UserSpelledColor, 1)
Dim errorBrush As New Pen(OCRsettings.SpellErrorColor, 1)

For pr As Integer = 0 To OCRblocks.Count - 1 Step 1
e.Graphics.FillRectangle(Brushes.White, OCRblocks(pr))
Next
Expand All @@ -1211,10 +1261,17 @@ Public Class ImageEditControl
Dim parag = HotHocrObjects(pr)

If HotHocrObjects(pr).Spelled = True Then
e.Graphics.DrawString(parag.text, HotHocrObjects(pr).Font, Brushes.Black, parag.bbox.Location, DifStringFormat)
If HotHocrObjects(pr).isUserText Then

e.Graphics.DrawString(parag.text, HotHocrObjects(pr).Font, userSpellBrush.Brush, parag.bbox.Location, DifStringFormat)
Else
e.Graphics.DrawString(parag.text, HotHocrObjects(pr).Font, Brushes.Black, parag.bbox.Location, DifStringFormat)
End If


Else

e.Graphics.DrawString(parag.text, HotHocrObjects(pr).Font, Brushes.Red, parag.bbox.Location, DifStringFormat)
e.Graphics.DrawString(parag.text, HotHocrObjects(pr).Font, errorBrush.Brush, parag.bbox.Location, DifStringFormat)
End If

If (pr = HighlightedHocrID) Then
Expand Down Expand Up @@ -1583,9 +1640,7 @@ Public Class ImageEditControl
HotParagraph.isDirty = True
End If

If OCRsettings.EditMode = ocrEditMode.WordEdit Then
HotParagraph.Spelled = SpellCheker.isValidWord(HotParagraph.text)
End If

End If

If HotParagraph.isDirty = True Then
Expand All @@ -1611,13 +1666,27 @@ Public Class ImageEditControl
End If
End If

If OCRsettings.EditMode = ocrEditMode.WordEdit Then
HotParagraph.Spelled = SpellCheker.isValidWord(HotParagraph.text)
HotParagraph.isUserText = False

If SpellCheker.UserWords.Count > 0 AndAlso HotParagraph.Spelled = True Then
Dim txt = HotParagraph.text.Trim(" ")

If SpellCheker.UserWords.Contains(txt) Then
HotParagraph.isUserText = True
End If

End If

End If

HotParagraph.isinEdit = False
HotHocrObjects(HighlightedHocrID) = HotParagraph
EditorTextBox.Visible = False
EditorTextBox = Nothing
HighlightedHocrID = -1
Invalidate()
End If

Freez = False
Expand Down
2 changes: 1 addition & 1 deletion AmhOCR/Data/HocrObjEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Public Structure HocrObjEditor
Public isLocked As Boolean
Public isDirty As Boolean
Public Spelled As Boolean

Public isUserText As Boolean
Public Font As Font
Public alignment As ParAlignment
Public bbox As Rectangle
Expand Down
4 changes: 1 addition & 3 deletions AmhOCR/Data/PageSetting.vb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ Public Class PageSetting






End Sub



End Class
1 change: 0 additions & 1 deletion AmhOCR/MainWindow.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b624a3f

Please sign in to comment.