Skip to content

Commit 41a0b31

Browse files
authored
Merge pull request #627 from FastReports/sync_branch_2023.3.0
FastReport.OpenSource 2023.3.0
2 parents 9afc57b + 303d1a8 commit 41a0b31

File tree

73 files changed

+2069
-1511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2069
-1511
lines changed

FastReport.Base/Base.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ public enum Flags
148148
internal enum ObjectState : byte
149149
{
150150
None = 0,
151-
IsAncestor = 0x01,
152-
IsDesigning = 0x02,
153-
IsPrinting = 0x04,
154-
IsRunning = 0x08,
151+
IsAncestor = 1,
152+
IsDesigning = 2,
153+
IsPrinting = 4,
154+
IsRunning = 8,
155+
IsDeserializing = 16,
155156
}
156157

157158
/// <summary>
@@ -449,6 +450,17 @@ public bool IsRunning
449450
get { return GetObjectState(ObjectState.IsRunning); }
450451
}
451452

453+
/// <summary>
454+
/// Gets a value indicating whether the object is currently processed by the report engine.
455+
/// </summary>
456+
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
457+
internal bool IsDeserializing
458+
{
459+
get { return GetObjectState(ObjectState.IsDeserializing); }
460+
set { SetObjectState(ObjectState.IsDeserializing, value); }
461+
}
462+
463+
452464
/// <summary>
453465
/// Gets an original component for this object.
454466
/// </summary>
@@ -867,10 +879,18 @@ public virtual void Serialize(FRWriter writer)
867879
/// <param name="reader">Reader object.</param>
868880
public virtual void Deserialize(FRReader reader)
869881
{
870-
reader.ReadProperties(this);
871-
while (reader.NextItem())
882+
try
883+
{
884+
IsDeserializing = true;
885+
reader.ReadProperties(this);
886+
while (reader.NextItem())
887+
{
888+
DeserializeSubItems(reader);
889+
}
890+
}
891+
finally
872892
{
873-
DeserializeSubItems(reader);
893+
IsDeserializing = false;
874894
}
875895
}
876896

FastReport.Base/Export/Html/HTMLExportLayers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private string GetHref(ReportComponentBase obj)
143143
EncodeURL(obj.Hyperlink.ReportParameter),
144144
EncodeURL(obj.Hyperlink.Value));
145145
string onClick = String.Format(OnClickTemplate, ReportID, "detailed_report", url);
146-
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
146+
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
147147
}
148148
else if (obj.Hyperlink.Kind == HyperlinkKind.DetailPage)
149149
{
@@ -152,7 +152,7 @@ private string GetHref(ReportComponentBase obj)
152152
EncodeURL(obj.Hyperlink.ReportParameter),
153153
EncodeURL(obj.Hyperlink.Value));
154154
string onClick = String.Format(OnClickTemplate, ReportID, "detailed_page", url);
155-
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
155+
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
156156
}
157157
else if (SinglePage)
158158
{
@@ -170,7 +170,7 @@ private string GetHref(ReportComponentBase obj)
170170
onClick = String.Format(OnClickTemplate, ReportID, "goto", url);
171171

172172
if (onClick != String.Empty)
173-
href = String.Format("<a {0} href=\"#\" onclick=\"{1}\">", hrefStyle, onClick);
173+
href = String.Format("<a {0} onclick=\"{1}\">", hrefStyle, onClick);
174174
}
175175
}
176176
return href;

FastReport.Base/HtmlObject.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,6 @@ public override void Draw(FRPaintEventArgs e)
130130
DrawDesign(e);
131131
}
132132

133-
/// <inheritdoc/>
134-
public override void ApplyStyle(Style style)
135-
{
136-
base.ApplyStyle(style);
137-
}
138-
139-
/// <inheritdoc/>
140-
public override void SaveStyle()
141-
{
142-
base.SaveStyle();
143-
}
144-
145-
/// <inheritdoc/>
146-
public override void RestoreStyle()
147-
{
148-
base.RestoreStyle();
149-
}
150133

151134
/// <inheritdoc/>
152135
public override void Serialize(FRWriter writer)

