Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Rendering Text as Paths in PDF Generation #214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ namespace MigraDoc.DocumentObjectModel.Fields
/// <summary>
/// DateField is used to reference the date and time the printing starts.
/// </summary>
public class DateField : DocumentObject
public class DateField : TextBasedDocumentObject
{
/// <summary>
/// Initializes a new instance of the DateField class.
/// </summary>
public DateField()
public DateField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new DateFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the DateField class with the specified parent.
/// </summary>
internal DateField(DocumentObject parent) : base(parent)
internal DateField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new DateFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ namespace MigraDoc.DocumentObjectModel.Fields
/// <summary>
/// InfoField is used to reference one of the DocumentInfo fields in the document.
/// </summary>
public class InfoField : DocumentObject
public class InfoField : TextBasedDocumentObject
{
/// <summary>
/// Initializes a new instance of the InfoField class.
/// </summary>
public InfoField()
public InfoField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new InfoFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the InfoField class with the specified parent.
/// </summary>
internal InfoField(DocumentObject parent) : base(parent)
internal InfoField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new InfoFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class NumPagesField : NumericFieldBase
/// <summary>
/// Initializes a new instance of the NumPagesField class.
/// </summary>
public NumPagesField()
public NumPagesField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new NumPagesFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the NumPagesField class with the specified parent.
/// </summary>
internal NumPagesField(DocumentObject parent) : base(parent)
internal NumPagesField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new NumPagesFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ namespace MigraDoc.DocumentObjectModel.Fields
/// NumericFieldBase serves as a base for Numeric fields, which are:
/// NumPagesField, PageField, PageRefField, SectionField, SectionPagesField
/// </summary>
public abstract class NumericFieldBase : DocumentObject
public abstract class NumericFieldBase : TextBasedDocumentObject
{
/// <summary>
/// The valid format strings for the supported numeric types.
/// </summary>
protected static readonly string[] ValidFormatStrings =
[
{
"",
"ROMAN",
"roman",
"ALPHABETIC",
"alphabetic"
];
};

/// <summary>
/// Initializes a new instance of the NumericFieldBase class.
/// </summary>
internal NumericFieldBase()
internal NumericFieldBase(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{ }

/// <summary>
/// Initializes a new instance of the NumericFieldBase class with the specified parent.
/// </summary>
internal NumericFieldBase(DocumentObject parent) : base(parent)
internal NumericFieldBase(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{ }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class PageField : NumericFieldBase
/// <summary>
/// Initializes a new instance of the PageField class.
/// </summary>
public PageField()
public PageField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new PageFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the PageField class with the specified parent.
/// </summary>
internal PageField(DocumentObject parent) : base(parent)
internal PageField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new PageFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ public class PageRefField : NumericFieldBase
/// <summary>
/// Initializes a new instance of the PageRefField class.
/// </summary>
public PageRefField()
public PageRefField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new PageRefFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the PageRefField class with the necessary bookmark name.
/// </summary>
public PageRefField(string name) : this()
public PageRefField(string name, TextRenderOption textRenderOption = TextRenderOption.Default) : this(textRenderOption)
{
Name = name;
}

/// <summary>
/// Initializes a new instance of the PageRefField class with the specified parent.
/// </summary>
internal PageRefField(DocumentObject parent) : base(parent)
internal PageRefField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{ }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class SectionField : NumericFieldBase
/// <summary>
/// Initializes a new instance of the SectionField class.
/// </summary>
public SectionField()
public SectionField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new SectionFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the SectionField class with the specified parent.
/// </summary>
internal SectionField(DocumentObject parent) : base(parent)
internal SectionField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new SectionFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class SectionPagesField : NumericFieldBase
/// <summary>
/// Initializes a new instance of the SectionPagesField class.
/// </summary>
public SectionPagesField()
public SectionPagesField(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new SectionPagesFieldValues(this);
}

/// <summary>
/// Initializes a new instance of the SectionPagesField class with the specified parent.
/// </summary>
internal SectionPagesField(DocumentObject parent) : base(parent)
internal SectionPagesField(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new SectionPagesFieldValues(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public Paragraph AddParagraph()
/// <summary>
/// Adds a new paragraph with the specified text to the text area.
/// </summary>
public Paragraph AddParagraph(string paragraphText)
public Paragraph AddParagraph(string paragraphText, TextRenderOption textRenderOption = TextRenderOption.Default)
{
return Elements.AddParagraph(paragraphText);
return Elements.AddParagraph(paragraphText, textRenderOption);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public Paragraph AddParagraph()
/// <summary>
/// Adds a new paragraph with the specified text to the text frame.
/// </summary>
public Paragraph AddParagraph(string paragraphText)
=> Elements.AddParagraph(paragraphText);
public Paragraph AddParagraph(string paragraphText, TextRenderOption textRenderOption = TextRenderOption.Default)
=> Elements.AddParagraph(paragraphText, textRenderOption);

/// <summary>
/// Adds a new chart with the specified type to the text frame.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public Paragraph AddParagraph()
/// <summary>
/// Adds a new paragraph with the specified text to the cell.
/// </summary>
public Paragraph AddParagraph(string paragraphText)
=> Elements.AddParagraph(paragraphText);
public Paragraph AddParagraph(string paragraphText, TextRenderOption textRenderOption = TextRenderOption.Default)
=> Elements.AddParagraph(paragraphText, textRenderOption);

/// <summary>
/// Adds a new chart with the specified type to the cell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
case '\t':
if (currentString.Length > 0)
{
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString()));
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString(), text.TextRenderOption));
++insertedObjects;
currentString.Clear();
}
elements.InsertObject(idx + insertedObjects, new Text(" "));
elements.InsertObject(idx + insertedObjects, new Text(" ", text.TextRenderOption));
++insertedObjects;
break;

Expand Down Expand Up @@ -141,7 +141,7 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
// Only start new Text if minus is not a sign, because numbers like "-5.5" have to be stored in one Text for correct DecimalTab alignment.
if (!isSign)
{
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString()));
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString(), text.TextRenderOption));
++insertedObjects;
currentString.Clear();
}
Expand All @@ -152,7 +152,7 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
case '\u200C': // zero width non-joiner.
if (currentString.Length > 0)
{
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString()));
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString(), text.TextRenderOption));
++insertedObjects;
currentString.Clear();
}
Expand All @@ -161,11 +161,11 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
case '\u00AD': // soft hyphen.
if (currentString.Length > 0)
{
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString()));
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString(), text.TextRenderOption));
++insertedObjects;
currentString.Clear();
}
elements.InsertObject(idx + insertedObjects, new Text("\u00AD"));
elements.InsertObject(idx + insertedObjects, new Text("\u00AD", text.TextRenderOption));
++insertedObjects;
//currentString = "";
break;
Expand All @@ -177,7 +177,7 @@ internal override void VisitDocumentObjectCollection(DocumentObjectCollection el
}
if (currentString.Length > 0)
{
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString()));
elements.InsertObject(idx + insertedObjects, new Text(currentString.ToString(), text.TextRenderOption));
++insertedObjects;
}
elements.RemoveObjectAt(idx + insertedObjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MigraDoc.DocumentObjectModel
/// Represents a special character in paragraph text.
/// </summary>
// TODO_OLD: Change this class and store symbolName and char in different fields.
public class Character : DocumentObject
public class Character : TextBasedDocumentObject
{
// ===== \space =====
/// <summary>
Expand Down Expand Up @@ -87,23 +87,23 @@ public class Character : DocumentObject
/// <summary>
/// Initializes a new instance of the Character class.
/// </summary>
public Character()
public Character(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new CharacterValues(this);
}

/// <summary>
/// Initializes a new instance of the Character class with the specified parent.
/// </summary>
internal Character(DocumentObject parent) : base(parent)
internal Character(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new CharacterValues(this);
}

/// <summary>
/// Initializes a new instance of the Character class with the specified SymbolName.
/// </summary>
Character(SymbolName name) : this()
Character(SymbolName name, TextRenderOption textRenderOption = TextRenderOption.Default) : this(textRenderOption)
{
Values.SymbolName = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public Paragraph AddParagraph()
/// <summary>
/// Adds a new paragraph with the specified text to the collection.
/// </summary>
public Paragraph AddParagraph(string text)
public Paragraph AddParagraph(string text, TextRenderOption textRenderOption = TextRenderOption.Default)
{
var paragraph = new Paragraph();
paragraph.AddText(text);
paragraph.AddText(text, textRenderOption);
Add(paragraph);
return paragraph;
}

/// <summary>
/// Adds a new paragraph with the specified text and style to the collection.
/// </summary>
public Paragraph AddParagraph(string text, string style)
public Paragraph AddParagraph(string text, string style, TextRenderOption textRenderOption = TextRenderOption.Default)
{
var paragraph = new Paragraph();
paragraph.AddText(text);
paragraph.AddText(text, textRenderOption);
paragraph.Style = style;
Add(paragraph);
return paragraph;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace MigraDoc.DocumentObjectModel
/// <summary>
/// Represents a footnote in a paragraph.
/// </summary>
public class Footnote : DocumentObject, IVisitable
public class Footnote : TextBasedDocumentObject, IVisitable
{
/// <summary>
/// Initializes a new instance of the Footnote class.
/// </summary>
public Footnote()
public Footnote(TextRenderOption textRenderOption = TextRenderOption.Default) : base(textRenderOption)
{
BaseValues = new FootnoteValues(this);
//NYI: Nested footnote check!
Expand All @@ -24,17 +24,17 @@ public Footnote()
/// <summary>
/// Initializes a new instance of the Footnote class with the specified parent.
/// </summary>
internal Footnote(DocumentObject parent) : base(parent)
internal Footnote(DocumentObject parent, TextRenderOption textRenderOption = TextRenderOption.Default) : base(parent, textRenderOption)
{
BaseValues = new FootnoteValues(this);
}

/// <summary>
/// Initializes a new instance of the Footnote class with a text the Footnote shall contain.
/// </summary>
internal Footnote(string content) : this()
internal Footnote(string content, TextRenderOption textRenderOption = TextRenderOption.Default) : this(textRenderOption)
{
Elements.AddParagraph(content);
Elements.AddParagraph(content, textRenderOption);
}

/// <summary>
Expand Down Expand Up @@ -71,8 +71,8 @@ public Paragraph AddParagraph()
/// <summary>
/// Adds a new paragraph with the specified text to the footnote.
/// </summary>
public Paragraph AddParagraph(string text)
=> Elements.AddParagraph(text);
public Paragraph AddParagraph(string text, TextRenderOption textRenderOption = TextRenderOption.Default)
=> Elements.AddParagraph(text, textRenderOption);

/// <summary>
/// Adds a new table to the footnote.
Expand Down
Loading