Getting a font selector in tools
This commit is contained in:
parent
fc8bbc1738
commit
813404e63b
5 changed files with 1288 additions and 28 deletions
|
|
@ -668,6 +668,34 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
private static TypeFace titilliumTypeFace = null;
|
||||
public static TypeFace TitilliumTypeFace
|
||||
{
|
||||
get
|
||||
{
|
||||
if (titilliumTypeFace == null)
|
||||
{
|
||||
titilliumTypeFace = TypeFace.LoadFrom(AggContext.StaticData.ReadAllText(Path.Combine("Fonts", "TitilliumWeb-Black.svg")));
|
||||
}
|
||||
|
||||
return titilliumTypeFace;
|
||||
}
|
||||
}
|
||||
|
||||
private static TypeFace damionTypeFace = null;
|
||||
public static TypeFace DamionTypeFace
|
||||
{
|
||||
get
|
||||
{
|
||||
if (damionTypeFace == null)
|
||||
{
|
||||
damionTypeFace = TypeFace.LoadFrom(AggContext.StaticData.ReadAllText(Path.Combine("Fonts", "Damion-Regular.svg")));
|
||||
}
|
||||
|
||||
return damionTypeFace;
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<T> LoadCacheableAsync<T>(string cacheKey, string cacheScope, string staticDataFallbackPath = null) where T : class
|
||||
{
|
||||
string cachePath = CacheablePath(cacheScope, cacheKey);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
|||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
|
|
@ -386,16 +387,41 @@ public class ChairFoot2 : MatterCadObject3D
|
|||
}
|
||||
}
|
||||
|
||||
public enum NamedTypeFace { Liberation_Sans, Liberation_Sans_Bold, Liberation_Mono, Titillium, Damion };
|
||||
|
||||
public static class NamedTypeFaceCache
|
||||
{
|
||||
public static TypeFace GetTypeFace(NamedTypeFace Name)
|
||||
{
|
||||
switch (Name)
|
||||
{
|
||||
case NamedTypeFace.Liberation_Sans:
|
||||
return LiberationSansFont.Instance;
|
||||
|
||||
case NamedTypeFace.Liberation_Sans_Bold:
|
||||
return LiberationSansBoldFont.Instance;
|
||||
|
||||
case NamedTypeFace.Liberation_Mono:
|
||||
return ApplicationController.MonoSpacedTypeFace;
|
||||
|
||||
case NamedTypeFace.Titillium:
|
||||
return ApplicationController.TitilliumTypeFace;
|
||||
|
||||
case NamedTypeFace.Damion:
|
||||
return ApplicationController.DamionTypeFace;
|
||||
|
||||
default:
|
||||
return LiberationSansFont.Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TextPrimitive : Object3D, IRebuildable
|
||||
{
|
||||
[DisplayName("Name")]
|
||||
public string NameToWrite { get; set; } = "Text";
|
||||
|
||||
public enum Style { Sans, SansBold, Mono };
|
||||
public Style FontStyle = Style.Sans;
|
||||
|
||||
public bool Bold { get; set; } = false;
|
||||
public bool Mono { get; set; } = false;
|
||||
public NamedTypeFace Font { get; set; } = new NamedTypeFace();
|
||||
|
||||
public double PointSize { get; set; } = 24;
|
||||
|
||||
|
|
@ -410,14 +436,7 @@ public class ChairFoot2 : MatterCadObject3D
|
|||
|
||||
public void Rebuild()
|
||||
{
|
||||
|
||||
var letterPrinter = new TypeFacePrinter(NameToWrite, PointSize * 0.352778, bold: Bold);
|
||||
|
||||
if (Mono)
|
||||
{
|
||||
letterPrinter = new TypeFacePrinter(NameToWrite, new StyledTypeFace(ApplicationController.MonoSpacedTypeFace, PointSize * 0.352778));
|
||||
}
|
||||
|
||||
var letterPrinter = new TypeFacePrinter(NameToWrite, new StyledTypeFace(NamedTypeFaceCache.GetTypeFace(Font), PointSize * 0.352778));
|
||||
|
||||
IObject3D nameMesh = new Object3D()
|
||||
{
|
||||
|
|
@ -750,8 +769,6 @@ public class ChairFoot2 : MatterCadObject3D
|
|||
{
|
||||
public override string ActiveEditor => "PublicPropertyEditor";
|
||||
|
||||
private static TypeFace typeFace = null;
|
||||
|
||||
public RibonWithName()
|
||||
{
|
||||
Rebuild();
|
||||
|
|
@ -760,18 +777,15 @@ public class ChairFoot2 : MatterCadObject3D
|
|||
[DisplayName("Name")]
|
||||
public string NameToWrite { get; set; } = "MatterHackers";
|
||||
|
||||
public NamedTypeFace Font { get; set; } = new NamedTypeFace();
|
||||
|
||||
public void Rebuild()
|
||||
{
|
||||
IObject3D cancerRibonStl = Object3D.Load("Cancer_Ribbon.stl", CancellationToken.None);
|
||||
|
||||
cancerRibonStl = new Rotate(cancerRibonStl, MathHelper.DegreesToRadians(90));
|
||||
|
||||
if (typeFace == null)
|
||||
{
|
||||
typeFace = TypeFace.LoadFrom(AggContext.StaticData.ReadAllText(Path.Combine("Fonts", "TitilliumWeb-Black.svg")));
|
||||
}
|
||||
|
||||
var letterPrinter = new TypeFacePrinter(NameToWrite.ToUpper(), new StyledTypeFace(typeFace, 12));
|
||||
var letterPrinter = new TypeFacePrinter(NameToWrite.ToUpper(), new StyledTypeFace(NamedTypeFaceCache.GetTypeFace(Font), 12));
|
||||
|
||||
IObject3D nameMesh = new Object3D()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,17 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public bool Unlocked { get; } = true;
|
||||
|
||||
|
||||
static Type[] allowedTypes =
|
||||
{
|
||||
typeof(double), typeof(int), typeof(string), typeof(bool),
|
||||
typeof(NamedTypeFace)
|
||||
};
|
||||
|
||||
static BindingFlags ownedPropertiesOnly = BindingFlags.Public
|
||||
| System.Reflection.BindingFlags.Instance
|
||||
| System.Reflection.BindingFlags.DeclaredOnly;
|
||||
|
||||
public GuiWidget Create(IObject3D item, View3DWidget view3DWidget, ThemeConfig theme)
|
||||
{
|
||||
this.view3DWidget = view3DWidget;
|
||||
|
|
@ -105,12 +116,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
{
|
||||
var rebuildable = item as IRebuildable;
|
||||
|
||||
var allowedTypes = new Type[] { typeof(double), typeof(int), typeof(string), typeof(bool) };
|
||||
|
||||
var ownedPropertiesOnly = System.Reflection.BindingFlags.Public
|
||||
| System.Reflection.BindingFlags.Instance
|
||||
| System.Reflection.BindingFlags.DeclaredOnly;
|
||||
|
||||
var editableProperties = this.item.GetType().GetProperties(ownedPropertiesOnly)
|
||||
.Where(pi => allowedTypes.Contains(pi.PropertyType)
|
||||
&& pi.GetGetMethod() != null
|
||||
|
|
@ -198,6 +203,34 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
rowContainer.AddChild(textEditWidget);
|
||||
tabContainer.AddChild(rowContainer);
|
||||
}
|
||||
// create a NamedTypeFace editor
|
||||
else if (property.Value is NamedTypeFace namedTypeFace)
|
||||
{
|
||||
FlowLayoutWidget rowContainer = CreateSettingsRow(property.DisplayName.Localize());
|
||||
var availableFonts = new Dictionary<string, string>();
|
||||
foreach (NamedTypeFace name in Enum.GetValues(typeof(NamedTypeFace)))
|
||||
{
|
||||
availableFonts.Add(name.ToString(), name.ToString().Replace('_', ' '));
|
||||
}
|
||||
|
||||
var dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize);
|
||||
|
||||
foreach (var fontName in availableFonts.OrderBy((n) => n.Value))
|
||||
{
|
||||
MenuItem newItem = dropDownList.AddItem(fontName.Value);
|
||||
|
||||
var localFontName = fontName;
|
||||
newItem.Selected += (sender, e) =>
|
||||
{
|
||||
NamedTypeFace key = (NamedTypeFace)Enum.Parse(typeof(NamedTypeFace), localFontName.Key);
|
||||
property.PropertyInfo.GetSetMethod().Invoke(this.item, new Object[] { key });
|
||||
rebuildable?.Rebuild();
|
||||
};
|
||||
}
|
||||
dropDownList.SelectedValue = namedTypeFace.ToString().Replace('_', ' ');
|
||||
rowContainer.AddChild(dropDownList);
|
||||
tabContainer.AddChild(rowContainer);
|
||||
}
|
||||
}
|
||||
|
||||
var updateButton = theme.ButtonFactory.Generate("Update".Localize());
|
||||
|
|
|
|||
1185
StaticData/Fonts/Damion-Regular.svg
Normal file
1185
StaticData/Fonts/Damion-Regular.svg
Normal file
File diff suppressed because it is too large
Load diff
|
After Width: | Height: | Size: 200 KiB |
|
|
@ -1 +1 @@
|
|||
Subproject commit 75bcac66c7f8a96e81b3ebd3ae47bce89d2c6342
|
||||
Subproject commit 84ded0e232d644f5ae96f556885cfff628503312
|
||||
Loading…
Add table
Add a link
Reference in a new issue