Skip to content

Commit

Permalink
fix(mod): Fix RTF exporter not supporting all Unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
AamuLumi committed Jul 7, 2023
1 parent cba5f09 commit c25e4f5
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 91 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>aamu.diary</identifier>
<version>1.1.6</version>
<version>1.1.7</version>
<dependencies>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
Expand Down
Binary file modified Assemblies/Diary.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.7 (07/07/2023)

- Fix RTF Exporter not supporting all Unicode characters

# 1.1.6 (06/16/2023)

- Add a button to open the images directory
Expand Down
139 changes: 69 additions & 70 deletions Source/Librairies/RTF/RTFDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
namespace RTFExporter
{
/// <summary>
/// The document margin
/// The document margin
/// </summary>
public class Margin
{
public float bottom;
public float left;
public float right;
public float top;
public float bottom;

/// <summary>
/// Margin constructor. All values need to be declared
/// Margin constructor. All values need to be declared
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
Expand All @@ -31,7 +31,7 @@ public Margin(float left, float right, float top, float bottom)
}

/// <summary>
/// Page orientation setup
/// Page orientation setup
/// </summary>
public enum Orientation
{
Expand All @@ -40,7 +40,7 @@ public enum Orientation
}

/// <summary>
/// Page measure units
/// Page measure units
/// </summary>
public enum Units
{
Expand All @@ -50,34 +50,34 @@ public enum Units
}

/// <summary>
/// The RTF document, it is the main class and use a IDisposable interface
/// The RTF document, it is the main class and use a IDisposable interface
/// </summary>
public class RTFDocument : IDisposable
{
public List<RTFParagraph> paragraphs = new List<RTFParagraph>();
public string author;
public List<Color> colors = new List<Color>();
private FileStream fileStream;
public List<string> fonts = new List<string>();
public string author;
public float width;
public float height;
public Orientation orientation;
public List<string> keywords = new List<string>();
public Margin margin;
public Units units;
private FileStream fileStream;
public Orientation orientation;
public List<RTFParagraph> paragraphs = new List<RTFParagraph>();
private StreamWriter streamWriter;
public Units units;
public int version = 1;
public List<string> keywords = new List<string>();
public float width;

/// <summary>
/// The simple RTF Document constructor without use streams
/// The simple RTF Document constructor without use streams
/// </summary>
public RTFDocument()
{
Init(8, 11, Orientation.Portrait, Units.Inch);
}

/// <summary>
/// The RTF Document constructor with a file path
/// The RTF Document constructor with a file path
/// </summary>
/// <param name="path">A path to a folder with file name</param>
public RTFDocument(string path)
Expand All @@ -87,7 +87,7 @@ public RTFDocument(string path)
}

/// <summary>
/// The RTF Document constructor with a file stream
/// The RTF Document constructor with a file stream
/// </summary>
/// <param name="fileStream">A file stream</param>
public RTFDocument(FileStream fileStream)
Expand All @@ -97,9 +97,9 @@ public RTFDocument(FileStream fileStream)
}

/// <summary>
/// RTF document constructor with setup parameters
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// RTF document constructor with setup parameters
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// </summary>
/// <param name="path">A path to a folder with file name</param>
/// <param name="width">the width of the page</param>
Expand All @@ -119,9 +119,9 @@ public RTFDocument(FileStream fileStream)
}

/// <summary>
/// RTF document constructor with setup parameters without use streams
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// RTF document constructor with setup parameters without use streams
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// </summary>
/// <param name="fileStream">A file stream</param>
/// <param name="width">the width of the page</param>
Expand All @@ -141,9 +141,9 @@ public RTFDocument(FileStream fileStream)
}

/// <summary>
/// RTF document constructor with setup parameters
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// RTF document constructor with setup parameters
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// </summary>
/// <param name="width">the width of the page</param>
/// <param name="height">the height of the page</param>
Expand All @@ -160,7 +160,19 @@ public RTFDocument(FileStream fileStream)
}

/// <summary>
/// Set a file by path and allocate it stream
/// The dispose routine. It save and close the streams (StreamWriter, FileStream)
/// </summary>
public void Dispose()
{
if (fileStream != null && streamWriter != null)
{
Save();
Close();
}
}

/// <summary>
/// Set a file by path and allocate it stream
/// </summary>
/// <param name="path">A path to a folder with file name</param>
public void SetFile(string path)
Expand All @@ -170,7 +182,7 @@ public void SetFile(string path)
}

