Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/Text.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using Autodesk.DesignScript.Geometry;
Expand All @@ -9,18 +11,29 @@ namespace DynamoText
{
public static class Text
{
public static IEnumerable<Curve> FromStringOriginAndScale(string text, Point origin, double scale)
public static IEnumerable<Curve> FromStringOriginAndScale(
string text,
Point origin,
double scale,
string fontFamily = "Arial",
bool bold = false,
bool italic = false)
{
//http://msdn.microsoft.com/en-us/library/ms745816(v=vs.110).aspx

var crvs = new List<Curve>();

var font = new System.Windows.Media.FontFamily("Arial");
var fontStyle = FontStyles.Normal;
var fontWeight = FontWeights.Medium;
// Validate that the font family exists
if (!Fonts.SystemFontFamilies.Any(f => f.Source.Equals(fontFamily, StringComparison.OrdinalIgnoreCase)))
{
throw new ArgumentException(
$"Font family '{fontFamily}' not found. Use GetInstalledFontNames() to get a list of available fonts.",
nameof(fontFamily));
}

//if (Bold == true) fontWeight = FontWeights.Bold;
//if (Italic == true) fontStyle = FontStyles.Italic;
var font = new System.Windows.Media.FontFamily(fontFamily);
var fontStyle = italic ? FontStyles.Italic : FontStyles.Normal;
var fontWeight = bold ? FontWeights.Bold : FontWeights.Medium;

// Create the formatted text based on the properties set.
var formattedText = new FormattedText(
Expand Down Expand Up @@ -73,6 +86,14 @@ public static IEnumerable<Curve> FromStringOriginAndScale(string text, Point ori
return crvs;
}

public static IList<string> GetInstalledFontNames()
{
return Fonts.SystemFontFamilies
.Select(f => f.Source)
.OrderBy(name => name, StringComparer.OrdinalIgnoreCase)
.ToList();
}

private static Line LineBetweenPoints(Point origin, double scale, System.Windows.Point a, System.Windows.Point b)
{
var pt1 = Point.ByCoordinates((a.X * scale) + origin.X, ((-a.Y + 1) * scale) + origin.Y, origin.Z);
Expand Down
Loading