Giter VIP home page Giter VIP logo

linecode / tinyhtmlwpf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fsdsabel/tinyhtmlwpf

0.0 1.0 0.0 255 KB

TinyHtml.Wpf is a WPF HTML rendering library based on litehtml. It provides the rendering backend for WPF. Contrary to similar libraries it uses native WPF drawing to render texts, images and other stuff. So it is fully capable of doing high dpi and blends seemlessly with other content.

License: BSD 3-Clause "New" or "Revised" License

C# 15.29% C++ 78.01% Objective-C 0.23% C 0.65% CSS 5.82%

tinyhtmlwpf's Introduction

TinyHtml.Wpf

Introduction

TinyHtml.Wpf is a WPF HTML rendering library based on litehtml. It provides the rendering backend for WPF. Contrary to similar libraries it uses native WPF drawing to render texts, images and other stuff. So it is fully capable of doing high dpi and blends seemlessly with other content.

Originally it was developed by me to replace HTMLayout that we used before. However text rendering was always blocky and didn't blend well with other WPF content. We use this extensively for dynamic formatted text that is authored as HTML.

This library does not provide scripting capabilities or very advanced HTML. It proved to be quite capable nonetheless.

A Nuget package can be found on nuget.org. It supports x86 and x64 (or AnyCPU) applications.

Requirements

  • .NET 4.6
  • A WPF application
  • Visual Studio 2017 for building

Supported features

  • WPF Text rendering
  • HTML Tables
  • HTML Lists
  • Images
  • css
  • and much more...

Building

  1. Get sources from https://github.com/fsdsabel/TinyHtmlWpf:
  2. Open the Solution TinyWpfHtml.sln in Visual Studio 2017
  3. Compile configuration Release - x86
  4. Compile configuration Release - x64
  5. Binaries should be in Bin directory and HtmlTestApp should run

Usage

Basically there is only one class you need. It is WpfHtmlControlBase which is subclassed from a standard WPF Control.

Before you can use the control, you must give it a master style sheet. This style is used for all the default HTML elements like paragraphs or bold elements. You can either use the master.css contained in the Nuget package or modify it to your liking. For example you could do something like this:

public class WpfHtmlControl : WpfHtmlControlBase
{
    static WpfHtmlControl()
    {
        using (var s = typeof (WpfHtmlControl).Assembly.GetManifestResourceStream(typeof (WpfHtmlControl), "master.css"))
        {
            SetMasterStylesheet(new StreamReader(s).ReadToEnd());
        }
    }
}

You would then use WpfHtmlControl in your application. The most basic usage would be:

<local:WpfHtmlControl Background="Blue" Foreground="Red" FontSize="16" 
                      Html="&lt;b&gt;Hello world!&lt;/b&gt;"></local:WpfHtmlControl>

It is possible to bind to the Html property to update the displayed HTML dynamically.

If you want to display images, you have to override OnLoadResource.

License

Copyright (c) 2017, Daniel Sabel
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
  • Neither the name of the nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This library uses litehtml:

Copyright (c) 2013, Yuri Kobets (tordex)
All rights reserved.

tinyhtmlwpf's People

Contributors

fsdsabel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.