Skip to content
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: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
HTML Renderer [![Build status](https://ci.appveyor.com/api/projects/status/cm8xpf8ebt3hyi3e)](https://ci.appveyor.com/project/ArthurHub/html-renderer)
=============
## .net 5 version of HtmlRendererCore and HtmlRendererCore.WPF added
* I didn't add nuget build targets
* included fix for https://github.com/ArthurHub/HTML-Renderer/issues/94

## Help Wanted
* Looking for a contributor(s) to take this project forward as I'm unable to continue supporting it.
Expand Down
47 changes: 47 additions & 0 deletions Source/HTMLRendererCore.WPF/Adapters/BrushAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"

using System.Windows.Media;
using TheArtOfDev.HtmlRenderer.Adapters;

namespace TheArtOfDev.HtmlRenderer.WPF.Adapters
{
/// <summary>
/// Adapter for WPF brushes.
/// </summary>
internal sealed class BrushAdapter : RBrush
{
/// <summary>
/// The actual WPF brush instance.
/// </summary>
private readonly Brush _brush;

/// <summary>
/// Init.
/// </summary>
public BrushAdapter(Brush brush)
{
_brush = brush;
}

/// <summary>
/// The actual WPF brush instance.
/// </summary>
public Brush Brush
{
get { return _brush; }
}

public override void Dispose()
{ }
}
}
88 changes: 88 additions & 0 deletions Source/HTMLRendererCore.WPF/Adapters/ContextMenuAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"

using System;
using System.Windows;
using System.Windows.Controls;
using TheArtOfDev.HtmlRenderer.Adapters;
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core.Utils;
using TheArtOfDev.HtmlRenderer.WPF.Utilities;

namespace TheArtOfDev.HtmlRenderer.WPF.Adapters
{
/// <summary>
/// Adapter for WPF context menu for core.
/// </summary>
internal sealed class ContextMenuAdapter : RContextMenu
{
#region Fields and Consts

/// <summary>
/// the underline WPF context menu
/// </summary>
private readonly ContextMenu _contextMenu;

#endregion


/// <summary>
/// Init.
/// </summary>
public ContextMenuAdapter()
{
_contextMenu = new ContextMenu();
}

public override int ItemsCount
{
get { return _contextMenu.Items.Count; }
}

public override void AddDivider()
{
_contextMenu.Items.Add(new Separator());
}

public override void AddItem(string text, bool enabled, EventHandler onClick)
{
ArgChecker.AssertArgNotNullOrEmpty(text, "text");
ArgChecker.AssertArgNotNull(onClick, "onClick");

var item = new MenuItem();
item.Header = text;
item.IsEnabled = enabled;
item.Click += new RoutedEventHandler(onClick);
_contextMenu.Items.Add(item);
}

public override void RemoveLastDivider()
{
if (_contextMenu.Items[_contextMenu.Items.Count - 1].GetType() == typeof(Separator))
_contextMenu.Items.RemoveAt(_contextMenu.Items.Count - 1);
}

public override void Show(RControl parent, RPoint location)
{
_contextMenu.PlacementTarget = ((ControlAdapter)parent).Control;
_contextMenu.PlacementRectangle = new Rect(Utils.ConvertRound(location), Size.Empty);
_contextMenu.IsOpen = true;
}

public override void Dispose()
{
_contextMenu.IsOpen = false;
_contextMenu.PlacementTarget = null;
_contextMenu.Items.Clear();
}
}
}
100 changes: 100 additions & 0 deletions Source/HTMLRendererCore.WPF/Adapters/ControlAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TheArtOfDev.HtmlRenderer.Adapters;
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
using TheArtOfDev.HtmlRenderer.Core.Utils;
using TheArtOfDev.HtmlRenderer.WPF.Utilities;

namespace TheArtOfDev.HtmlRenderer.WPF.Adapters
{
/// <summary>
/// Adapter for WPF Control for core.
/// </summary>
internal sealed class ControlAdapter : RControl
{
/// <summary>
/// the underline WPF control.
/// </summary>
private readonly Control _control;

/// <summary>
/// Init.
/// </summary>
public ControlAdapter(Control control)
: base(WpfAdapter.Instance)
{
ArgChecker.AssertArgNotNull(control, "control");

_control = control;
}

/// <summary>
/// Get the underline WPF control
/// </summary>
public Control Control
{
get { return _control; }
}

public override RPoint MouseLocation
{
get { return Utils.Convert(_control.PointFromScreen(Mouse.GetPosition(_control))); }
}

public override bool LeftMouseButton
{
get { return Mouse.LeftButton == MouseButtonState.Pressed; }
}

public override bool RightMouseButton
{
get { return Mouse.RightButton == MouseButtonState.Pressed; }
}

public override void SetCursorDefault()
{
_control.Cursor = Cursors.Arrow;
}

public override void SetCursorHand()
{
_control.Cursor = Cursors.Hand;
}

public override void SetCursorIBeam()
{
_control.Cursor = Cursors.IBeam;
}

public override void DoDragDropCopy(object dragDropData)
{
DragDrop.DoDragDrop(_control, dragDropData, DragDropEffects.Copy);
}

public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
{
using (var g = new GraphicsAdapter())
{
g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth);
}
}

public override void Invalidate()
{
_control.InvalidateVisual();
}
}
}
125 changes: 125 additions & 0 deletions Source/HTMLRendererCore.WPF/Adapters/FontAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"

using System.Windows.Media;
using TheArtOfDev.HtmlRenderer.Adapters;

namespace TheArtOfDev.HtmlRenderer.WPF.Adapters
{
/// <summary>
/// Adapter for WPF Font.
/// </summary>
internal sealed class FontAdapter : RFont
{
#region Fields and Consts

/// <summary>
/// the underline win-forms font.
/// </summary>
private readonly Typeface _font;

/// <summary>
/// The glyph font for the font
/// </summary>
private readonly GlyphTypeface _glyphTypeface;

/// <summary>
/// the size of the font
/// </summary>
private readonly double _size;

/// <summary>
/// the vertical offset of the font underline location from the top of the font.
/// </summary>
private readonly double _underlineOffset = -1;

/// <summary>
/// Cached font height.
/// </summary>
private readonly double _height = -1;

/// <summary>
/// Cached font whitespace width.
/// </summary>
private double _whitespaceWidth = -1;

#endregion


/// <summary>
/// Init.
/// </summary>
public FontAdapter(Typeface font, double size)
{
_font = font;
_size = size;
_height = 96d / 72d * _size * _font.FontFamily.LineSpacing;
_underlineOffset = 96d / 72d * _size * (_font.FontFamily.LineSpacing + font.UnderlinePosition);

GlyphTypeface typeface;
if (font.TryGetGlyphTypeface(out typeface))
{
_glyphTypeface = typeface;
}
else
{
foreach (var sysTypeface in Fonts.SystemTypefaces)
{
if (sysTypeface.TryGetGlyphTypeface(out typeface))
break;
}
}
}

/// <summary>
/// the underline win-forms font.
/// </summary>
public Typeface Font
{
get { return _font; }
}

public GlyphTypeface GlyphTypeface
{
get { return _glyphTypeface; }
}

public override double Size
{
get { return _size; }
}

public override double UnderlineOffset
{
get { return _underlineOffset; }
}

public override double Height
{
get { return _height; }
}

public override double LeftPadding
{
get { return _height / 6f; }
}

public override double GetWhitespaceWidth(RGraphics graphics)
{
if (_whitespaceWidth < 0)
{
_whitespaceWidth = graphics.MeasureString(" ", this).Width;
}
return _whitespaceWidth;
}
}
}
Loading