Skip to content

Commit

Permalink
Adding subscript support (no rendering)
Browse files Browse the repository at this point in the history
  • Loading branch information
FremyCompany_cp authored and FremyCompany_cp committed Aug 28, 2012
1 parent 71c08e3 commit 991172c
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 36 deletions.
8 changes: 7 additions & 1 deletion FC.MathEditor/WpfMathEditor/Classes/Helpers/ExportHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@
Protected MustOverride ReadOnly Property PreferInlineContent_Internal As Boolean
Public ReadOnly Property PreferInlineContent As Boolean
Get
Return PreferInlineContent_Internal ' OrElse (This.ParentElement IsNot Nothing AndAlso This.ParentElement.Export.PreferInlineContent)
Return PreferInlineContent_Internal OrElse (This.ParentElement IsNot Nothing AndAlso This.ParentElement.Export.PreferInlineContentFor(This))
End Get
End Property

Public Overridable ReadOnly Property PreferInlineContentFor(Child As MathElement) As Boolean
Get
Return PreferInlineContent
End Get
End Property

Expand Down
81 changes: 61 additions & 20 deletions FC.MathEditor/WpfMathEditor/Classes/Helpers/InputHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,20 @@
End Function

Public Function ProcessChar_FromRight(InputChar As Integer) As Boolean

' Process special chars from right
Select Case InputChar
Case AscW("_"c)
If ProcessUnderscore_FromRight() Then Return True
Case AscW("/"c)
If ProcessFraction_FromRight() Then Return True
Case AscW("^"c)
If ProcessHat_FromRight() Then Return True
End Select

' Handle all other cases
Return ProcessChar_FromRight_Internal(InputChar)

End Function

Public Sub ProcessDelete(Ctrl As Boolean, Alt As Boolean, Shift As Boolean)
Expand All @@ -104,23 +117,22 @@
Exit Sub
End If

' Perform the classical action for Delete for this element
If ProcessDelete_Internal(Ctrl, Alt, Shift) Then
Exit Sub
End If

' If this element didn't respond to the keypress, we may forward the event to another one
If This.Selection.NextSibling Is Nothing Then
If This.Selection.MoveAfterParent() Then This.Selection.ParentElement.Input.ProcessDelete(Ctrl, Alt, Shift)
Exit Sub
End If

Else

' If the selection is not empty, we just need to delete its content
This.Selection.DeleteContents()
Exit Sub

End If

' Perform the classical action for Delete for this element
If ProcessDelete_Internal(Ctrl, Alt, Shift) Then
Exit Sub
End If

' If this element didn't respond to the keypress, we may forward the event to another one
If This.Selection.NextSibling Is Nothing Then
If This.Selection.MoveAfterParent() Then This.Selection.ParentElement.Input.ProcessDelete(Ctrl, Alt, Shift)
Exit Sub
End If

End Sub
Expand Down Expand Up @@ -299,7 +311,7 @@

Public Overridable Function ProcessWaitChar(InputChar As Integer) As Boolean
' Default wait char processing : eat, and walk to next child
WaitChar = Nothing : This.Selection.SetPoint(This.ParentElement.GetSelectionAt(This.ChildIndex + 1))
WaitChar = Nothing : This.Selection.SetPoint(This.ParentElement.GetSelectionAfter())
Return True
End Function

Expand Down Expand Up @@ -335,10 +347,9 @@
' In case there's no element to delete, forward the call
If ElementToDelete Is Nothing Then Return False

' If there's one element to delete, delete it
' Move selection end point to the right, then clear
ProcessRightKey(Ctrl, Alt, True)
This.Selection.DeleteContents()
'x ElementToDelete.ParentElement.RemoveChild(ElementToDelete)

' Inform that the delete key was handled
Return True
Expand All @@ -353,10 +364,9 @@
' In case there's no element to delete, forward the call
If ElementToDelete Is Nothing Then Return False

' If there's one element to delete, delete it
' Move selection end point to the left, then clear
ProcessLeftKey(Ctrl, Alt, True)
This.Selection.DeleteContents()
'x ElementToDelete.ParentElement.RemoveChild(ElementToDelete)

' Inform that the delete key was handled
Return True
Expand Down Expand Up @@ -443,19 +453,50 @@
Return False
End Function

