Skip to content

Commit 1a53962

Browse files
committed
0.1.0-pre10
1 parent 86dfb71 commit 1a53962

File tree

13 files changed

+239
-73
lines changed

13 files changed

+239
-73
lines changed

CSharpMath.Forms/CSharpMath.Forms.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
6-
<PackageVersion>0.1.0-pre9</PackageVersion>
6+
<PackageVersion>0.1.0-pre10</PackageVersion>
77
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
88
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
99
<RepositoryType>git</RepositoryType>
1010
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
1111
<RepositoryBranch>master</RepositoryBranch>
12-
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
12+
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
1313
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
1414
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1515
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>

CSharpMath.Ios/CSharpMath.Ios.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<NuGetPackageImportStamp></NuGetPackageImportStamp>
1515
<PackOnBuild>true</PackOnBuild>
1616
<PackageId>CSharpMath.Ios</PackageId>
17-
<PackageVersion>0.1.0-pre9</PackageVersion>
17+
<PackageVersion>0.1.0-pre10</PackageVersion>
1818
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
1919
<NeutralLanguage>en</NeutralLanguage>
2020
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
@@ -28,7 +28,7 @@
2828
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
2929
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
3030
<RepositoryBranch>master</RepositoryBranch>
31-
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
31+
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
3232
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
3333
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
3434
</PropertyGroup>

CSharpMath.Rendering/CSharpMath.Rendering.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard1.3</TargetFramework>
44
<LangVersion>latest</LangVersion>
@@ -11,7 +11,7 @@
1111
<!--NuGet Properties-->
1212
<PackOnBuild>true</PackOnBuild>
1313
<PackageId>CSharpMath.Rendering</PackageId>
14-
<PackageVersion>0.1.0-pre9</PackageVersion>
14+
<PackageVersion>0.1.0-pre10</PackageVersion>
1515
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
1616
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
1717
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
@@ -24,7 +24,7 @@
2424
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
2525
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
2626
<RepositoryBranch>master</RepositoryBranch>
27-
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
27+
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
2828
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
2929
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
3030
</PropertyGroup>

