Skip to content

Commit

Permalink
Merge pull request #627 from FastReports/sync_branch_2023.3.0
Browse files Browse the repository at this point in the history
FastReport.OpenSource 2023.3.0
  • Loading branch information
0legK authored Sep 11, 2023
2 parents 9afc57b + 303d1a8 commit 41a0b31
Show file tree
Hide file tree
Showing 73 changed files with 2,069 additions and 1,511 deletions.
34 changes: 27 additions & 7 deletions FastReport.Base/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ public enum Flags
internal enum ObjectState : byte
{
None = 0,
IsAncestor = 0x01,
IsDesigning = 0x02,
IsPrinting = 0x04,
IsRunning = 0x08,
IsAncestor = 1,
IsDesigning = 2,
IsPrinting = 4,
IsRunning = 8,
IsDeserializing = 16,
}

/// <summary>
Expand Down Expand Up @@ -449,6 +450,17 @@ public bool IsRunning
get { return GetObjectState(ObjectState.IsRunning); }
}

/// <summary>
/// Gets a value indicating whether the object is currently processed by the report engine.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal bool IsDeserializing
{
get { return GetObjectState(ObjectState.IsDeserializing); }
set { SetObjectState(ObjectState.IsDeserializing, value); }
}


/// <summary>
/// Gets an original component for this object.
/// </summary>
Expand Down Expand Up @@ -867,10 +879,18 @@ public virtual void Serialize(FRWriter writer)
/// <param name="reader">Reader object.</param>
public virtual void Deserialize(FRReader reader)
{
reader.ReadProperties(this);
while (reader.NextItem())
try
{
IsDeserializing = true;
reader.ReadProperties(this);
while (reader.NextItem())
{
DeserializeSubItems(reader);
}
}
finally
{
DeserializeSubItems(reader);
IsDeserializing = false;
}
}

Expand Down
6 changes: 3 additions & 3 deletions FastReport.Base/Export/Html/HTMLExportLayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private string GetHref(ReportComponentBase obj)
EncodeURL(obj.Hyperlink.ReportParameter),
EncodeURL(obj.Hyperlink.Value));
string onClick = String.Format(OnClickTemplate, ReportID, "detailed_report", url);
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
}
else if (obj.Hyperlink.Kind == HyperlinkKind.DetailPage)
{
Expand All @@ -152,7 +152,7 @@ private string GetHref(ReportComponentBase obj)
EncodeURL(obj.Hyperlink.ReportParameter),
EncodeURL(obj.Hyperlink.Value));
string onClick = String.Format(OnClickTemplate, ReportID, "detailed_page", url);
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
}
else if (SinglePage)
{
Expand All @@ -170,7 +170,7 @@ private string GetHref(ReportComponentBase obj)
onClick = String.Format(OnClickTemplate, ReportID, "goto", url);

if (onClick != String.Empty)
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
}
}
return href;
Expand Down
17 changes: 0 additions & 17 deletions FastReport.Base/HtmlObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,6 @@ public override void Draw(FRPaintEventArgs e)
DrawDesign(e);
}

/// <inheritdoc/>
public override void ApplyStyle(Style style)
{
base.ApplyStyle(style);
}

/// <inheritdoc/>
public override void SaveStyle()
{
base.SaveStyle();
}

/// <inheritdoc/>
public override void RestoreStyle()
{
base.RestoreStyle();
}

/// <inheritdoc/>
public override void Serialize(FRWriter writer)
Expand Down
9 changes: 7 additions & 2 deletions FastReport.Base/ReportPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public float PaperHeight
/// Gets or sets the raw index of a paper size.
/// </summary>
/// <remarks>
/// This property stores the RawKind value of a selected papersize. It is used to distiguish
/// This property stores the RawKind value of a selected papersize. It is used to distinguish
/// between several papers with the same size (for ex. "A3" and "A3 with no margins") used in some
/// printer drivers.
/// <para/>It is not obligatory to set this property. FastReport will select the
Expand Down Expand Up @@ -281,6 +281,12 @@ public bool Landscape
{
if (landscape != value)
{
landscape = value;
if (IsDeserializing)
{
return;
}

float e = paperWidth;
paperWidth = paperHeight;
paperHeight = e;
Expand All @@ -305,7 +311,6 @@ public bool Landscape
bottomMargin = m2;
}
}
landscape = value;
}
}

Expand Down
9 changes: 0 additions & 9 deletions FastReport.Base/Utils/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public static partial class Config
#endif
#region Private Fields

private static readonly CultureInfo engCultureInfo = new CultureInfo("en-US");
private static readonly XmlDocument FDoc = new XmlDocument();

private static readonly string version = typeof(Report).Assembly.GetName().Version.ToString(3);
Expand Down Expand Up @@ -117,14 +116,6 @@ public static string ApplicationFolder
}
}

/// <summary>
/// Gets an english culture information for localization purposes
/// </summary>
public static CultureInfo EngCultureInfo
{
get { return engCultureInfo; }
}

/// <summary>
/// Gets or sets the path used to load/save the configuration file.
/// </summary>
Expand Down
104 changes: 84 additions & 20 deletions FastReport.Base/Utils/FRPrivateFontCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using System.Drawing.Text;
using System.Drawing;
using System.Linq;

