|
// -- FILE ------------------------------------------------------------------
// name : RtfHtmlStyleConverter.cs
// project : RTF Framelet
// created : Jani Giannoudis - 2008.07.13
// language : c#
// environment: .NET 2.0
// copyright : (c) 2004-2010 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.Drawing;
namespace Itenso.Rtf.Converter.Html
{
// ------------------------------------------------------------------------
public class RtfHtmlStyleConverter : IRtfHtmlStyleConverter
{
// ----------------------------------------------------------------------
public virtual IRtfHtmlStyle TextToHtml( IRtfVisualText visualText )
{
if ( visualText == null )
{
throw new ArgumentNullException( "visualText" );
}
RtfHtmlStyle htmlStyle = new RtfHtmlStyle();
IRtfTextFormat textFormat = visualText.Format;
// background color
Color backgroundColor = textFormat.BackgroundColor.AsDrawingColor;
if ( backgroundColor.R != 0 || backgroundColor.G != 0 || backgroundColor.B != 0 )
{
htmlStyle.BackgroundColor = ColorTranslator.ToHtml( backgroundColor );
}
// foreground color
Color foregroundColor = textFormat.ForegroundColor.AsDrawingColor;
if ( foregroundColor.R != 0 || foregroundColor.G != 0 || foregroundColor.B != 0 )
{
htmlStyle.ForegroundColor = ColorTranslator.ToHtml( foregroundColor );
}
// font
htmlStyle.FontFamily = textFormat.Font.Name;
if ( textFormat.FontSize > 0 )
{
htmlStyle.FontSize = (textFormat.FontSize /2) + "pt";
}
return htmlStyle;
} // TextToHtml
} // class GetTextHtmlStyle
} // namespace Itenso.Rtf.Converter.Html
// -- EOF -------------------------------------------------------------------
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
👨 Senior .NET Software Engineer
🚀 My Open Source Projects
-
Time Period Library 👉
GitHub
-
Payroll Engine 👉
GitHub
Feedback and contributions are welcome.