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

Solving bug of error resolution "ul ol+li{fill:#000000;font-family:ZW… #574

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion Source/External/ExCSS/Model/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ internal enum GrammarSegment
Colon,
Comma,
Semicolon,
Whitespace
Whitespace,
PlusSign
}

public enum RuleType
Expand Down
12 changes: 11 additions & 1 deletion Source/External/ExCSS/Model/Values/TermList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void AddSeparator(TermSeparator termSeparator)
AddSeparator(GrammarSegment.Whitespace);
break;
}
case (TermSeparator.PlusSign):
{
AddSeparator(GrammarSegment.PlusSign);
break;
}
}
}

Expand Down Expand Up @@ -103,6 +108,10 @@ public override string ToString()
builder.Append(",");
break;

case GrammarSegment.PlusSign:
builder.Append("+");
break;

default:
throw new NotImplementedException();
}
Expand All @@ -117,7 +126,8 @@ public override string ToString()
public enum TermSeparator
{
Comma,
Space
Space,
PlusSign
}

internal void SetLastTerm(Term term)
Expand Down
5 changes: 5 additions & 0 deletions Source/External/ExCSS/Parser.Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ private bool ParseValueDelimiter(DelimiterBlock token)
_isFraction = true;
return true;

case Specification.PlusSign:
_terms.AddSeparator(TermList.TermSeparator.PlusSign);
SetParsingContext(ParsingContext.InValuePool);
return true;

default:
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Svg.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.2;net35;net452;net472</TargetFrameworks>
<PackageLicenseExpression>MS-PL</PackageLicenseExpression>
Expand Down Expand Up @@ -78,12 +78,12 @@
<Title>Svg for .Net Core 2.2</Title>
<DefineConstants>$(DefineConstants);NETCORE;NETCORE22</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<Title>Svg for .Net Standard 2.0</Title>
<DefineConstants>$(DefineConstants);NETSTANDARD;NETSTANDARD20</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net35'">
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -140,12 +140,12 @@
</ItemGroup>

<!-- Mac specific include -->

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.8.64" />
</ItemGroup>


<ItemGroup>
<Compile Remove=".\External\ExCSS\Parser.generated.cs" />
<Compile Remove=".\External\ExCSS\ParserX.cs" />
Expand Down
50 changes: 44 additions & 6 deletions Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class SvgDocument : SvgFragment, ITypeDescriptorContext
private SvgElementIdManager _idManager;

private Dictionary<string, IEnumerable<SvgFontFace>> _fontDefns = null;
private PrivateFontCollection _privateFonts = null;
private IList<FontFaceRule> _fontFaceDirectives = null;

private static int GetSystemDpi()
{
Expand All @@ -36,7 +38,7 @@ private static int GetSystemDpi()
isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
var platform = Environment.OSVersion.Platform;
isWindows = platform == PlatformID.Win32NT;
isWindows = platform == PlatformID.Win32NT;
#endif

if (isWindows)
Expand Down Expand Up @@ -74,6 +76,33 @@ group f by f.FontFamily into family
}
return _fontDefns;
}
internal FontFamily[] PrivateFontDefns()
{
if (_privateFonts == null)
{
_privateFonts = new PrivateFontCollection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is remarks in the API reference.
What do you think about this ?

if (_fontFaceDirectives != null)
{
foreach (var item in _fontFaceDirectives)
{
try
{
var bytes = downBytes(item.Src, this.BaseUri);

IntPtr MeAdd = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, MeAdd, bytes.Length);
_privateFonts.AddMemoryFont(MeAdd, bytes.Length);
}
catch (Exception ex)
{
Trace.TraceWarning(ex.Message);
}
}
}
}
return _privateFonts.Families;
}


/// <summary>
/// Initializes a new instance of the <see cref="SvgDocument"/> class.
Expand Down Expand Up @@ -182,15 +211,15 @@ public virtual TSvgElement GetElementById<TSvgElement>(string id) where TSvgElem
/// <returns>Boolean whether the system is capable of using GDI+</returns>
public static bool SystemIsGdiPlusCapable()
{
try
try
{
EnsureSystemIsGdiPlusCapable();
}
catch(SvgGdiPlusCannotBeLoadedException)
catch (SvgGdiPlusCannotBeLoadedException)
{
return false;
}
catch(Exception)
catch (Exception)
{
//If somehow another type of exception is raised by the ensure function we will let it bubble up, since that might indicate other issues/problems
throw;
Expand Down Expand Up @@ -218,7 +247,7 @@ public static void EnsureSystemIsGdiPlusCapable()
throw new SvgGdiPlusCannotBeLoadedException(e);
}
//If the Matrix creation is causing another type of exception we should just raise that one
throw;
throw;
}
}

Expand Down Expand Up @@ -482,12 +511,21 @@ public static SvgDocument Open(string path)
}
}
}

svgDocument._fontFaceDirectives = sheet.FontFaceDirectives;
}

svgDocument?.FlushStyles(true);
return svgDocument;
}

private static byte[] downBytes(string url, Uri baseUri)
{
var urlString = Utility.GetUrlString(url);
var uri = new Uri(urlString, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri && baseUri != null)
uri = new Uri(baseUri, uri);
return Utility.GetBytesFromUri(uri)?.DataBytes;
}
/// <summary>
/// Opens an SVG document from the specified <see cref="XmlDocument"/>.
/// </summary>
Expand Down
Loading