-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 11.0.183
- Loading branch information
Showing
1,380 changed files
with
112,449 additions
and
8,953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using OSPSuite.Utility.Collections; | ||
using DevExpress.Utils.Svg; | ||
|
||
namespace OSPSuite.Assets | ||
{ | ||
public class ApplicationIcon | ||
{ | ||
private readonly Icon _masterIcon; | ||
private IconHeader _iconHeader; | ||
private MemoryStream _icoStream; | ||
private readonly IList<IconEntry> _iconEntries = new List<IconEntry>(); | ||
private readonly ICache<IconSize, Icon> _iconCache = new Cache<IconSize, Icon>(); | ||
private readonly ICache<IconSize, Bitmap> _imageCache = new Cache<IconSize, Bitmap>(); | ||
private readonly SvgImage _image; | ||
private readonly SvgBitmap _bitmap; | ||
|
||
public string IconName { get; set; } | ||
public IconSize IconSize { get; set; } | ||
public int Index { get; set; } | ||
|
||
public ApplicationIcon(byte[] bytes): this(bytesToIcon(bytes)) | ||
public ApplicationIcon(byte[] bytes) : this(bytesToImage(bytes)) | ||
{ | ||
} | ||
|
||
public ApplicationIcon(Icon icon) | ||
public ApplicationIcon(SvgImage image) | ||
{ | ||
_masterIcon = icon; | ||
_image = image; | ||
_bitmap = image == null ? null : new SvgBitmap(image); | ||
Index = -1; | ||
IconSize = IconSizes.Size16x16; | ||
createMultipleIconList(); | ||
} | ||
|
||
private static Icon bytesToIcon(byte[] bytes) | ||
private static SvgImage bytesToImage(byte[] bytes) | ||
{ | ||
using (MemoryStream ms = new MemoryStream(bytes)) | ||
{ | ||
return new Icon(ms); | ||
} | ||
} | ||
|
||
private void createMultipleIconList() | ||
{ | ||
if (_masterIcon == null) return; | ||
_icoStream = _masterIcon.ToMemoryStream(); | ||
_iconHeader = new IconHeader(_icoStream); | ||
|
||
// Read the icons | ||
var tempList = new List<IconEntry>(); | ||
for (int counter = 0; counter < _iconHeader.Count; counter++) | ||
{ | ||
tempList.Add(new IconEntry(_icoStream)); | ||
} | ||
|
||
//Order by width and bit count so that we retrieve always with icon with the higher bit count | ||
foreach (var iconEntry in tempList.OrderBy(item => item.Width).ThenByDescending(item => item.BitCount)) | ||
{ | ||
_iconEntries.Add(iconEntry); | ||
} | ||
} | ||
|
||
public static implicit operator Icon(ApplicationIcon icon) | ||
{ | ||
return icon.ToIcon(); | ||
using (var ms = new MemoryStream(bytes)) | ||
return new SvgImage(ms); | ||
} | ||
|
||
public static implicit operator Image(ApplicationIcon icon) | ||
{ | ||
return icon.ToImage(); | ||
} | ||
public static implicit operator SvgImage(ApplicationIcon icon) => icon.ToSvgImage(); | ||
|
||
public virtual Bitmap ToImage() | ||
{ | ||
return ToImage(IconSize); | ||
} | ||
public virtual Image ToImage() => ToImage(IconSizes.Size16x16); | ||
|
||
public virtual Bitmap ToImage(IconSize imageSize) | ||
public virtual Image ToImage(IconSize imageSize) | ||
{ | ||
if (!_imageCache.Contains(imageSize)) | ||
return _bitmap?.Render(imageSize, null) | ||
?? new Bitmap(imageSize.Width, imageSize.Height); | ||
/*Bitmap target = new Bitmap( | ||
(int)imageSize.Width, | ||
(int)imageSize.Height); | ||
using (Graphics g = Graphics.FromImage(target)) | ||
{ | ||
var icon = WithSize(imageSize); | ||
var image = icon?.ToBitmap() ?? new Bitmap(imageSize.Width, imageSize.Height); | ||
_imageCache.Add(imageSize, image); | ||
} | ||
return _imageCache[imageSize]; | ||
} | ||
|
||
public virtual Icon ToIcon() | ||
{ | ||
return WithSize(IconSize); | ||
_bitmap.RenderToGraphics(g, | ||
SvgPaletteHelper.GetSvgPalette(LookAndFeel, ObjectState.Normal)); | ||
}*/ | ||
} | ||
|
||
public virtual Icon WithSize(IconSize iconSize) | ||
{ | ||
try | ||
{ | ||
if (!_iconCache.Contains(iconSize)) | ||
_iconCache.Add(iconSize, retrieveIconBySize(iconSize)); | ||
|
||
return _iconCache[iconSize]; | ||
} | ||
catch (Exception) | ||
{ | ||
return _masterIcon; | ||
} | ||
} | ||
|
||
private Icon retrieveIconBySize(IconSize iconSize) | ||
{ | ||
foreach (var iconEntry in _iconEntries) | ||
{ | ||
if (iconEntry.FitIn(iconSize)) | ||
return buildIcon(iconEntry); | ||
} | ||
|
||
//we did not find any icon with the accurate size. We return the master icon | ||
return _masterIcon; | ||
} | ||
|
||
private Icon buildIcon(IconEntry icon) | ||
{ | ||
var newIcon = new MemoryStream(); | ||
|
||
// New Values | ||
Int16 newNumber = 1; | ||
Int32 newOffset = 22; | ||
|
||
// Write it | ||
var writer = new BinaryWriter(newIcon); | ||
writer.Write(_iconHeader.Reserved); | ||
writer.Write(_iconHeader.Type); | ||
writer.Write(newNumber); | ||
writer.Write(icon.Width); | ||
writer.Write(icon.Height); | ||
writer.Write(icon.ColorCount); | ||
writer.Write(icon.Reserved); | ||
writer.Write(icon.Planes); | ||
writer.Write(icon.BitCount); | ||
writer.Write(icon.BytesInRes); | ||
writer.Write(newOffset); | ||
|
||
// Grab the icon | ||
byte[] tmpBuffer = new byte[icon.BytesInRes]; | ||
_icoStream.Position = icon.ImageOffset; | ||
_icoStream.Read(tmpBuffer, 0, icon.BytesInRes); | ||
writer.Write(tmpBuffer); | ||
|
||
// Finish up | ||
writer.Flush(); | ||
newIcon.Position = 0; | ||
return new Icon(newIcon, icon.Width, icon.Height); | ||
} | ||
public virtual SvgImage ToSvgImage() => _image; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.