namespace FastReport.Utils
{
Expand All @@ -13,8 +14,9 @@ namespace FastReport.Utils
public partial class FRPrivateFontCollection
{
private readonly PrivateFontCollection collection = TypeConverters.FontConverter.PrivateFontCollection;
private Dictionary<string, string> FontFiles = new Dictionary<string, string>();
private Dictionary<string, MemoryFont> MemoryFonts = new Dictionary<string, MemoryFont>();

private readonly Dictionary<string, DictionaryFont> _fonts = new Dictionary<string, DictionaryFont>();


internal PrivateFontCollection Collection { get { return collection; } }

Expand All @@ -30,7 +32,7 @@ public partial class FRPrivateFontCollection
/// <returns>true if the font is contained in this collection.</returns>
public bool HasFont(string fontName)
{
return FontFiles.ContainsKey(fontName) || MemoryFonts.ContainsKey(fontName);
return _fonts.ContainsKey(fontName);
}

/// <summary>
Expand All @@ -40,18 +42,11 @@ public bool HasFont(string fontName)
/// <returns>Either FileStream or MemoryStream containing font data.</returns>
public Stream GetFontStream(string fontName)
{
if (FontFiles.ContainsKey(fontName))
{
return new FileStream(FontFiles[fontName], FileMode.Open, FileAccess.Read);
}
else if (MemoryFonts.ContainsKey(fontName))
if (_fonts.TryGetValue(fontName, out var font))
{
MemoryFont font = MemoryFonts[fontName];
byte[] buffer = new byte[font.Length];
Marshal.Copy(font.Memory, buffer, 0, font.Length);
return new MemoryStream(buffer);
return font.GetFontStream();
}

return null;
}

Expand All @@ -65,7 +60,8 @@ public bool AddFontFile(string filename)
bool success = false;
if(File.Exists(filename))
{
if (!FontFiles.ContainsValue(filename))
// if (!FontFiles.ContainsValue(filename))
if (!_fonts.Values.OfType<FontFromFile>().Any(fontFile => fontFile._filepath == filename))
{
collection.AddFontFile(filename);
RegisterFontInternal(filename);
Expand All @@ -91,6 +87,24 @@ public bool AddFontFile(string filename)
public void AddFontFromStream(Stream stream)
{
collection.AddFont(stream);
stream.Position = 0;

var fontFamily = Families[Families.Length - 1];
string fontName = fontFamily.Name;

var isBold = fontFamily.IsStyleAvailable(FontStyle.Bold);
// every time is false
//var isItalic = fontFamily.IsStyleAvailable(FontStyle.Italic);

fontName = fontName + (isBold ? "-B" : "") /*+ (isItalic ? "-I" : "")*/;

if (!_fonts.ContainsKey(fontName))
{
var ms = new MemoryStream();
stream.CopyTo(ms);
ms.Position = 0;
_fonts.Add(fontName, new FontFromStream(ms));
}
}
#endif

Expand All @@ -103,21 +117,71 @@ public void AddMemoryFont(IntPtr memory, int length)
{
collection.AddMemoryFont(memory, length);
string fontName = Families[Families.Length - 1].Name;
if (!FontFiles.ContainsKey(fontName))
MemoryFonts.Add(fontName, new MemoryFont(memory, length));
if (!_fonts.ContainsKey(fontName))
_fonts.Add(fontName, new MemoryFont(memory, length));
}

private struct MemoryFont
private abstract class DictionaryFont
{
public readonly IntPtr Memory;
public readonly int Length;
public abstract Stream GetFontStream();
}

private sealed class FontFromFile : DictionaryFont
{
internal readonly string _filepath;

public FontFromFile(string filepath)
{
_filepath = filepath;
}

public override Stream GetFontStream()
{
return new FileStream(_filepath, FileMode.Open, FileAccess.Read);
}

public override string ToString()
{
return _filepath;
}
}

private sealed class FontFromStream : DictionaryFont
{
private readonly Stream _stream;

public FontFromStream(Stream stream)
{
_stream = stream;
}

public override Stream GetFontStream()
{
var newStream = new MemoryStream();
_stream.CopyTo(newStream);
_stream.Position = 0;
newStream.Position = 0;
return newStream;
}
}

private sealed class MemoryFont : DictionaryFont
{
private readonly IntPtr Memory;
private readonly int Length;

public MemoryFont(IntPtr memory, int length)
{
Memory = memory;
Length = length;
}
}

public override Stream GetFontStream()
{
byte[] buffer = new byte[Length];
Marshal.Copy(Memory, buffer, 0, Length);
return new MemoryStream(buffer);
}
}
}
}
5 changes: 5 additions & 0 deletions FastReport.Base/Utils/Json/Serialization/JsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static T Deserialize<T>(string json)
return JsonDeserializer.Deserialize<T>(json);
}

public static object Deserialize(string json, Type type)
{
return JsonDeserializer.Deserialize(json, type);
}

public static string Serialize<T>(T instance)
{
return JsonSerializer.Serialize(instance);
Expand Down
7 changes: 7 additions & 0 deletions FastReport.Base/Utils/Json/Serialization/JsonDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public static T Deserialize<T>(string json)
return instance;
}

public static object Deserialize(string json, Type type)
{
var instance = CreateInstance(type);
DeserializeProperties(instance, json);
return instance;
}

private static object Deserialize(JsonBase jsonBase, Type type)
{
var instance = CreateInstance(type);
Expand Down
10 changes: 9 additions & 1 deletion FastReport.Base/Utils/Res.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ private static void LoadBuiltinLocale()
using (Stream stream = ResourceLoader.GetStream("en.xml"))
{
FLocale.Load(stream);
CultureInfo enCulture = CultureInfo.GetCultureInfo("en");
CultureInfo enCulture;
try
{
enCulture = CultureInfo.GetCultureInfo("en");
}
catch // InvariantGlobalization mod fix (#939)
{
enCulture = CultureInfo.InvariantCulture;
}
CurrentCulture = enCulture;
if (!LocalesCache.ContainsKey(enCulture))
LocalesCache.Add(enCulture, FLocale);
Expand Down
Loading

0 comments on commit 41a0b31

Please sign in to comment.