/// <summary>
/// Use a file stream directly
/// Use a file stream directly
/// </summary>
/// <param name="fileStream">A file stream</param>
public void SetStream(FileStream fileStream)
Expand All @@ -180,9 +192,9 @@ public void SetStream(FileStream fileStream)
}

/// <summary>
/// RTF document init method to use after a simple constructor
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// RTF document init method to use after a simple constructor
/// <seealso cref="RTFExporter.Orientation">
/// <seealso cref="RTFExporter.Units">
/// </summary>
/// <param name="width">the width of the page</param>
/// <param name="height">the height of the page</param>
Expand Down Expand Up @@ -210,7 +222,7 @@ public void Init(float width, float height, Orientation orientation, Units units
}

/// <summary>
/// A method to set the margin of the document
/// A method to set the margin of the document
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
Expand All @@ -225,48 +237,48 @@ public void SetMargin(float left, float right, float top, float bottom)
}

/// <summary>
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// </summary>
/// <returns>The appended paragraph</returns>
public RTFParagraph AppendParagraph()
{
RTFParagraph paragraph = new RTFParagraph(this);
var paragraph = new RTFParagraph(this);
return paragraph;
}

/// <summary>
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.RTFParagraphStyle">
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.RTFParagraphStyle">
/// </summary>
/// <param name="style">A paragraph style object</param>
/// <returns>The appended paragraph</returns>
public RTFParagraph AppendParagraph(RTFParagraphStyle style)
{
RTFParagraph paragraph = new RTFParagraph(this);
var paragraph = new RTFParagraph(this);
paragraph.style = style;
return paragraph;
}

/// <summary>
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// </summary>
/// <param name="alignment">A paragraph alignment object</param>
/// <returns>The appended paragraph</returns>
public RTFParagraph AppendParagraph(Alignment alignment)
{
RTFParagraph paragraph = new RTFParagraph(this);
var paragraph = new RTFParagraph(this);
paragraph.style = new RTFParagraphStyle(alignment);
return paragraph;
}

/// <summary>
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Indent">
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Indent">
/// </summary>
/// <param name="indent">A paragraph indent object</param>
/// <returns>The appended paragraph</returns>
Expand All @@ -276,26 +288,25 @@ public RTFParagraph AppendParagraph(Indent indent)
}

/// <summary>
///
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// <seealso cref="RTFExporter.Indent">
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// <seealso cref="RTFExporter.Indent">
/// </summary>
/// <param name="alignment">A paragraph alignment object</param>
/// <param name="indent">A paragraph indent object</param>
/// <returns>The appended paragraph</returns>
public RTFParagraph AppendParagraph(Alignment alignment, Indent indent)
{
RTFParagraph paragraph = new RTFParagraph(this);
var paragraph = new RTFParagraph(this);
paragraph.style = new RTFParagraphStyle(alignment, indent);
return paragraph;
}

/// <summary>
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// <seealso cref="RTFExporter.Indent">
/// Append a new paragraph to the document
/// <seealso cref="RTFExporter.RTFParagraph">
/// <seealso cref="RTFExporter.Alignment">
/// <seealso cref="RTFExporter.Indent">
/// </summary>
/// <param name="alignment">A paragraph alignment object</param>
/// <param name="indent">A paragraph indent object</param>
Expand All @@ -309,13 +320,13 @@ public RTFParagraph AppendParagraph(Alignment alignment, Indent indent)
int spaceAfter
)
{
RTFParagraph paragraph = new RTFParagraph(this);
var paragraph = new RTFParagraph(this);
paragraph.style = new RTFParagraphStyle(alignment, indent, spaceBefore, spaceAfter);
return paragraph;
}

/// <summary>
/// Close the streams (StreamWriter, FileStream)
/// Close the streams (StreamWriter, FileStream)
/// </summary>
public void Close()
{
Expand All @@ -324,23 +335,11 @@ public void Close()
}

/// <summary>
/// Save the values to the file
/// Save the values to the file
/// </summary>
public void Save()
{
streamWriter.Write(RTFParser.ToString(this));
}

/// <summary>
/// The dispose routine. It save and close the streams (StreamWriter, FileStream)
/// </summary>
public void Dispose()
{
if (fileStream != null && streamWriter != null)
{
Save();
Close();
}
}
}
}
}

0 comments on commit c25e4f5

Please sign in to comment.