-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#63) CharInfo: decouple from WPF and move into Shared assembly
- Loading branch information
Showing
18 changed files
with
87 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace WpfMath.Fonts; | ||
|
||
public interface IFontTypeface | ||
{ | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using WpfMath.Exceptions; | ||
|
||
namespace WpfMath.Fonts; | ||
|
||
internal static class WpfCharInfoEx | ||
{ | ||
public static GlyphRun GetGlyphRun(this CharInfo info, double x, double y, double scale) | ||
{ | ||
var typeface = ((WpfGlyphTypeface)info.Font).Typeface; | ||
var characterInt = (int)info.Character; | ||
if (!typeface.CharacterToGlyphMap.TryGetValue(characterInt, out var glyphIndex)) | ||
{ | ||
var fontName = typeface.FamilyNames.Values.First(); | ||
var characterHex = characterInt.ToString("X4"); | ||
throw new TexCharacterMappingNotFoundException( | ||
$"The {fontName} font does not support '{info.Character}' (U+{characterHex}) character."); | ||
} | ||
#if NET452 | ||
var glyphRun = new GlyphRun(typeface, 0, false, info.Size * scale, | ||
new ushort[] { glyphIndex }, new Point(x * scale, y * scale), | ||
new double[] { typeface.AdvanceWidths[glyphIndex] }, null, null, null, null, null, null); | ||
#else | ||
var glyphRun = new GlyphRun((float)scale); | ||
((ISupportInitialize)glyphRun).BeginInit(); | ||
glyphRun.GlyphTypeface = typeface; | ||
glyphRun.FontRenderingEmSize = info.Size * scale; | ||
glyphRun.GlyphIndices = new[] { glyphIndex }; | ||
glyphRun.BaselineOrigin = new Point(x * scale, y * scale); | ||
glyphRun.AdvanceWidths = new[] { typeface.AdvanceWidths[glyphIndex] }; | ||
((ISupportInitialize)glyphRun).EndInit(); | ||
#endif | ||
return glyphRun; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using System.Windows.Media; | ||
|
||
namespace WpfMath.Fonts; | ||
|
||
internal record WpfGlyphTypeface(GlyphTypeface Typeface) : IFontTypeface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters