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

Fix invalid style generation on systems with different cultures #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions RtfPipe/Html/CssString.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using RtfPipe.Tokens;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

@@ -33,7 +34,7 @@ public CssString(IEnumerable<IToken> tokens, ElementType elementType, IEnumerabl
if (token is Font font)
Append(font);
else if (token is FontSize fontSize)
Append("font-size", fontSize.Value.ToPt().ToString("0.#") + "pt");
Append("font-size", fontSize.Value.ToPt().ToString("0.#", CultureInfo.InvariantCulture) + "pt");
else if (token is BackgroundColor background)
Append("background", "#" + background.Value);
else if (token is ParagraphBackgroundColor backgroundPara)
@@ -104,8 +105,8 @@ public CssString(IEnumerable<IToken> tokens, ElementType elementType, IEnumerabl
{
if (tokens.OfType<LineSpacingMultiple>().Any(m => m.Value == 1))
{
if ((Math.Abs(lineSpace.Value) / 240.0).ToString("0.#") != "1")
Append("line-height", (Math.Abs(lineSpace.Value) * DefaultBrowserLineHeight / 240.0).ToString("0.#"));
if ((Math.Abs(lineSpace.Value) / 240.0).ToString("0.#", CultureInfo.InvariantCulture) != "1")
Append("line-height", (Math.Abs(lineSpace.Value) * DefaultBrowserLineHeight / 240.0).ToString("0.#", CultureInfo.InvariantCulture));
}
else if (lineSpace.Value < 0)
{
@@ -496,7 +497,7 @@ public CssString Append(string property, params UnitValue[] values)
{
if (i > 0)
_builder.Append(' ');
var px = values[i].ToPx().ToString("0.#");
var px = values[i].ToPx().ToString("0.#", CultureInfo.InvariantCulture);
_builder.Append(px);
if (px != "0")
_builder.Append("px");
3 changes: 2 additions & 1 deletion RtfPipe/Html/HtmlVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using RtfPipe.Tokens;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
@@ -532,7 +533,7 @@ private void WriteTabs(IEnumerable<IToken> parentStyles, bool newLine, int tabCo
{
var size = IndentSize(parentStyles, newLine, tabCount);
_writer.WriteStartElement("span");
_writer.WriteAttributeString("style", $"display:inline-block;width:{size.ToPx()}px");
_writer.WriteAttributeString("style", $"display:inline-block;width:{size.ToPx().ToString(CultureInfo.InvariantCulture)}px");
_writer.WriteEndElement();
}

2 changes: 1 addition & 1 deletion RtfPipe/RtfPipe.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net40;net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NeutralLanguage>en-US</NeutralLanguage>
<Authors>Eric Domke</Authors>
<Company />