' TODO: Override this for RLE to avoid RLE in RLE (+next functions)
Public Overridable Function ProcessHat_FromRight_Internal() As Boolean
' TODO: ProcessHat

' Wrap the element in a script automatically by default
Dim Script As New SubSupScriptFormatter()
This.ParentElement.ReplaceChild(This, Script)
Script.Base.AddChild(This)

' Set the selection in the script
This.Selection.SetPoint(Script.SuperScript.GetSelectionAtOrigin())

' Abort any other steps
Return True

End Function

Public Overridable Function ProcessUnderscore_FromRight_Internal() As Boolean
' TODO: ProcessUnderscore

' Wrap the element in a script automatically by default
Dim Script As New SubSupScriptFormatter()
This.ParentElement.ReplaceChild(This, Script)
Script.Base.AddChild(This)

' Set the selection in the script
This.Selection.SetPoint(Script.SubScript.GetSelectionAtOrigin())

' Abort any other steps
Return True

End Function

Public Overridable Function ProcessFraction_FromRight_Internal() As Boolean
' TODO: ProcessFraction

' Wrap the element in a fraction automatically by default
Dim Fraction As New FractionFormatter()
This.ParentElement.ReplaceChild(This, Fraction)
Fraction.Numerator.AddChild(This)

' Set the selection in the script
This.Selection.SetPoint(Fraction.Denominator.GetSelectionAtOrigin())

' Abort any other steps
Return True

End Function

Public Event BeforeProcessChar As EventHandler(Of InputEventArgs)
Expand Down
3 changes: 2 additions & 1 deletion FC.MathEditor/WpfMathEditor/EquationEditor.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
<Compile Include="Formatters\Fraction\FractionFormatterExportHelper.vb" />
<Compile Include="Formatters\Root\RootFormatter.vb" />
<Compile Include="Formatters\Root\RootFormatterExportHelper.vb" />
<Compile Include="Formatters\SubSupScript\SubSupScriptFormatter.vb" />
<Compile Include="Formatters\SubSupScript\SubSupScriptFormatterExportHelper.vb" />
<Compile Include="QualityControl.vb" />
<Compile Include="Classes\Helpers\SelectionHelper2.Actions.vb" />
<Compile Include="Classes\Helpers\SelectionHelper2.SubTypes.vb" />
Expand Down Expand Up @@ -234,7 +236,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Classes\Properties\" />
<Folder Include="Formatters\SubScript\" />
<Folder Include="Parsers\Elements\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Public Class FractionFormatter : Inherits MathElement


Public Sub New(Optional Numerator As RowLayoutEngine = Nothing, Optional Denominator As RowLayoutEngine = Nothing)

If Numerator Is Nothing Then Numerator = New RowLayoutEngine()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Public Class SubSupScriptFormatter : Inherits MathElement

Public Sub New(Optional Base As RowLayoutEngine = Nothing, Optional SubScript As RowLayoutEngine = Nothing, Optional SuperScript As RowLayoutEngine = Nothing)

If Base Is Nothing Then Base = New RowLayoutEngine()
If SubScript Is Nothing Then SubScript = New RowLayoutEngine()
If SuperScript Is Nothing Then SuperScript = New RowLayoutEngine()

Children.Add(Base)
Children.Add(SubScript)
Children.Add(SuperScript)
DirectCast(Children, FormatterChildrenHelper).Freeze()

End Sub

Public Property Base As RowLayoutEngine
Get
Return Children(0)
End Get
Set(value As RowLayoutEngine)
Children.Replace(Children(0), value)
End Set
End Property

Public Property SubScript As RowLayoutEngine
Get
Return Children(1)
End Get
Set(value As RowLayoutEngine)
Children.Replace(Children(1), value)
End Set
End Property

Public Property SuperScript As RowLayoutEngine
Get
Return Children(2)
End Get
Set(value As RowLayoutEngine)
Children.Replace(Children(2), value)
End Set
End Property

Protected Overrides Function Clone_Internal(ByRef ShouldCloneChildren As Boolean) As MathElement

If ShouldCloneChildren Then
Dim Result As New SubSupScriptFormatter(Base.Clone, SubScript.Clone, SuperScript.Clone)
ShouldCloneChildren = False
Return Result
Else
Return New SubSupScriptFormatter()
End If

End Function