FastReport.Base/ReportPage.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public float PaperHeight
153153
/// Gets or sets the raw index of a paper size.
154154
/// </summary>
155155
/// <remarks>
156-
/// This property stores the RawKind value of a selected papersize. It is used to distiguish
156+
/// This property stores the RawKind value of a selected papersize. It is used to distinguish
157157
/// between several papers with the same size (for ex. "A3" and "A3 with no margins") used in some
158158
/// printer drivers.
159159
/// <para/>It is not obligatory to set this property. FastReport will select the
@@ -281,6 +281,12 @@ public bool Landscape
281281
{
282282
if (landscape != value)
283283
{
284+
landscape = value;
285+
if (IsDeserializing)
286+
{
287+
return;
288+
}
289+
284290
float e = paperWidth;
285291
paperWidth = paperHeight;
286292
paperHeight = e;
@@ -305,7 +311,6 @@ public bool Landscape
305311
bottomMargin = m2;
306312
}
307313
}
308-
landscape = value;
309314
}
310315
}
311316

FastReport.Base/Utils/Config.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public static partial class Config
2828
#endif
2929
#region Private Fields
3030

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

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

120-
/// <summary>
121-
/// Gets an english culture information for localization purposes
122-
/// </summary>
123-
public static CultureInfo EngCultureInfo
124-
{
125-
get { return engCultureInfo; }
126-
}
127-
128119
/// <summary>
129120
/// Gets or sets the path used to load/save the configuration file.
130121
/// </summary>

FastReport.Base/Utils/FRPrivateFontCollection.cs

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.InteropServices;
55
using System.Drawing.Text;
66
using System.Drawing;
7+
using System.Linq;
78

89
namespace FastReport.Utils
910
{
@@ -13,8 +14,9 @@ namespace FastReport.Utils
1314
public partial class FRPrivateFontCollection
1415
{
1516
private readonly PrivateFontCollection collection = TypeConverters.FontConverter.PrivateFontCollection;
16-
private Dictionary<string, string> FontFiles = new Dictionary<string, string>();
17-
private Dictionary<string, MemoryFont> MemoryFonts = new Dictionary<string, MemoryFont>();
17+
18+
private readonly Dictionary<string, DictionaryFont> _fonts = new Dictionary<string, DictionaryFont>();
19+
1820

1921
internal PrivateFontCollection Collection { get { return collection; } }
2022

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

3638
/// <summary>
@@ -40,18 +42,11 @@ public bool HasFont(string fontName)
4042
/// <returns>Either FileStream or MemoryStream containing font data.</returns>
4143
public Stream GetFontStream(string fontName)
4244
{
43-
if (FontFiles.ContainsKey(fontName))
44-
{
45-
return new FileStream(FontFiles[fontName], FileMode.Open, FileAccess.Read);
46-
}
47-
else if (MemoryFonts.ContainsKey(fontName))
45+
if (_fonts.TryGetValue(fontName, out var font))
4846
{
49-
MemoryFont font = MemoryFonts[fontName];
50-
byte[] buffer = new byte[font.Length];
51-
Marshal.Copy(font.Memory, buffer, 0, font.Length);
52-
return new MemoryStream(buffer);
47+
return font.GetFontStream();
5348
}
54-
49+
5550
return null;
5651
}
5752

@@ -65,7 +60,8 @@ public bool AddFontFile(string filename)
6560
bool success = false;
6661
if(File.Exists(filename))
6762
{
68-
if (!FontFiles.ContainsValue(filename))
63+
// if (!FontFiles.ContainsValue(filename))
64+
if (!_fonts.Values.OfType<FontFromFile>().Any(fontFile => fontFile._filepath == filename))
6965
{
7066
collection.AddFontFile(filename);
7167
RegisterFontInternal(filename);
@@ -91,6 +87,24 @@ public bool AddFontFile(string filename)
9187
public void AddFontFromStream(Stream stream)
9288
{
9389
collection.AddFont(stream);
90+
stream.Position = 0;
91+
92+
var fontFamily = Families[Families.Length - 1];
93+
string fontName = fontFamily.Name;
94+
95+
var isBold = fontFamily.IsStyleAvailable(FontStyle.Bold);
96+
// every time is false
97+
//var isItalic = fontFamily.IsStyleAvailable(FontStyle.Italic);
98+
99+
fontName = fontName + (isBold ? "-B" : "") /*+ (isItalic ? "-I" : "")*/;
100+
101+
if (!_fonts.ContainsKey(fontName))
102+
{
103+
var ms = new MemoryStream();
104+
stream.CopyTo(ms);
105+
ms.Position = 0;
106+
_fonts.Add(fontName, new FontFromStream(ms));
107+
}
94108
}
95109
#endif
96110

@@ -103,21 +117,71 @@ public void AddMemoryFont(IntPtr memory, int length)
103117
{
104118
collection.AddMemoryFont(memory, length);
105119
string fontName = Families[Families.Length - 1].Name;
106-
if (!FontFiles.ContainsKey(fontName))
107-
MemoryFonts.Add(fontName, new MemoryFont(memory, length));
120+
if (!_fonts.ContainsKey(fontName))
121+
_fonts.Add(fontName, new MemoryFont(memory, length));
108122
}
109123

110-
private struct MemoryFont
124+
private abstract class DictionaryFont
111125
{
112-
public readonly IntPtr Memory;
113-
public readonly int Length;
126+
public abstract Stream GetFontStream();
127+
}
128+
129+
private sealed class FontFromFile : DictionaryFont
130+
{
131+
internal readonly string _filepath;
132+
133+
public FontFromFile(string filepath)
134+
{
135+
_filepath = filepath;
136+
}
137+
138+
public override Stream GetFontStream()
139+
{
140+
return new FileStream(_filepath, FileMode.Open, FileAccess.Read);
141+
}
142+
143+
public override string ToString()
144+
{
145+
return _filepath;
146+
}
147+
}
148+
149+
private sealed class FontFromStream : DictionaryFont
150+
{
151+
private readonly Stream _stream;
152+
153+
public FontFromStream(Stream stream)
154+
{
155+
_stream = stream;
156+
}
157+
158+
public override Stream GetFontStream()
159+
{
160+
var newStream = new MemoryStream();
161+
_stream.CopyTo(newStream);
162+
_stream.Position = 0;
163+
newStream.Position = 0;
164+
return newStream;
165+
}
166+
}
167+
168+
private sealed class MemoryFont : DictionaryFont
169+
{
170+
private readonly IntPtr Memory;
171+
private readonly int Length;
114172

115173
public MemoryFont(IntPtr memory, int length)
116174
{
117175
Memory = memory;
118176
Length = length;
119177
}
120-
}
121178

179+
public override Stream GetFontStream()
180+
{
181+
byte[] buffer = new byte[Length];
182+
Marshal.Copy(Memory, buffer, 0, Length);
183+
return new MemoryStream(buffer);
184+
}
185+
}
122186
}
123187
}

FastReport.Base/Utils/Json/Serialization/JsonConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static T Deserialize<T>(string json)
1515
return JsonDeserializer.Deserialize<T>(json);
1616
}
1717