CSharpMath.Rendering/Text/TextAtom.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public sealed class Space : TextAtom {
3030
public sealed class ControlSpace : TextAtom {
3131
public ControlSpace(int index) : base(new Range(index, 2)) { } // backslash + whitespace = 2 characters
3232
}
33+
public sealed class Accent : TextAtom {
34+
public Accent(TextAtom content, char accent, int index, int commandLength) : base(new Range(index, commandLength + content.Range.Length + 2 /*{ and }*/)) =>
35+
(Content, AccentChar, content.Range) =
36+
(content, accent, new Range(content.Range.Location + commandLength + index + 1/*{*/, content.Range.Length));
37+
38+
public TextAtom Content { get; }
39+
40+
public char AccentChar { get; }
41+
}
3342
public sealed class Math : TextAtom {
3443
public Math(Interfaces.IMathList content, bool displayStyle, Range range) : base(range) => (Content, DisplayStyle) = (content, displayStyle);
3544

CSharpMath.Rendering/Text/TextAtomListBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class TextAtomListBuilder : IReadOnlyList<TextAtom> {
99

1010
private void Add(TextAtom atom) { _list.Add(atom); TextLength += atom.Range.Length; }
1111
public void Add() => Add(new TextAtom.ControlSpace(TextLength));
12+
public void Add(TextAtom atom, char accent, int sourceLength) => Add(new TextAtom.Accent(atom, accent, TextLength, sourceLength));
1213
public void Add(string text) => Add(new TextAtom.Text(text, TextLength));
1314
public void Add(Structures.Space space, int sourceLength) => Add(new TextAtom.Space(space, TextLength, sourceLength));
1415
public void Add(TextAtom atom, Enumerations.FontStyle style, int commandLength) => Add(new TextAtom.Style(atom, style, TextLength, commandLength));

CSharpMath.Rendering/Text/TextAtoms.cs

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,82 @@
44

55
namespace CSharpMath.Rendering {
66
public static class TextAtoms {
7-
public static Dictionary<string, string> PredefinedReplacementAliases { get; } = new Dictionary<string, string> {
8-
{ "backslash", @"\" },
9-
};
10-
public static BiDictionary<string, string> PredefinedReplacements { get; } = new BiDictionary<string, string> {
11-
{ "{", "{" },
12-
{ "}", "}" },
7+
public static AliasDictionary<string, string> PredefinedTextSymbols { get; } = new AliasDictionary<string, string> {
8+
//https://en.wikibooks.org/wiki/LaTeX/Special_Characters
9+
{ "€", "euro" },
10+
{ "°", "textdegree" },
11+
{ "℃", "celsius" },
12+
13+
//http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf page 14 (2 Body-text symbols)
1314
{ "%", "%" },
14-
{ "$", "$" },
15-
{ "_", "_" },
16-
{ "P", "¶" },
17-
{ "ddag", "‡" },
18-
{ "textbar", "|" },
19-
{ "textgreater", ">" },
20-
{ "textendash", "–" },
21-
{ "texttrademark", "™" },
22-
{ "textexclamdown", "¡" },
23-
//textsuperscript
24-
{ "pounds", "£" },
25-
{ "#", "#" },
2615
{ "&", "&" },
27-
{ "S", "§" },
28-
{ "dag", "†" },
29-
{ "textbackslash", @"\" },
30-
{ "textless", "<" },
31-
{ "textemdash", "—" },
32-
{ "textregistered", "®" },
33-
{ "textquestiondown", "¿" },
34-
//textcircled
35-
{ "copyright", "©" },
16+
{ "#", "#" },
17+
{ "^", "textasciicircum" },
18+
{ "<", "textless" },
19+
{ "˜", "textasciitilde" },
20+
{ "ª", "textordfeminine" },
21+
{ "∗", "textasteriskcentered" },
22+
{ "º", "textordmasculine" },
23+
{ "∖", "textbackslash" },
24+
{ "¶", "P", "textparagraph" },
25+
{ "|", "textbar" },
26+
{ "·", "textperiodcentered" },
27+
{ "‖", "textbardbl" },
28+
{ "‱", "textpertenthousand" },
29+
{ "○", "textbigcircle" },
30+
{ "‰", "textperthousand" },
31+
{ "{", "{", "textbraceleft" },
32+
{ "¿", "textquestiondown" },
33+
{ "}", "}", "textbraceright" },
34+
{ "“", "textquotedblleft" },
35+
{ "•", "textbullet" },
36+
{ "”", "textquotedblright" },
37+
{ "©", "copyright", "textcopyright" },
38+
{ "‘", "textquoteleft" },
39+
{ "†", "dag", "textdagger" },
40+
{ "’", "textquoteright" },
41+
{ "‡", "ddag", "textdaggerdbl" },
42+
{ "®", "textregistered" },
43+
{ "$", "$", "textdollar" },
44+
{ "§", "S", "textsection" },
45+
{ "…", "textellipsis" },
46+
{ "£", "pounds", "textsterling" },
47+
{ "—", "textemdash" },
48+
{ "™", "texttrademark" },
49+
{ "–", "textendash" },
50+
{ "_", "_", "textunderscore" },
51+
{ "¡", "textexclamdown" },
52+
{ "␣", "textvisiblespace" },
53+
{ ">", "textgreater" },
3654
};
55+
[System.Obsolete("Work in progress. Don't use because it won't work anyway.")]
3756
public static BiDictionary<char, char> PredefinedAccents { get; } = new BiDictionary<char, char> {
38-
39-
{ '`' , '\u0300' }, //grave
57+
#warning ___WIP___
58+
#if false
59+
//textsuperscript, textsubscript
60+
//textcircled
61+
{ '`' , '\u0300' }, //grave
4062
{ '\'' , '\u0301' }, //acute
4163
{ '^' , '\u0302' }, //circumflex
4264
{ '"' , '\u0308' }, //umlaut, trema or dieresis
4365
{ '~' , '\u0303' }, //tilde
4466
{ '.' , '\u0307' }, //dot
45-
/*{ 'bar' , '\u0304' },
46-
{ 'overbar', '\u0305' }, //not in iosMath
47-
{ 'breve' , '\u0306' },
48-
{ 'ovhook', '\u0309' }, //not in iosMath
49-
{ 'ocirc', '\u030A' }, //not in iosMath
50-
{ 'check' , '\u030C' },
51-
{ 'leftharpoonaccent', '\u20D0' }, //not in iosMath
52-
{ 'rightharpoonaccent', '\u20D1' }, //not in iosMath
53-
{ 'vertoverlay', '\u20D2' }, //not in iosMath
54-
{ 'vec' , '\u20D7' },
55-
{ 'dddot', '\u20DB' }, //not in iosMath
56-
{ 'ddddot', '\u20DC' }, //not in iosMath
57-
{ 'widebridgeabove', '\u20E9' }, //not in iosMath
58-
{ 'asteraccent', '\u20F0' }, //not in iosMath
59-
{ 'threeunderdot', '\u20E8' } //not in iosMath*/
67+
{ 't', '\u20E9' }, //tie
68+
/*{ 'bar' , '\u0304' },
69+
{ 'overbar', '\u0305' }, //not in iosMath
70+
{ 'breve' , '\u0306' },
71+
{ 'ovhook', '\u0309' }, //not in iosMath
72+
{ 'ocirc', '\u030A' }, //not in iosMath
73+
{ 'check' , '\u030C' },
74+
{ 'leftharpoonaccent', '\u20D0' }, //not in iosMath
75+
{ 'rightharpoonaccent', '\u20D1' }, //not in iosMath
76+
{ 'vertoverlay', '\u20D2' }, //not in iosMath
77+
{ 'vec' , '\u20D7' },
78+
{ 'dddot', '\u20DB' }, //not in iosMath
79+
{ 'ddddot', '\u20DC' }, //not in iosMath
80+
{ 'asteraccent', '\u20F0' }, //not in iosMath
81+
{ 'threeunderdot', '\u20E8' } //not in iosMath*/
82+
#endif
6083
};
6184

6285
}

CSharpMath.Rendering/Text/TextBuilder.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,25 @@ Result<string> ReadArgument() {
305305
break;
306306
}
307307
//case "textbf", "textit", ...
308-
case var command when !command.Contains("math") && FontStyleExtensions.FontStyles.TryGetByFirst(command.Replace("text", "math"), out var fontStyle): {
308+
case var textStyle when !textStyle.Contains("math") && FontStyleExtensions.FontStyles.TryGetByFirst(textStyle.Replace("text", "math"), out var fontStyle): {
309309
if (ReadArgument()
310310
.Bind(Build)
311-
.Bind(builtContent => atoms.Add(builtContent, fontStyle, command.Length))
311+
.Bind(builtContent => atoms.Add(builtContent, fontStyle, textStyle.Length))
312312
.Error is string error)
313313
return error;
314314
break;
315315
}
316-
case var alias when TextAtoms.PredefinedReplacementAliases.TryGetValue(alias, out var aliasResult):
317-
string replaceResult = TextAtoms.PredefinedReplacements[first: aliasResult];
318-
atoms.Add(replaceResult);
319-
break;
320-
case var replace when TextAtoms.PredefinedReplacements.TryGetByFirst(replace, out replaceResult):
316+
//case "^", "\"", ...
317+
case var textAccent when TextAtoms.PredefinedAccents.TryGetByFirst(textAccent[0], out var accent): {
318+
if (ReadArgument()
319+
.Bind(Build)
320+
.Bind(builtContent => atoms.Add(builtContent, accent, textAccent.Length))
321+
.Error is string error)
322+
return error;
323+
break;
324+
}
325+
//case "textasciicircum", "textless", ...
326+
case var textSymbol when TextAtoms.PredefinedTextSymbols.TryGetValue(textSymbol, out var replaceResult):
321327
atoms.Add(replaceResult);
322328
break;
323329
case var command:

CSharpMath.Rendering/Text/TextLayoutter.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,45 @@ void FinalizeInlineDisplay(float ascender, float rawDescender, float lineGap, bo
106106
FinalizeInlineDisplay(spaceGlyph.Typeface.Ascender * scale, spaceGlyph.Typeface.Descender * scale, spaceGlyph.Typeface.LineGap * scale,
107107
forbidAtLineStart: true); //No spaces at start of line
108108
break;
109+
#warning ___WIP___
110+
#if false
111+
case TextAtom.Accent a:
112+
float _GetSkew(IAccent accent, float accenteeWidth, TGlyph accentGlyph) {
113+
if (accent.Nucleus.Length == 0) {
114+
// no accent
115+
return 0;
116+
}
117+
float accentAdjustment = _mathTable.GetTopAccentAdjustment(_styleFont, accentGlyph);
118+
float accenteeAdjustment = 0;
119+
if (!_IsSingleCharAccent(accent)) {
120+
accenteeAdjustment = accenteeWidth / 2;
121+
} else {
122+
var innerAtom = accent.InnerList.Atoms[0];
123+
var accenteeGlyph = _context.GlyphFinder.FindGlyphForCharacterAtIndex(_font, innerAtom.Nucleus.Length - 1, innerAtom.Nucleus);
124+
accenteeAdjustment = _context.MathTable.GetTopAccentAdjustment(_styleFont, accenteeGlyph);
125+
}
126+
return accenteeAdjustment - accentAdjustment;
127+
}
128+
var (relative, absolute) = Layout(a.Content, fonts, canvasWidth, additionalLineSpacing);
129+
var accentee = new MathListDisplay<Fonts, Glyph>(new[] { relative, absolute });
130+
var rawAccentGlyph = GlyphFinder.Instance.Lookup(fonts, a.AccentChar);
131+
var accenteeWidth = accentee.Width;
132+
scale = rawAccentGlyph.Typeface.CalculateScaleToPixelFromPointSize(fonts.PointSize);
133+
var accentGlyph = _FindVariantGlyph(rawAccentGlyph, accenteeWidth, out float glyphAscent, out float glyphDescent, out float glyphWidth);
134+
var delta = Math.Min(accentee.Ascent, fonts.MathConsts.AccentBaseHeight.Value * scale);
135+
float skew = _GetSkew(accent, accenteeWidth, accentGlyph);
136+
var height = accentee.Ascent - delta;
137+
var accentPosition = new System.Drawing.PointF(skew, height);
138+
display = new GlyphDisplay<Fonts, Glyph>(accentGlyph, a.Range, fonts) {
139+
Ascent = glyphAscent,
140+
Descent = glyphDescent,
141+
Width = glyphWidth,
142+
Position = accentPosition
143+
};
144+
display = new AccentDisplay<Fonts, Glyph>(new GlyphDisplay<Fonts, Glyph>(accentGlyph, a.Range, fonts), new MathListDisplay<Fonts, Glyph>(new[] { relative, absolute }));
145+
FinalizeInlineDisplay(accentGlyph.Typeface.Ascender * scale, accentGlyph.Typeface.Descender * scale, accentGlyph.Typeface.LineGap * scale);
146+
break;
147+
#endif
109148
case null:
110149
throw new InvalidOperationException("TextAtoms should never be null. You must have sneaked one in.");
111150
case var a:

CSharpMath.SkiaSharp/CSharpMath.SkiaSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<TargetFramework>netstandard1.3</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
6-
<PackageVersion>0.1.0-pre9</PackageVersion>
6+
<PackageVersion>0.1.0-pre10</PackageVersion>
77
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
88
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
99
<RepositoryType>git</RepositoryType>
1010
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
1111
<RepositoryBranch>master</RepositoryBranch>
12-
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
12+
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
1313
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
1414
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1515
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>

CSharpMath.Utils.NuGet/ReleaseData.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<ReleaseData>
33
<_Global->
44
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
5-
<PackageVersion>0.1.0-pre9</PackageVersion>
5+
<PackageVersion>0.1.0-pre10</PackageVersion>
66
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
77
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
88
<RepositoryType>git</RepositoryType>
99
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
1010
<RepositoryBranch>master</RepositoryBranch>
11-
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
11+
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
1212
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
1313
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1414
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>

0 commit comments

Comments
 (0)