Protected Overrides Function GetInitialChildrenHelper() As ChildrenHelper
Return New FormatterChildrenHelper(Me)
End Function

Protected Overrides Function GetInitialExportHelper() As ExportHelper
Return New SubSupScriptFormatterExportHelper(Me)
End Function

Protected Overrides Function GetInitialInputHelper() As InputHelper
' TODO: Input helper for
Return New EmptyInputHelper(Me)
End Function

End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Public Class SubSupScriptFormatterExportHelper : Inherits ExportHelper

Public Sub New(This As SubSupScriptFormatter)
MyBase.New(This)
End Sub

Public Shadows ReadOnly Property This As SubSupScriptFormatter
Get
Return MyBase.This
End Get
End Property

Public Overrides Sub AppendKeyboardInput(SB As System.Text.StringBuilder)
This.Base.Export.AppendKeyboardInput(SB)
SB.Append("_"c)
This.SubScript.Export.AppendKeyboardInput(SB)
End Sub

Public Overrides Sub AppendLaTeX(SB As System.Text.StringBuilder)
This.Base.Export.AppendLaTeX(SB)
SB.Append("_"c)
This.SubScript.Export.AppendLaTeX(SB)
End Sub

Public Overrides Sub AppendMathML(SB As System.Text.StringBuilder)

End Sub

Public Overrides Sub AppendSimpleText(SB As System.Text.StringBuilder)
This.Base.Export.AppendSimpleText(SB)
SB.Append("_"c)
This.SubScript.Export.AppendSimpleText(SB)
End Sub

Protected Overrides Sub CalculateMinHeight_Internal()

End Sub

Protected Overrides Sub Draw_Internal(DG As System.Windows.Media.DrawingContext)

End Sub

Protected Overrides Sub GenerateLayout_Internal()

End Sub

Protected Overrides ReadOnly Property PreferInlineContent_Internal As Boolean
Get
Return False
End Get
End Property

Public Overrides ReadOnly Property PreferInlineContentFor(Child As MathElement) As Boolean
Get

' Only the scripts have a special behavior
If Child IsNot This.Base Then Return True

' We need to keep inheritance for the base
Return MyBase.PreferInlineContentFor(Child)

End Get
End Property

Protected Overrides Sub PrepareLayout_Internal(AvailABH As Double, AvailBBH As Double)

End Sub
End Class
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,57 @@ Public Class RowLayoutEngineExportHelper : Inherits ExportHelper
End Sub

Public Overrides Sub AppendSimpleText(SB As System.Text.StringBuilder)
For Each Child In This.Children
Child.Export.AppendSimpleText(SB)
Next
If This.Children.HasOne AndAlso This.Children.First.IsTextEdit Then

' If there's only one child and that it's text, we can simply add it
This.Children.First.Export.AppendSimpleText(SB)

Else

' Or else we need parenthesis
SB.Append("("c)
For Each Child In This.Children
Child.Export.AppendSimpleText(SB)
Next
SB.Append(")"c)

End If
End Sub

Public Overrides Sub AppendKeyboardInput(SB As System.Text.StringBuilder)
SB.Append("(")
For Each Child In This.Children
Child.Export.AppendKeyboardInput(SB)
Next
SB.Append(")")
If This.Children.HasOne AndAlso This.Children.First.IsTextEdit Then

' If there's only one child and that it's text, we can simply add it
This.Children.First.Export.AppendKeyboardInput(SB)

Else

' Or else we need parenthesis
SB.Append("("c)
For Each Child In This.Children
Child.Export.AppendKeyboardInput(SB)
Next
SB.Append(")"c)

End If
End Sub

Public Overrides Sub AppendLaTeX(SB As System.Text.StringBuilder)
SB.Append("{")
For Each Child In This.Children
Child.Export.AppendLaTeX(SB)
Next
SB.Append("}")
If This.Children.HasOne AndAlso This.Children.First.IsTextEdit Then

' If there's only one child and that it's text, we can simply add it
This.Children.First.Export.AppendLaTeX(SB)

Else

' Or else we need parenthesis
SB.Append("{")
For Each Child In This.Children
Child.Export.AppendLaTeX(SB)
Next
SB.Append("}")

End If
End Sub

Public Overrides Sub AppendMathML(SB As System.Text.StringBuilder)
Expand Down

0 comments on commit 991172c

Please sign in to comment.