18+
public static object Deserialize(string json, Type type)
19+
{
20+
return JsonDeserializer.Deserialize(json, type);
21+
}
22+
1823
public static string Serialize<T>(T instance)
1924
{
2025
return JsonSerializer.Serialize(instance);

FastReport.Base/Utils/Json/Serialization/JsonDeserializer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public static T Deserialize<T>(string json)
2424
return instance;
2525
}
2626

27+
public static object Deserialize(string json, Type type)
28+
{
29+
var instance = CreateInstance(type);
30+
DeserializeProperties(instance, json);
31+
return instance;
32+
}
33+
2734
private static object Deserialize(JsonBase jsonBase, Type type)
2835
{
2936
var instance = CreateInstance(type);

FastReport.Base/Utils/Res.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ private static void LoadBuiltinLocale()
8585
using (Stream stream = ResourceLoader.GetStream("en.xml"))
8686
{
8787
FLocale.Load(stream);
88-
CultureInfo enCulture = CultureInfo.GetCultureInfo("en");
88+
CultureInfo enCulture;
89+
try
90+
{
91+
enCulture = CultureInfo.GetCultureInfo("en");
92+
}
93+
catch // InvariantGlobalization mod fix (#939)
94+
{
95+
enCulture = CultureInfo.InvariantCulture;
96+
}
8997
CurrentCulture = enCulture;
9098
if (!LocalesCache.ContainsKey(enCulture))
9199
LocalesCache.Add(enCulture, FLocale);

0 commit comments

Comments
 (0)