From a3435a24e70699451641a5765f0504b2c4b772ac Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Mon, 8 Feb 2016 23:38:41 -0800 Subject: [PATCH] Added in-progress Text3D --- OSCADSharp/OSCADSharp/OSCADSharp.csproj | 1 + OSCADSharp/OSCADSharp/Text3D.cs | 94 +++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 OSCADSharp/OSCADSharp/Text3D.cs diff --git a/OSCADSharp/OSCADSharp/OSCADSharp.csproj b/OSCADSharp/OSCADSharp/OSCADSharp.csproj index ac69dc3..8289d91 100644 --- a/OSCADSharp/OSCADSharp/OSCADSharp.csproj +++ b/OSCADSharp/OSCADSharp/OSCADSharp.csproj @@ -50,6 +50,7 @@ + diff --git a/OSCADSharp/OSCADSharp/Text3D.cs b/OSCADSharp/OSCADSharp/Text3D.cs new file mode 100644 index 0000000..f27b481 --- /dev/null +++ b/OSCADSharp/OSCADSharp/Text3D.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OSCADSharp +{ + /// + /// Create text using fonts installed on the local system or provided as separate font file. + /// + public class Text3D : OSCADObject + { + /// + /// Text to display + /// + public string Text { get; set; } + + /// + /// The generated text will have approximately an ascent of the given value (height above the baseline). Default is 10. + /// Note that specific fonts will vary somewhat and may not fill the size specified exactly, usually slightly smaller. + /// + public uint Size { get; set; } + + /// + /// The name of the font that should be used. This is not the name of the font file, + /// but the logical font name (internally handled by the fontconfig library). This can also include a style parameter, see below. + /// A list of installed fonts & styles can be obtained using the font list dialog (Help -> Font List). + /// + public string Font { get; set; } + + /// + /// The horizontal alignment for the text. Possible values are "left", "center" and "right". Default is "left". + /// + /// TODO: Implement alignments + public string HorizontalAlignment { get; set; } + + /// + /// The vertical alignment for the text. Possible values are "top", "center", "baseline" and "bottom". Default is "baseline". + /// + /// TODO: Implement alignments + // public string VerticalAlignment { get; set; } + + /// + /// Factor to increase/decrease the character spacing. The default value of 1 will result in the normal spacing for the font, giving a value greater than 1 will cause the letters to be spaced further apart. + /// + public uint Spacing { get; set; } + + /// + /// Direction of the text flow. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), "ttb" (top-to-bottom) and "btt" (bottom-to-top). Default is "ltr". + /// + public string TextDirection { get; set; } + + /// + /// The language of the text. Default is "en". + /// + public string Language { get; set; } + + /// + /// Used for subdividing the curved path segments provided by freetype + /// ($fn in OpenSCAD) + /// + public int Resolution { get; set; } = 0; + + public override OSCADObject Clone() + { + throw new NotImplementedException(); + } + + private void appendValueIfExists(string name, string value, StringBuilder sb) + { + if(!String.IsNullOrEmpty(value)) + { + sb.Append(name); + sb.Append("="); + sb.Append(value); + } + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("text("); + sb.Append("\""); + sb.Append(this.Text); + sb.Append("\""); + + appendValueIfExists("font", this.Font, sb); + sb.Append(");"); + + return base.ToString(); + } + } +}