Skip to content

Commit

Permalink
0.1.0-pre10
Browse files Browse the repository at this point in the history
  • Loading branch information
Happypig375 committed Sep 6, 2018
1 parent 86dfb71 commit 1a53962
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 73 deletions.
4 changes: 2 additions & 2 deletions CSharpMath.Forms/CSharpMath.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre9</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Ios/CSharpMath.Ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<NuGetPackageImportStamp></NuGetPackageImportStamp>
<PackOnBuild>true</PackOnBuild>
<PackageId>CSharpMath.Ios</PackageId>
<PackageVersion>0.1.0-pre9</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -28,7 +28,7 @@
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions CSharpMath.Rendering/CSharpMath.Rendering.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<LangVersion>latest</LangVersion>
Expand All @@ -11,7 +11,7 @@
<!--NuGet Properties-->
<PackOnBuild>true</PackOnBuild>
<PackageId>CSharpMath.Rendering</PackageId>
<PackageVersion>0.1.0-pre9</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
Expand All @@ -24,7 +24,7 @@
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions CSharpMath.Rendering/Text/TextAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public sealed class Space : TextAtom {
public sealed class ControlSpace : TextAtom {
public ControlSpace(int index) : base(new Range(index, 2)) { } // backslash + whitespace = 2 characters
}
public sealed class Accent : TextAtom {
public Accent(TextAtom content, char accent, int index, int commandLength) : base(new Range(index, commandLength + content.Range.Length + 2 /*{ and }*/)) =>
(Content, AccentChar, content.Range) =
(content, accent, new Range(content.Range.Location + commandLength + index + 1/*{*/, content.Range.Length));

public TextAtom Content { get; }

public char AccentChar { get; }
}
public sealed class Math : TextAtom {
public Math(Interfaces.IMathList content, bool displayStyle, Range range) : base(range) => (Content, DisplayStyle) = (content, displayStyle);

Expand Down
1 change: 1 addition & 0 deletions CSharpMath.Rendering/Text/TextAtomListBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class TextAtomListBuilder : IReadOnlyList<TextAtom> {

private void Add(TextAtom atom) { _list.Add(atom); TextLength += atom.Range.Length; }
public void Add() => Add(new TextAtom.ControlSpace(TextLength));
public void Add(TextAtom atom, char accent, int sourceLength) => Add(new TextAtom.Accent(atom, accent, TextLength, sourceLength));
public void Add(string text) => Add(new TextAtom.Text(text, TextLength));
public void Add(Structures.Space space, int sourceLength) => Add(new TextAtom.Space(space, TextLength, sourceLength));
public void Add(TextAtom atom, Enumerations.FontStyle style, int commandLength) => Add(new TextAtom.Style(atom, style, TextLength, commandLength));
Expand Down
111 changes: 67 additions & 44 deletions CSharpMath.Rendering/Text/TextAtoms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,82 @@

namespace CSharpMath.Rendering {
public static class TextAtoms {
public static Dictionary<string, string> PredefinedReplacementAliases { get; } = new Dictionary<string, string> {
{ "backslash", @"\" },
};
public static BiDictionary<string, string> PredefinedReplacements { get; } = new BiDictionary<string, string> {
{ "{", "{" },
{ "}", "}" },
public static AliasDictionary<string, string> PredefinedTextSymbols { get; } = new AliasDictionary<string, string> {
//https://en.wikibooks.org/wiki/LaTeX/Special_Characters
{ "€", "euro" },
{ "°", "textdegree" },
{ "℃", "celsius" },

//http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf page 14 (2 Body-text symbols)
{ "%", "%" },
{ "$", "$" },
{ "_", "_" },
{ "P", "¶" },
{ "ddag", "‡" },
{ "textbar", "|" },
{ "textgreater", ">" },
{ "textendash", "–" },
{ "texttrademark", "™" },
{ "textexclamdown", "¡" },
//textsuperscript
{ "pounds", "£" },
{ "#", "#" },
{ "&", "&" },
{ "S", "§" },
{ "dag", "†" },
{ "textbackslash", @"\" },
{ "textless", "<" },
{ "textemdash", "—" },
{ "textregistered", "®" },
{ "textquestiondown", "¿" },
//textcircled
{ "copyright", "©" },
{ "#", "#" },
{ "^", "textasciicircum" },
{ "<", "textless" },
{ "˜", "textasciitilde" },
{ "ª", "textordfeminine" },
{ "∗", "textasteriskcentered" },
{ "º", "textordmasculine" },
{ "∖", "textbackslash" },
{ "¶", "P", "textparagraph" },
{ "|", "textbar" },
{ "·", "textperiodcentered" },
{ "‖", "textbardbl" },
{ "‱", "textpertenthousand" },
{ "○", "textbigcircle" },
{ "‰", "textperthousand" },
{ "{", "{", "textbraceleft" },
{ "¿", "textquestiondown" },
{ "}", "}", "textbraceright" },
{ "“", "textquotedblleft" },
{ "•", "textbullet" },
{ "”", "textquotedblright" },
{ "©", "copyright", "textcopyright" },
{ "‘", "textquoteleft" },
{ "†", "dag", "textdagger" },
{ "’", "textquoteright" },
{ "‡", "ddag", "textdaggerdbl" },
{ "®", "textregistered" },
{ "$", "$", "textdollar" },
{ "§", "S", "textsection" },
{ "…", "textellipsis" },
{ "£", "pounds", "textsterling" },
{ "—", "textemdash" },
{ "™", "texttrademark" },
{ "–", "textendash" },
{ "_", "_", "textunderscore" },
{ "¡", "textexclamdown" },
{ "␣", "textvisiblespace" },
{ ">", "textgreater" },
};
[System.Obsolete("Work in progress. Don't use because it won't work anyway.")]
public static BiDictionary<char, char> PredefinedAccents { get; } = new BiDictionary<char, char> {

{ '`' , '\u0300' }, //grave
#warning ___WIP___
#if false
//textsuperscript, textsubscript
//textcircled
{ '`' , '\u0300' }, //grave
{ '\'' , '\u0301' }, //acute
{ '^' , '\u0302' }, //circumflex
{ '"' , '\u0308' }, //umlaut, trema or dieresis
{ '~' , '\u0303' }, //tilde
{ '.' , '\u0307' }, //dot
/*{ 'bar' , '\u0304' },
{ 'overbar', '\u0305' }, //not in iosMath
{ 'breve' , '\u0306' },
{ 'ovhook', '\u0309' }, //not in iosMath
{ 'ocirc', '\u030A' }, //not in iosMath
{ 'check' , '\u030C' },
{ 'leftharpoonaccent', '\u20D0' }, //not in iosMath
{ 'rightharpoonaccent', '\u20D1' }, //not in iosMath
{ 'vertoverlay', '\u20D2' }, //not in iosMath
{ 'vec' , '\u20D7' },
{ 'dddot', '\u20DB' }, //not in iosMath
{ 'ddddot', '\u20DC' }, //not in iosMath
{ 'widebridgeabove', '\u20E9' }, //not in iosMath
{ 'asteraccent', '\u20F0' }, //not in iosMath
{ 'threeunderdot', '\u20E8' } //not in iosMath*/
{ 't', '\u20E9' }, //tie
/*{ 'bar' , '\u0304' },
{ 'overbar', '\u0305' }, //not in iosMath
{ 'breve' , '\u0306' },
{ 'ovhook', '\u0309' }, //not in iosMath
{ 'ocirc', '\u030A' }, //not in iosMath
{ 'check' , '\u030C' },
{ 'leftharpoonaccent', '\u20D0' }, //not in iosMath
{ 'rightharpoonaccent', '\u20D1' }, //not in iosMath
{ 'vertoverlay', '\u20D2' }, //not in iosMath
{ 'vec' , '\u20D7' },
{ 'dddot', '\u20DB' }, //not in iosMath
{ 'ddddot', '\u20DC' }, //not in iosMath
{ 'asteraccent', '\u20F0' }, //not in iosMath
{ 'threeunderdot', '\u20E8' } //not in iosMath*/
#endif
};

}
Expand Down
20 changes: 13 additions & 7 deletions CSharpMath.Rendering/Text/TextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,25 @@ Result<string> ReadArgument() {
break;
}
//case "textbf", "textit", ...
case var command when !command.Contains("math") && FontStyleExtensions.FontStyles.TryGetByFirst(command.Replace("text", "math"), out var fontStyle): {
case var textStyle when !textStyle.Contains("math") && FontStyleExtensions.FontStyles.TryGetByFirst(textStyle.Replace("text", "math"), out var fontStyle): {
if (ReadArgument()
.Bind(Build)
.Bind(builtContent => atoms.Add(builtContent, fontStyle, command.Length))
.Bind(builtContent => atoms.Add(builtContent, fontStyle, textStyle.Length))
.Error is string error)
return error;
break;
}
case var alias when TextAtoms.PredefinedReplacementAliases.TryGetValue(alias, out var aliasResult):
string replaceResult = TextAtoms.PredefinedReplacements[first: aliasResult];
atoms.Add(replaceResult);
break;
case var replace when TextAtoms.PredefinedReplacements.TryGetByFirst(replace, out replaceResult):
//case "^", "\"", ...
case var textAccent when TextAtoms.PredefinedAccents.TryGetByFirst(textAccent[0], out var accent): {
if (ReadArgument()
.Bind(Build)
.Bind(builtContent => atoms.Add(builtContent, accent, textAccent.Length))
.Error is string error)
return error;
break;
}
//case "textasciicircum", "textless", ...
case var textSymbol when TextAtoms.PredefinedTextSymbols.TryGetValue(textSymbol, out var replaceResult):
atoms.Add(replaceResult);
break;
case var command:
Expand Down
39 changes: 39 additions & 0 deletions CSharpMath.Rendering/Text/TextLayoutter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ void FinalizeInlineDisplay(float ascender, float rawDescender, float lineGap, bo
FinalizeInlineDisplay(spaceGlyph.Typeface.Ascender * scale, spaceGlyph.Typeface.Descender * scale, spaceGlyph.Typeface.LineGap * scale,
forbidAtLineStart: true); //No spaces at start of line
break;
#warning ___WIP___
#if false
case TextAtom.Accent a:
float _GetSkew(IAccent accent, float accenteeWidth, TGlyph accentGlyph) {
if (accent.Nucleus.Length == 0) {
// no accent
return 0;
}
float accentAdjustment = _mathTable.GetTopAccentAdjustment(_styleFont, accentGlyph);
float accenteeAdjustment = 0;
if (!_IsSingleCharAccent(accent)) {
accenteeAdjustment = accenteeWidth / 2;
} else {
var innerAtom = accent.InnerList.Atoms[0];
var accenteeGlyph = _context.GlyphFinder.FindGlyphForCharacterAtIndex(_font, innerAtom.Nucleus.Length - 1, innerAtom.Nucleus);
accenteeAdjustment = _context.MathTable.GetTopAccentAdjustment(_styleFont, accenteeGlyph);
}
return accenteeAdjustment - accentAdjustment;
}
var (relative, absolute) = Layout(a.Content, fonts, canvasWidth, additionalLineSpacing);
var accentee = new MathListDisplay<Fonts, Glyph>(new[] { relative, absolute });
var rawAccentGlyph = GlyphFinder.Instance.Lookup(fonts, a.AccentChar);
var accenteeWidth = accentee.Width;
scale = rawAccentGlyph.Typeface.CalculateScaleToPixelFromPointSize(fonts.PointSize);
var accentGlyph = _FindVariantGlyph(rawAccentGlyph, accenteeWidth, out float glyphAscent, out float glyphDescent, out float glyphWidth);
var delta = Math.Min(accentee.Ascent, fonts.MathConsts.AccentBaseHeight.Value * scale);
float skew = _GetSkew(accent, accenteeWidth, accentGlyph);
var height = accentee.Ascent - delta;
var accentPosition = new System.Drawing.PointF(skew, height);
display = new GlyphDisplay<Fonts, Glyph>(accentGlyph, a.Range, fonts) {
Ascent = glyphAscent,
Descent = glyphDescent,
Width = glyphWidth,
Position = accentPosition
};
display = new AccentDisplay<Fonts, Glyph>(new GlyphDisplay<Fonts, Glyph>(accentGlyph, a.Range, fonts), new MathListDisplay<Fonts, Glyph>(new[] { relative, absolute }));
FinalizeInlineDisplay(accentGlyph.Typeface.Ascender * scale, accentGlyph.Typeface.Descender * scale, accentGlyph.Typeface.LineGap * scale);
break;
#endif
case null:
throw new InvalidOperationException("TextAtoms should never be null. You must have sneaked one in.");
case var a:
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.SkiaSharp/CSharpMath.SkiaSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<TargetFramework>netstandard1.3</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre9</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Utils.NuGet/ReleaseData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<ReleaseData>
<_Global->
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild>
<PackageVersion>0.1.0-pre9</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
<PackageReleaseNotes>The 0.1.0 SkiaSharp Update brings the SkiaSharp and Xamarin.Forms front ends to CSharpMath.</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageProjectUrl>https://github.com/verybadcat/CSharpMath</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
6 changes: 3 additions & 3 deletions CSharpMath/CSharpMath.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<LangVersion>latest</LangVersion>
Expand All @@ -12,9 +12,9 @@
<PackageLicenseUrl>https://github.com/verybadcat/CSharpMath/blob/master/LICENSE</PackageLicenseUrl>
<Copyright>CSharpMath Contributors 2018</Copyright>
<PackageTags>math;mathematics;mathematical;formula;equation;equations;expression;tex;latex;render;rendering;display</PackageTags>
<PackageVersion>0.1.0-pre8</PackageVersion>
<PackageVersion>0.1.0-pre10</PackageVersion>
<RepositoryBranch>master</RepositoryBranch>
<RepositoryCommit>e02f5b39a1346affa843b3001f95d1185b695029</RepositoryCommit>
<RepositoryCommit>86dfb7101a319291a5481c41a1d13fb1ad9d8ec0</RepositoryCommit>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/verybadcat/CSharpMath/master/Icon.png</PackageIconUrl>
<PackageId>CSharpMath</PackageId>
Expand Down
Loading

0 comments on commit 1a53962

Please sign in to comment.