Commits

Dmitri Nesteruk committed f26420d

migration to vs11

  • Participants
  • Parent commits c067c02
  • Branches intel

Comments (0)

Files changed (25)

File TypograFix.Common/ConversionOptions.cs

       CodeBlockLabel = "({0})";
     }
 
+    [Category("Headings")]
+    [DisplayName("Color headings")]
+    [Description("When set, takes rasterization FG color and applies it to headings. YMMV.")]
+    public bool ColorHeadings
+    {
+      get { return colorHeadings; }
+      set
+      {
+        if (Equals(colorHeadings, value)) return;
+        colorHeadings = value;
+        OnPropertyChanged("ColorHeadings");
+      }
+    }
+
     [Category("Substitution")]
     [DisplayName("Em font override")]
     [Description("If set, star-delimeted emphasis gets a <font> tag.")]
 
     private bool tocRightAlign;
     private HeadingNumberingOptions headingNumberingOptions;
+    private bool colorHeadings;
 
     [Category("Table of Contents")]
     [DisplayName("Right-align")]

File TypograFix.Common/ExtensionMethods.cs

-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Drawing;
-using System.IO;
-using System.Linq;
-using System.Runtime.Serialization.Formatters.Binary;
-using System.Text;
-using System.Text.RegularExpressions;
-using DmitriNesteruk.TypograFix.Common;
+namespace DmitriNesteruk.TypograFix
+{
+  using System;
+  using System.Collections.Generic;
+  using System.Collections.ObjectModel;
+  using System.Drawing;
+  using System.IO;
+  using System.Linq;
+  using System.Runtime.Serialization.Formatters.Binary;
+  using System.Text;
+  using System.Text.RegularExpressions;
+  using Common;
 
-namespace DmitriNesteruk.TypograFix
-{
   /// <summary>
   /// Useful extension methods.
   /// </summary>
     /// Convert a .NET Color to a hex string.
     /// </summary>
     /// <returns>ex: "FFFFFF", "AB12E9"</returns>
-    public static string AsHex(this System.Windows.Media.Color color)
+    public static string ToHexString(this System.Windows.Media.Color color)
     {
       var bytes = new byte[3];
       bytes[0] = color.R;

File TypograFix.Common/HeadingEntry.cs

+using System;
+using System.Text.RegularExpressions;
+
 namespace DmitriNesteruk.TypograFix.Common
 {
   using System.Text;
       Level = level;
       Text = text;
     }
+
     public string SuggestedTagText
     {
       get
       {
         var sb = new StringBuilder();
-        foreach (char c in Text)
+        foreach (char c in RemoveTags(Text))
         {
           if (char.IsLetterOrDigit(c))
             sb.Append(c);
         return sb.ToString();
       }
     }
+
+    internal static string RemoveTags(string text)
+    {
+      return Regex.Replace(text, @"<[^>]*>", String.Empty);
+    }
   }
 }

File TypograFix.Common/Options/SyntaxMarkupOptions.cs

-/* Copyright � Dmitri Nesteruk, 2009 dmitrinesteruk (a) gmail.com, http://nesteruk.org */
-
 namespace DmitriNesteruk.TypograFix.Common
 {
   using System.ComponentModel;

File TypograFix.csproj

       <IncludeHash>True</IncludeHash>
       <FileType>Assembly</FileType>
     </PublishFile>
-    <PublishFile Include="NBehave.Narrator.Framework">
-      <Visible>False</Visible>
-      <Group>TestOnly</Group>
-      <TargetPath>
-      </TargetPath>
-      <PublishState>Exclude</PublishState>
-      <IncludeHash>True</IncludeHash>
-      <FileType>Assembly</FileType>
-    </PublishFile>
-    <PublishFile Include="NBehave.Spec.Framework">
-      <Visible>False</Visible>
-      <Group>TestOnly</Group>
-      <TargetPath>
-      </TargetPath>
-      <PublishState>Exclude</PublishState>
-      <IncludeHash>True</IncludeHash>
-      <FileType>Assembly</FileType>
-    </PublishFile>
-    <PublishFile Include="NBehave.Spec.MbUnit">
-      <Visible>False</Visible>
-      <Group>TestOnly</Group>
-      <TargetPath>
-      </TargetPath>
-      <PublishState>Exclude</PublishState>
-      <IncludeHash>True</IncludeHash>
-      <FileType>Assembly</FileType>
-    </PublishFile>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="TypograFix.Common\TypograFix.Common.csproj">

File TypograFixImpl/AnnotationRasterizer/AnnotationRasterizer.cs

 using DmitriNesteruk.TypograFix.Common;
 using Microsoft.WindowsAPICodePack.DirectX.Direct2D1;
 using Microsoft.WindowsAPICodePack.DirectX.DirectWrite;
-using Microsoft.WindowsAPICodePack.DirectX.Graphics;
 using Microsoft.WindowsAPICodePack.DirectX.WindowsImagingComponent;
 
 namespace DmitriNesteruk.TypograFixImpl.AnnotationRasterizer

File TypograFixImpl/CodeFormatting/CSharpFormat.cs

       { 
         return "abstract as async await base bool break byte case catch char "
                + "checked class const continue decimal default delegate do double dynamic else "
-               + "enum event explicit extern false finally fixed float for foreach goto "
+               + "enum event explicit extern false finally fixed float for foreach get goto "
                + "if implicit in int interface internal is lock long namespace new null "
                + "object operator out override partial params private protected public readonly "
-               + "ref return sbyte sealed short sizeof stackalloc static string struct "
+               + "ref return sbyte sealed set short sizeof stackalloc static string struct "
                + "switch this throw true try typeof uint ulong unchecked unsafe ushort "
                + "using value var virtual void volatile where while yield";
       }

File TypograFixImpl/CodeFormatting/CodeFormat.cs

           {
             sb.Append("\n");
           }
-          sb.AppendFormat("<font color=\"#{0}\">", CommentColor.AsHex());
+          sb.AppendFormat("<font color=\"#{0}\">", CommentColor.ToHexString());
           if (ItalicizeComments)
             sb.Append("<em>");
 
       }
       if(match.Groups[2].Success) //string literal
       {
-        return string.Format("<font color=\"#{0}\">{1}</font>", StringColor.AsHex(), match);
+        return string.Format("<font color=\"#{0}\">{1}</font>", StringColor.ToHexString(), match);
       }
       if(match.Groups[3].Success) //preprocessor keyword
       {
-        return string.Format("<font color=\"#{0}\">{1}</font>", PreprocColor.AsHex(), match);
+        return string.Format("<font color=\"#{0}\">{1}</font>", PreprocColor.ToHexString(), match);
       }
       if(match.Groups[4].Success) //keyword
       {
-        return string.Format("<font color=\"#{0}\">{1}</font>", KeywordColor.AsHex(), match);
+        return string.Format("<font color=\"#{0}\">{1}</font>", KeywordColor.ToHexString(), match);
       }
       Debug.Assert(false, "None of the above!");
       return ""; //none of the above

File TypograFixImpl/CodeFormatting/SourceFormat.cs

-using DmitriNesteruk.TypograFix;
-
 namespace DmitriNesteruk.TypograFixImpl.CodeFormatting
 {
   using System;
   using System.Reflection;
   using System.Text;
   using System.Text.RegularExpressions;
-  using System.Web;
   using System.Windows.Media;
   using TypograFix.Common;
   using System.Linq;
   using System.Net;
+  using TypograFix;
 
   /// <summary>
   ///	Provides a base implementation for all code formatters.

File TypograFixImpl/FlowBasedRenderer.cs

       {
         g.FillRectangle(System.Drawing.Brushes.White, 0, 0, (int) resultSize.Width, (int) resultSize.Height);
         g.DrawImage(source, (int) marginSize.Width, (int) marginSize.Height);
-        g.DrawRectangle(Pens.Black, 0, 0, (int) (source.Width + marginSize.Width*2),
-                        (int) (source.Height + marginSize.Height*2));
+        //g.DrawRectangle(Pens.Black, 0, 0, (int) (source.Width + marginSize.Width*2),
+        //                (int) (source.Height + marginSize.Height*2));
         return resultingBitmap;
       }
     }

File TypograFixImpl/Generator.cs

         if (options.ForcePInsideLI)
           text = text.Replace("<li>", "<li><p>").Replace("</li>", "</p></li>");
 
+        // color headings if necessary
+        if (options.ColorHeadings)
+          text = TableOfContentsGenerator.ColorHeadings(text, options);
+
         #region auto-number headings
         if (options.HeadingNumberingOptions == HeadingNumberingOptions.Numbered)
         {
                       .Replace("<insertionpoint>", string.Empty);
                     string markup = string.Format("[{0}][{1}]{2}",
                       options.RasterizationFont, options.FreeformFontSize, converted);
-                    string filename = RegenerateFreeformImage(options, markup, (++rasterizedCodeBlockIndex) + 100, true);
+                    string filename = RegenerateFreeformImage(options, markup, (++rasterizedCodeBlockIndex) + 100, true); // todo: make optional
                     formatted = new XElement("p",
                       new XElement("img",
                       new XAttribute("src", filename))).ToString();

File TypograFixImpl/Generators/TableOfContentsGenerator.cs

 
   public class TableOfContentsGenerator
   {
+    
+
     /// <summary>
     /// Generates the table of contents.
     /// </summary>
         hb.Insert(String.Format("<h{0}>{1}</h{0}>{2}", minLevel,
                                 WebUtility.HtmlEncode(options.TocLabel), Environment.NewLine), 0);
     }
+
+    public static string ColorHeadings(string text, ConversionOptions options)
+    {
+      const string headingPattern = "<h([^<]+)>(.+)</h.>";
+      string openingFontTag = "<font color=\"#{0}\">".ƒ(options.ImageHeadingForegroundColor.ToHexString());
+      const string closingFontTag = "</font>";
+
+      return Regex.Replace(text, headingPattern,
+                           m =>
+                             {
+                               int n;
+                               if (int.TryParse(m.Groups[1].Value, out n) && n <= 3)
+                                return "<h{0}>{1}{2}{3}</h{0}>".ƒ(m.Groups[1].Value, openingFontTag,
+                                                                 m.Groups[2].Value, closingFontTag);
+                               return m.Groups[0].Value;
+                             });
+    }
   }
 }

File TypograFixImpl/HtmlToConfluenceConverter.cs

-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Xml;
-using System.Xml.Linq;
-using DmitriNesteruk.TypograFix;
-using Sgml;
-
-namespace DmitriNesteruk.TypograFixImpl
+namespace DmitriNesteruk.TypograFixImpl
 {
-  using TypograFix.Common;
+  using System.Collections.Generic;
+  using System.IO;
+  using System.Text;
+  using System.Text.RegularExpressions;
+  using System.Xml;
+  using System.Xml.Linq;
+  using TypograFix;
+  using Sgml;
 
   class HtmlToConfluenceConverter : IPipelineConverter
   {
 
         {"<ul>", ""},
         {"</ul>", ""},
+        
+        {"<ol>", ""},
+        {"</ol>", ""},
 
         {"<li>\n", "* "},
+        {"  <li>", "* "},
         {"<li>", "* "},
         {"</li>", ""}
       };

File Typografix.Bitmap/.wave-vs.net.backup/TypograFix.CardRendering._30_3_2011_21_54_50_.cpp

-#include "stdafx.h"
-#include "Typografix.CardRendering.h"
-#include "TypograFix.ManaVisual.h"
-
-typedef CComPtr<ID2D1Bitmap> Bitmap;
-
-HRESULT GetBitmap(CComPtr<ID2D1RenderTarget>& rt, CComPtr<IWICImagingFactory>& wic, LPCWSTR filename,
-                         Bitmap& bitmap)
-{
-  // first, create a decoder from the given background name
-  CComPtr<IWICBitmapDecoder> decoder;
-  CComPtr<IWICBitmapFrameDecode> frame;
-  CComPtr<IWICFormatConverter> converter;
-
-  HRESULT hr = wic->CreateDecoderFromFilename(filename, NULL, GENERIC_READ,
-    WICDecodeMetadataCacheOnLoad, &decoder);
-
-  if (SUCCEEDED(hr))
-  {
-    hr = decoder->GetFrame(0, &frame);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    // Convert the image format to 32bppPBGRA
-    // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
-    hr = wic->CreateFormatConverter(&converter);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = converter->Initialize(
-        frame, GUID_WICPixelFormat32bppPBGRA,
-        WICBitmapDitherTypeNone, NULL, 0.f,
-        WICBitmapPaletteTypeMedianCut);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    // Create a Direct2D bitmap from the WIC bitmap.
-    hr = rt->CreateBitmapFromWicBitmap(converter, NULL, &bitmap);
-  }
-
-  return hr;
-}
-
-MYAPI void RenderCard(BYTE* dst, int stride, LPCWSTR background, LPCWSTR cardName, LPCWSTR cardType, 
-                      LPCWSTR cardText, LPCWSTR manaSpec, LPCWSTR pt, LPCWSTR color, LPCWSTR rarity, LPCWSTR setName)
-{
-  map<wstring, wstring> editionMap;
-  editionMap[L"8e"] = L"8thedition";
-  editionMap[L"9e"] = L"9th";
-  editionMap[L"10e"] = L"M10";
-
-  HRESULT hr = S_OK;
-  CComPtr<ID2D1Factory> d2dFactory;
-  CComPtr<IDWriteFactory> dWriteFactory;
-  CComPtr<IWICBitmap> wicBitmap;
-  CComPtr<ID2D1RenderTarget> renderTarget;
-  CComPtr<ID2D1SolidColorBrush> blackBrush;
-  CComPtr<IDWriteTextFormat> nameTextFormat;
-  CComPtr<IDWriteTextLayout> nameTextLayout;
-  CComPtr<IDWriteTextFormat> typeTextFormat;
-  CComPtr<IDWriteTextLayout> typeTextLayout;
-
-  const int width = 512, height = 512;
-
-  // create d2d factory
-  if (SUCCEEDED(hr))
-    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory);
-
-  // create wic factory
-  CComPtr<IWICImagingFactory> wicFactory;
-  hr = CoCreateInstance(
-    CLSID_WICImagingFactory,
-    NULL,
-    CLSCTX_INPROC_SERVER,
-    IID_IWICImagingFactory,
-    reinterpret_cast<void **>(&wicFactory));
-
-  // create dwrite factory
-  if (SUCCEEDED(hr))
-  {
-    hr = DWriteCreateFactory(
-         DWRITE_FACTORY_TYPE_SHARED,
-         __uuidof(dWriteFactory),
-         reinterpret_cast<IUnknown **>(&dWriteFactory));
-  }
-
-  // make a fairly large bitmap
-  if (SUCCEEDED(hr))
-  {
-    hr = wicFactory->CreateBitmap(width, height,
-         GUID_WICPixelFormat32bppBGR,
-         WICBitmapCacheOnLoad, &wicBitmap);
-  }
-
-  // make the render target
-  if (SUCCEEDED(hr))
-  {
-    hr = d2dFactory->CreateWicBitmapRenderTarget(
-         wicBitmap, D2D1::RenderTargetProperties(), &renderTarget);
-  }
-
-  // attempt to get the background bitmap
-  Bitmap bgrBitmap;
-  if (SUCCEEDED(hr))
-  {
-    wstring filename = L"F:\\Program Files\\Wizards of the Coast\\Magic Online III\\Graphics\\Cards\\Frame\\" +
-      wstring(background) + L".png";
-    GetBitmap(renderTarget, wicFactory, filename.c_str(), bgrBitmap);
-  }
-
-  // attempt to get the card image
-  Bitmap picBitmap;
-  if (SUCCEEDED(hr))
-  {
-    wstring filename = L"F:\\Program Files\\Wizards of the Coast\\Magic Online III\\Graphics\\Cards\\Pics\\" +
-      wstring(L"00001_typ_reg_sty_001.jpg");
-    GetBitmap(renderTarget, wicFactory, filename.c_str(), picBitmap);
-  }
-
-  // get set image
-  Bitmap setBitmap;
-  if (SUCCEEDED(hr))
-  {
-    wstring r = L"";
-    if (rarity == NULL || wcslen(rarity) == 0)
-      r = L"common";
-    else if (rarity[0] == L'u')
-      r = L"uncommon";
-    else if (rarity[0] == L'r')
-      r = L"rare";
-    else
-      r = L"common";
-
-    // NOTE: 10th edition symbol is a special case!
-
-    wstring filename = L"F:\\Program Files\\Wizards of the Coast\\Magic Online III\\Graphics\\Cards\\Icon\\" +
-      wstring(L"graphic_seticon_") + editionMap[setName] + wstring(L"_") + r + wstring(L".png");
-    GetBitmap(renderTarget, wicFactory, filename.c_str(), setBitmap);
-  }
-
-  // prepare text options for card title
-  const int fontSize = 10;
-  wstring fontFamily = L"Arial Narrow";
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextFormat(
-         fontFamily.c_str(),
-         NULL,
-         DWRITE_FONT_WEIGHT_NORMAL,
-         DWRITE_FONT_STYLE_NORMAL,
-         DWRITE_FONT_STRETCH_NORMAL,
-         fontSize,
-         L"", //locale
-         &nameTextFormat);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextLayout(cardName, wcslen(cardName),
-      nameTextFormat, 256, 16, &nameTextLayout);
-  }
-
-  // prepare text options for card type
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextFormat(
-         fontFamily.c_str(),
-         NULL,
-         DWRITE_FONT_WEIGHT_NORMAL,
-         DWRITE_FONT_STYLE_NORMAL,
-         DWRITE_FONT_STRETCH_NORMAL,
-         fontSize,
-         L"", //locale
-         &typeTextFormat);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextLayout(cardType, wcslen(cardType),
-      typeTextFormat, 256, 16, &typeTextLayout);
-  }
-
-  // card text
-  CComPtr<IDWriteTextLayout> cardTextLayout;
-  CComPtr<IDWriteTextFormat> cardTextFormat;
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextFormat(
-         fontFamily.c_str(),
-         NULL,
-         DWRITE_FONT_WEIGHT_NORMAL,
-         DWRITE_FONT_STYLE_NORMAL,
-         DWRITE_FONT_STRETCH_NORMAL,
-         fontSize,
-         L"", //locale
-         &cardTextFormat);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = dWriteFactory->CreateTextLayout(cardText, wcslen(cardText),
-      cardTextFormat, 156, 120, &cardTextLayout);
-  }
-
-  // mana visuals
-  ManaVisual manaVisual(manaSpec, renderTarget, wicFactory);
-
-  // black brush (comes in handy)
-  if (SUCCEEDED(hr))
-  {
-    hr = renderTarget->CreateSolidColorBrush(
-      D2D1::ColorF(D2D1::ColorF::Black),
-      &blackBrush);
-  }
-
-  // check if p/t box is needed
-  int ptLen = wcslen(pt);
-  Bitmap ptLeft;
-  Bitmap ptCenter;
-  Bitmap ptRight;
-  if (ptLen > 0)
-  {
-    wstring dir = L"F:\\Program Files\\Wizards of the Coast\\Magic Online III\\Graphics\\Cards\\PowerBox\\";
-    GetBitmap(renderTarget, wicFactory, (dir + wstring(L"graphic_card_powerbox_") + color + L"_left.png").c_str(), ptLeft);
-    GetBitmap(renderTarget, wicFactory, (dir + wstring(L"graphic_card_powerbox_") + color + L"_middle.png").c_str(), ptCenter);
-    GetBitmap(renderTarget, wicFactory, (dir + wstring(L"graphic_card_powerbox_") + color + L"_right.png").c_str(), ptRight);
-  }
-
-  // perform the rendering
-  if (SUCCEEDED(hr))
-  {
-    renderTarget->BeginDraw();
-
-    renderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
-
-    D2D1_SIZE_F rtSize = renderTarget->GetSize();
-
-    if (bgrBitmap != NULL)
-    {
-      D2D1_RECT_F rtBgr;
-      rtBgr.left = rtBgr.top = 0;
-      rtBgr.right = 180;
-      rtBgr.top = 256;
-      renderTarget->DrawBitmap(bgrBitmap, &rtBgr, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR);
-    }
-
-    if (picBitmap != NULL)
-    {
-      D2D1_RECT_F rtPic;
-      rtPic.left = 10;
-      rtPic.top = 25;
-      rtPic.right = rtPic.left + 160;
-      rtPic.bottom = rtPic.top + 118;
-      renderTarget->DrawBitmap(picBitmap, &rtPic, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR);
-    }
-
-    int final_right = 170;
-    int final_bottom = 158;
-    int effective_height = 12;
-    if (setBitmap != NULL)
-    {
-      D2D1_RECT_F rtSet;
-      D2D1_SIZE_F s = setBitmap->GetSize();
-      
-      float aspect_ratio = s.width / s.height;
-      float effective_width = effective_height * aspect_ratio;
-      rtSet.left = final_right - effective_width;
-      rtSet.right = final_right;
-      rtSet.bottom = final_bottom;
-      rtSet.top = final_bottom - effective_height;
-      renderTarget->DrawBitmap(setBitmap, &rtSet, 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR);
-    }
-
-    // text
-    D2D1_POINT_2F ptText;
-    ptText.x = 12;
-    ptText.y = 161;
-    renderTarget->DrawTextLayout(ptText, cardTextLayout, blackBrush);
-
-    // name
-    D2D1_POINT_2F ptName;
-    ptName.x = 12;
-    ptName.y = 8;
-    renderTarget->DrawTextLayout(ptName, nameTextLayout, blackBrush);
-
-    // type
-    D2D1_POINT_2F ptType;
-    ptType.x = 12;
-    ptType.y = 144;
-    renderTarget->DrawTextLayout(ptType, typeTextLayout, blackBrush);
-
-    // mana visuals
-    int numberOfManaGlyphs = manaVisual.Bitmaps.size();
-    int glyphSize = 12;
-    for (int i = 0; i < numberOfManaGlyphs; ++i)
-    {
-      D2D1_RECT_F rc;
-      rc.right = final_right - (i * glyphSize);
-      rc.left = rc.right - glyphSize;
-      rc.top = 9;
-      rc.bottom = rc.top + glyphSize;
-      renderTarget->DrawBitmap(manaVisual.Bitmaps[numberOfManaGlyphs - i - 1], &rc);
-    }
-
-    // p/t if necessary
-    if (ptLen > 0 && ptLeft != NULL && ptCenter != NULL && ptRight != NULL)
-    {
-      int final_y = 225;
-      // draw the powerbox
-      D2D1_RECT_F rcLeft;
-      D2D1_SIZE_F sizeLeft = ptLeft->GetSize();
-      rcLeft.top = final_y;
-      rcLeft.bottom = rcLeft.top + sizeLeft.height;
-      rcLeft.left = 130;
-      rcLeft.right = rcLeft.left + sizeLeft.width;
-      renderTarget->DrawBitmap(ptLeft, rcLeft);
-
-      D2D1_RECT_F rcCenter(rcLeft);
-      D2D1_SIZE_F sizeCenter = ptCenter->GetSize();
-      rcCenter.left += sizeLeft.width;
-      rcCenter.right = rcCenter.left + sizeCenter.width;
-      renderTarget->DrawBitmap(ptCenter, rcCenter);
-
-      // quickly set up and render the text right here
-      {
-        CComPtr<IDWriteTextFormat> ptTextFormat;
-        if (SUCCEEDED(hr))
-        {
-          hr = dWriteFactory->CreateTextFormat(
-               fontFamily.c_str(),
-               NULL,
-               DWRITE_FONT_WEIGHT_NORMAL,
-               DWRITE_FONT_STYLE_NORMAL,
-               DWRITE_FONT_STRETCH_NORMAL,
-               fontSize + 4,
-               L"", //locale
-               &ptTextFormat);
-          ptTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
-          
-        }
-
-        if (SUCCEEDED(hr))
-        {
-          D2D1_POINT_2F point;
-          point.x = rcCenter.left;
-          point.y = rcCenter.bottom;
-          renderTarget->DrawText(pt, ptLen, ptTextFormat, rcCenter, blackBrush);
-        }
-      }
-
-      D2D1_RECT_F rcRight(rcCenter);
-      rcRight.left += sizeCenter.width;
-      rcRight.right = rcRight.left + ptRight->GetSize().width;
-      renderTarget->DrawBitmap(ptRight, rcRight);
-    }
-
-    hr = renderTarget->EndDraw();
-  }
-
-  // never mind now...
-  WICRect r;
-  r.X = r.Y = 0;
-  r.Width = width;
-  r.Height = height;
-  hr = wicBitmap->CopyPixels(&r, stride, sizeof(Pixel) * width * height, dst);
-}

File Typografix.Bitmap/.wave-vs.net.backup/TypograFix.CardRendering._30_3_2011_21_54_50_.cpp.info

-BackupReason=wave-vs.net Session to Jesus Salas, 
-File=TypograFix.CardRendering._30_3_2011_21_54_50_.cpp

File Typografix.Bitmap/.wave-vs.net.backup/TypograFix.MarkupParser._30_3_2011_21_54_50_.cpp

-#include "stdafx.h"
-
-class MarkupElement
-{
-public:
-  float Size;
-  wstring FontFamily;
-  UINT Color;
-  bool Italic, SmallCaps;
-  wstring Text;
-  bool ContextualLigatures;
-  bool StandardLigatures;
-  bool Swash;
-  int StylisticSet;
-  float LineSpacing, Baseline;
-  bool Right;
-
-  MarkupElement() {}
-
-  MarkupElement(const MarkupElement& other)
-  {
-    Size = other.Size;
-    FontFamily = other.FontFamily;
-    Color = other.Color;
-    Italic = other.Italic;
-    SmallCaps = other.SmallCaps;
-    FontFamily = other.FontFamily;
-    Text = other.Text;
-    ContextualLigatures = other.ContextualLigatures;
-    StandardLigatures = other.StandardLigatures;
-    Swash = other.Swash;
-    Right = other.Right;
-  }
-};
-
-typedef vector<MarkupElement> vme;
-
-class MarkupParser
-{
-  static void ApplyMarkupToElement(wstring& markup, MarkupElement& element, 
-    bool set, MarkupElement& prototype)
-  {
-    if (markup.length() == 0) return;
-
-    if (markup[0] == L'#' && markup.length() == 10)
-    {
-      // try parsing HEX color
-      int r = _wtoi(markup.substr(1, 3).c_str());
-      int g = _wtoi(markup.substr(4, 3).c_str());
-      int b = _wtoi(markup.substr(7, 3).c_str());
-      int a = 0xff;
-      
-      element.Color = (r << 16) + (g << 8) + (b);
-      return;
-    }
-
-    // check whether it's a font size
-    float n = (float)_wtof(markup.c_str());
-    if (n != 0.0f)
-    {
-      element.Size = n;
-      return;
-    }
-
-    // check italics
-    if (markup == L"i" || markup == L"em")
-    {
-      element.Italic = set;
-      return;
-    }
-
-    // check small caps
-    if (markup == L"sc")
-    {
-      element.SmallCaps = set;
-      return;
-    }
-
-    // contextual ligatures
-    if (markup == L"liga")
-    {
-      element.StandardLigatures = set;
-      return;
-    }
-
-    // swash
-    if (markup == L"sw" || markup == L"swsh")
-    {
-      element.Swash = set;
-      return;
-    }
-
-    // stylistic set
-    if (markup.length() == 4 && markup[0] == L's' && markup[1] == L's')
-    {
-      wstring number = L"";
-      number += markup[2];
-      number += markup[3];
-      int n = _wtoi(number.c_str());
-      if (n != 0)
-      {
-        element.StylisticSet = n;
-        return;
-      }
-    }
-
-    // hack
-    if (markup == L"right")
-    {
-      element.Right = true;
-      return;
-    }
-
-    // failing all that, it's a font name
-    if (set)
-      element.FontFamily = markup;
-    else if (element.FontFamily == markup)
-      element.FontFamily = prototype.FontFamily;
-  }
-
-  static void AddDataToResult(vector<wchar_t>& buffer, 
-    MarkupElement& current, vme& result)
-  {
-    if (buffer.size() > 0)
-    {
-      // set the buffer as the text property of the markup element
-      current.Text = wstring(buffer.begin(), buffer.end());
-      // add the markup element to the result
-      result.push_back(current);
-      // clean the buffer
-      buffer.clear();
-    }
-  }
-public:
-  static vector<MarkupElement> Parse(wstring markup, MarkupElement prototype)
-  {
-    vme result;
-    vector<wchar_t> textBuffer;
-    vector<wchar_t> tagBuffer;
-    MarkupElement current(prototype);
-    bool insideBrackets = false;
-    bool isClosing = false;
-
-    int len = markup.length();
-    for (int i = 0; i < len; ++i)
-    {
-      wchar_t letter = markup[i];
-
-      if (letter == L'[' && (i == 0 || markup[i-1] != L'\\'))
-      {
-        insideBrackets = true;
-        isClosing = false;
-        // if something is pending, process it
-        ApplyMarkupToElement(wstring(tagBuffer.begin(), tagBuffer.end()), 
-          current, !isClosing, prototype);
-        tagBuffer.clear();
-        AddDataToResult(textBuffer, current, result);
-      }
-      else if (letter == L']' && insideBrackets && (i == 0 || markup[i-1] != L'\\'))
-      {
-        ApplyMarkupToElement(wstring(tagBuffer.begin(), tagBuffer.end()),
-          current, !isClosing, prototype);
-        tagBuffer.clear();
-        AddDataToResult(textBuffer, current, result);
-        insideBrackets = false;
-        isClosing = false;
-      }
-      else if (letter == L',' && insideBrackets)
-      {
-        // don't flush, just apply
-        ApplyMarkupToElement(wstring(tagBuffer.begin(), tagBuffer.end()), current, !isClosing, prototype);
-        tagBuffer.clear();
-      }
-      else if (letter == L'/' && insideBrackets)
-      {
-        // if we are inside brackets, we're closing
-        // otherwise, it's a normal slash
-        isClosing = true;
-      }
-      else
-      {
-        if (!((letter == L'\\') && ((i+1 < len) && 
-          (markup[i+1] == L'[' || markup[i+1] == L']'))))
-        {
-          (insideBrackets ? tagBuffer : textBuffer).push_back(letter);
-        }
-      }
-    }
-
-    // apply anything that's left
-    ApplyMarkupToElement(wstring(tagBuffer.begin(), tagBuffer.end()), current, !isClosing, prototype);
-    tagBuffer.clear();
-    AddDataToResult(textBuffer, current, result);
-    return result;
-  }
-};

File Typografix.Bitmap/.wave-vs.net.backup/TypograFix.MarkupParser._30_3_2011_21_54_50_.cpp.info

-BackupReason=wave-vs.net Session to Jesus Salas, 
-File=TypograFix.MarkupParser._30_3_2011_21_54_50_.cpp

File Typografix.Bitmap/.wave-vs.net.backup/Typografix.Bitmap._30_3_2011_21_54_49_.cpp

-#include "stdafx.h"
-#include "common.h"
-#include "Typografix.Bitmap.h"
-#include "Typografix.MarkupParser.cpp"
-
-void StringSplit(string str, string delim, vector<string> results)
-{
-  int cutAt;
-  while((cutAt = str.find_first_of(delim)) != str.npos)
-  {
-    if(cutAt > 0)
-    {
-      results.push_back(str.substr(0,cutAt));
-    }
-    str = str.substr(cutAt+1);
-  }
-  if(str.length() > 0)
-  {
-    results.push_back(str);
-  }
-}
-
-// dst must be same size as src
-MYAPI void Coalesce(BYTE* src, BYTE* dst, int width, int height, int stride)
-{
-  #pragma omp parallel for
-  for (int y = 0; y < height; ++y) {
-    int y_offset = y * stride;
-    for (int x = 2; x < (width - 2); ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      Pixel& d = *reinterpret_cast<Pixel*>(dst + offset);
-      Pixel& r1 = *reinterpret_cast<Pixel*>(src + (offset + sizeof(Pixel)));
-      Pixel& r2 = *reinterpret_cast<Pixel*>(src + (offset + 2*sizeof(Pixel)));
-      Pixel& l1 = *reinterpret_cast<Pixel*>(src + (offset - sizeof(Pixel)));
-      Pixel& l2 = *reinterpret_cast<Pixel*>(src + (offset - 2*sizeof(Pixel)));
-      // изменяем d
-      d.Blue = 0;
-      d.Green = 0;
-      d.Red = 0;
-      UINT result = (l2.Alpha >> 3) + (l1.Alpha >> 2) + (s.Alpha >> 1) + (r1.Alpha >> 2) + (r2.Alpha >> 3);
-      d.Alpha = result > 0xff ? 0xff : (BYTE)result;
-    }
-  }
-}
-
-MYAPI RECT MeasureCropArea(BYTE* src, int width, int height, int stride, int color)
-{
-  Pixel& bgr = *reinterpret_cast<Pixel*>(&color);
-  RECT result;
-
-  // find the first non-conforming row of pixels
-  for (int y = 0; y < height; ++y) 
-  {
-    int y_offset = y * stride;
-    for (int x = 0; x < width; ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the row
-      if (s != bgr)
-      {
-        result.top = y;
-        // cause soft eject
-        x = width;
-        y = height;
-      }
-    }
-  }
-
-  // find the last non-conforming row of pixels
-  for (int y = height - 1; y >= 0; --y) 
-  {
-    int y_offset = y * stride;
-    for (int x = 0; x < width; ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the row
-      if (s != bgr)
-      {
-        result.bottom = y;
-        // cause soft eject
-        x = width;
-        y = -1;
-      }
-    }
-  }
-
-  // find the first non-conforming column of pixels
-  for (int x = 0; x < width; ++x)
-  {
-    for (int y = 0; y < height; ++y) 
-    {
-      int offset = x * sizeof(Pixel) + y * stride;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the column
-      if (s != bgr)
-      {
-        result.left = x;
-        // cause soft eject
-        x = width;
-        y = height;
-      }
-    }
-  }
-
-  // find the last non-conforming column of pixels
-  for (int x = width - 1; x >= 0; --x)
-  {
-    for (int y = 0; y < height; ++y) 
-    {
-      int offset = x * sizeof(Pixel) + y * stride;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the column
-      if (s != bgr)
-      {
-        result.right = x;
-        // cause soft eject
-        x = -1;
-        y = height;
-      }
-    }
-  }
-
-  int w = result.right - result.left;
-  int h = result.bottom - result.top;
-  if (w < 1) { result.left = 0; result.right = 1; }
-  if (h < 1) { result.top = 0; result.bottom = 1; }
-  return result;
-}
-
-MYAPI void Fold(BYTE* src, BYTE* dst, int dstWidth, int height, int srcStride, int dstStride)
-{
-  #pragma omp parallel for
-  for (int y = 0; y < height; ++y)
-  {
-    int src_y_offset = y * srcStride;
-    int dst_y_offset = y * dstStride;
-    for (int x = 0; x < dstWidth; ++x)
-    {
-      int dst_offset = x * sizeof(Pixel) + dst_y_offset;
-      Pixel& d = *reinterpret_cast<Pixel*>(dst + dst_offset);
-
-      int r_offset = x * 3 * sizeof(Pixel) + src_y_offset;
-      int g_offset = (x * 3 + 1) * sizeof(Pixel) + src_y_offset;
-      int b_offset = (x * 3 + 2) * sizeof(Pixel) + src_y_offset;
-      Pixel& r = *reinterpret_cast<Pixel*>(src + r_offset);
-      Pixel& g = *reinterpret_cast<Pixel*>(src + g_offset);
-      Pixel& b = *reinterpret_cast<Pixel*>(src + b_offset);
-
-      // let's do it
-      d.Alpha = 0xff;
-      d.Red = 0xff - r.Alpha;
-      d.Green = 0xff - g.Alpha;
-      d.Blue = 0xff - b.Alpha;
-    }
-  }
-}
-
-MYAPI void RenderMarkup(BYTE* dst, LPCWSTR markup, int width, int height, 
-                        int stride, LPCWSTR fontFamily, float fontSize,
-                        bool smallCaps, bool italic, bool contextualLigatures,
-                        bool standardLigatures, bool swash, int stylisticSet,
-                        float lineSpacing, float baseline)
-{
-  HRESULT hr = S_OK;
-
-  IWICImagingFactory *pWICFactory = NULL;
-  ID2D1Factory *pD2DFactory = NULL;
-  IDWriteFactory *pDWriteFactory = NULL;
-  IWICBitmap *pWICBitmap = NULL;
-  ID2D1RenderTarget *pRT = NULL;
-  IDWriteTextFormat *pTextFormat = NULL;
-  ID2D1SolidColorBrush *pBlackBrush = NULL;
-  IDWriteTextLayout *pTextLayout = NULL;
-  IDWriteTypography *pTypography = NULL;
-
-  vector<IDWriteTypography*> typographies;
-
-  // build the prototype markup element
-  MarkupElement prototype;
-  prototype.FontFamily = wstring(fontFamily);
-  prototype.Size = fontSize;
-  prototype.Italic = italic;
-  prototype.SmallCaps = smallCaps;
-  prototype.ContextualLigatures = contextualLigatures;
-  prototype.StandardLigatures = standardLigatures;
-  prototype.Swash = swash;
-  prototype.StylisticSet = stylisticSet;
-  prototype.LineSpacing = lineSpacing;
-  prototype.Baseline = baseline;
-  prototype.Right = false;
-  prototype.Color = 0;
-
-  // parse the markup
-  vector<MarkupElement> elements = MarkupParser::Parse(wstring(markup), prototype);
-
-  // get the total text
-  vector<wchar_t> vTemp;
-  for (vme::const_iterator it = elements.begin(); it != elements.end(); it++)
-  {
-    for (int i = 0; i < (*it).Text.length(); ++i)
-      vTemp.push_back((*it).Text[i]);
-  }
-  wstring allText(vTemp.begin(), vTemp.end());
-
-  hr = CoCreateInstance(
-    CLSID_WICImagingFactory,
-    NULL,
-    CLSCTX_INPROC_SERVER,
-    IID_IWICImagingFactory,
-    reinterpret_cast<void **>(&pWICFactory));
-
-  if (SUCCEEDED(hr))
-  {
-    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = DWriteCreateFactory(
-         DWRITE_FACTORY_TYPE_SHARED,
-         __uuidof(pDWriteFactory),
-         reinterpret_cast<IUnknown **>(&pDWriteFactory));
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pWICFactory->CreateBitmap(width, height,
-         GUID_WICPixelFormat32bppBGR,
-         WICBitmapCacheOnLoad, &pWICBitmap);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pD2DFactory->CreateWicBitmapRenderTarget(
-         pWICBitmap, D2D1::RenderTargetProperties(), &pRT);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pDWriteFactory->CreateTextFormat(
-          fontFamily,
-          NULL,
-          DWRITE_FONT_WEIGHT_NORMAL,
-          italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
-          DWRITE_FONT_STRETCH_NORMAL,
-          fontSize,
-          L"", //locale
-          &pTextFormat);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    if (elements.size() > 0)
-    {
-      // if first element has right-align marker, act accordingly
-      if (elements[0].Right)
-      {
-        pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
-        pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR);
-      } 
-      else
-      {
-        pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
-        pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
-      }
-
-      pTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM, 
-        elements[0].LineSpacing, elements[0].Baseline);
-    }
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pDWriteFactory->CreateTextLayout(allText.c_str(), allText.size(),
-      pTextFormat, width, height, &pTextLayout);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    pDWriteFactory->CreateTypography(&pTypography);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    // iteratively apply typography settings to range
-    int passedChars = 0;
-    for (vme::const_iterator it = elements.begin(); it != elements.end(); it++)
-    {
-      IDWriteTypography* t;
-      pDWriteFactory->CreateTypography(&t);
-      
-      // choose typography features
-      MarkupElement me = *it;
-      
-      if (me.SmallCaps)
-      {
-        DWRITE_FONT_FEATURE f;
-        f.nameTag = DWRITE_FONT_FEATURE_TAG_SMALL_CAPITALS;
-        f.parameter = 1;
-        t->AddFontFeature(f);
-      }
-
-      if (me.ContextualLigatures)
-      {
-        DWRITE_FONT_FEATURE f;
-        f.nameTag = DWRITE_FONT_FEATURE_TAG_CONTEXTUAL_LIGATURES;
-        f.parameter = 1;
-        t->AddFontFeature(f);
-      }
-
-      if (me.StandardLigatures)
-      {
-        DWRITE_FONT_FEATURE f;
-        f.nameTag = DWRITE_FONT_FEATURE_TAG_STANDARD_LIGATURES;
-        f.parameter = 1;
-        t->AddFontFeature(f);
-      }
-
-      // swash
-      if (me.Swash)
-      {
-        DWRITE_FONT_FEATURE f;
-        f.nameTag = DWRITE_FONT_FEATURE_TAG_SWASH;
-        f.parameter = 1;
-        t->AddFontFeature(f);
-      }
-
-      // right-alignment (hack!)
-      if (me.Right)
-      {
-        pTextLayout->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR);
-        pTextLayout->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
-      }
-
-      // stylistic sets - this is tricky
-      if (me.StylisticSet > 0 && me.StylisticSet <= 20)
-      {
-        DWRITE_FONT_FEATURE f;
-        f.parameter = 1;
-        switch (me.StylisticSet)
-        {
-        case 1:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_1;
-          break;
-        case 2:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_2;
-          break;
-        case 3:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_3;
-          break;
-        case 4:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_4;
-          break;
-        case 5:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_5;
-          break;
-        case 6:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_6;
-          break;
-        case 7:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7;
-          break;
-        case 8:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_8;
-          break;
-        case 9:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_9;
-          break;
-        case 10:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_10;
-          break;
-        case 11:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_11;
-          break;
-        case 12:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_12;
-          break;
-        case 13:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_13;
-          break;
-        case 14:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_14;
-          break;
-        case 15:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_15;
-          break;
-        case 16:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_16;
-          break;
-        case 17:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_17;
-          break;
-        case 18:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_18;
-          break;
-        case 19:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_19;
-          break;
-        case 20:
-          f.nameTag = DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_20;
-          break;
-        }
-        t->AddFontFeature(f);
-      }
-
-      // make sure that kerning is on
-      {
-        DWRITE_FONT_FEATURE f;
-        f.nameTag = DWRITE_FONT_FEATURE_TAG_KERNING;
-        f.parameter = 1;
-        t->AddFontFeature(f);
-      }
-
-      // form the range to which 
-      DWRITE_TEXT_RANGE range;
-      range.startPosition = passedChars;
-      range.length = me.Text.length();
-
-      // set typography
-      pTextLayout->SetTypography(t, range);
-
-      // set basic non-OT features
-      pTextLayout->SetFontSize(me.Size, range);
-      pTextLayout->SetFontFamilyName(me.FontFamily.c_str(), range);
-      pTextLayout->SetFontStyle(
-        me.Italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
-        range);
-
-      // none of these do anything :(
-      //hr = pTextLayout->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 10.0f, 8.0f);
-      hr = pTextLayout->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM, me.LineSpacing, me.Baseline);
-      //hr = pTextLayout->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 100.0f, 100.0f);
-
-      if (me.Color != 0)
-      {
-        CComPtr<ID2D1SolidColorBrush> brush;
-        hr = pRT->CreateSolidColorBrush(D2D1::ColorF(me.Color), &brush);
-        IUnknown* punk;
-        brush->QueryInterface(IID_IUnknown, (void**)&punk);
-        pTextLayout->SetDrawingEffect(punk, range);
-      }
-      
-      typographies.push_back(t);
-      passedChars += range.length;
-    }
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pRT->CreateSolidColorBrush(
-      D2D1::ColorF(D2D1::ColorF::Black),
-      &pBlackBrush);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    pRT->BeginDraw();
-
-    pRT->Clear(D2D1::ColorF(D2D1::ColorF::White));
-
-    D2D1_SIZE_F rtSize = pRT->GetSize();
-
-	pRT->DrawTextLayout(D2D1::Point2F(0.0F, rtSize.height / 2.0f), pTextLayout, pBlackBrush);
-
-    hr = pRT->EndDraw();
-  }
-
-  // never mind now...
-  WICRect r;
-  r.X = r.Y = 0;
-  r.Width = width;
-  r.Height = height;
-  hr = pWICBitmap->CopyPixels(&r, stride, sizeof(Pixel) * width * height, dst);
-
-  SafeRelease(&pTypography);
-  SafeRelease(&pWICFactory);
-  SafeRelease(&pD2DFactory);
-  SafeRelease(&pDWriteFactory);
-  SafeRelease(&pWICBitmap);
-  SafeRelease(&pRT);
-  SafeRelease(&pTextFormat);
-  SafeRelease(&pTextLayout);
-  SafeRelease(&pBlackBrush);
-
-  for (int i = 0; i < typographies.size(); ++i)
-    SafeRelease(&typographies[i]);
-}

File Typografix.Bitmap/.wave-vs.net.backup/Typografix.Bitmap._30_3_2011_21_54_49_.cpp.info

-BackupReason=wave-vs.net Session to Jesus Salas, 
-File=Typografix.Bitmap._30_3_2011_21_54_49_.cpp

File Typografix.Bitmap/.wave-vs.net.backup/Typografix.Bitmap._4_4_2011_16_37_11_.cpp

-#include "stdafx.h"
-#include "common.h"
-#include "Typografix.Bitmap.h"
-#include "Typografix.MarkupParser.cpp"
-
-void StringSplit(string str, string delim, vector<string> results)
-{
-  int cutAt;
-  while((cutAt = str.find_first_of(delim)) != str.npos)
-  {
-    if(cutAt > 0)
-    {
-      results.push_back(str.substr(0,cutAt));
-    }
-    str = str.substr(cutAt+1);
-  }
-  if(str.length() > 0)
-  {
-    results.push_back(str);
-  }
-}
-
-// dst must be same size as src
-MYAPI void Coalesce(BYTE* src, BYTE* dst, int width, int height, int stride)
-{
-  #pragma omp parallel for
-  for (int y = 0; y < height; ++y) {
-    int y_offset = y * stride;
-    for (int x = 2; x < (width - 2); ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      Pixel& d = *reinterpret_cast<Pixel*>(dst + offset);
-      Pixel& r1 = *reinterpret_cast<Pixel*>(src + (offset + sizeof(Pixel)));
-      Pixel& r2 = *reinterpret_cast<Pixel*>(src + (offset + 2*sizeof(Pixel)));
-      Pixel& l1 = *reinterpret_cast<Pixel*>(src + (offset - sizeof(Pixel)));
-      Pixel& l2 = *reinterpret_cast<Pixel*>(src + (offset - 2*sizeof(Pixel)));
-      // изменяем d
-      d.Blue = 0;
-      d.Green = 0;
-      d.Red = 0;
-      UINT result = (l2.Alpha >> 3) + (l1.Alpha >> 2) + (s.Alpha >> 1) + (r1.Alpha >> 2) + (r2.Alpha >> 3);
-      d.Alpha = result > 0xff ? 0xff : (BYTE)result;
-    }
-  }
-}
-
-MYAPI RECT MeasureCropArea(BYTE* src, int width, int height, int stride, int color)
-{
-  Pixel& bgr = *reinterpret_cast<Pixel*>(&color);
-  RECT result;
-
-  // find the first non-conforming row of pixels
-  for (int y = 0; y < height; ++y) 
-  {
-    int y_offset = y * stride;
-    for (int x = 0; x < width; ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the row
-      if (s != bgr)
-      {
-        result.top = y;
-        // cause soft eject
-        x = width;
-        y = height;
-      }
-    }
-  }
-
-  // find the last non-conforming row of pixels
-  for (int y = height - 1; y >= 0; --y) 
-  {
-    int y_offset = y * stride;
-    for (int x = 0; x < width; ++x)
-    {
-      int offset = x * sizeof(Pixel) + y_offset;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the row
-      if (s != bgr)
-      {
-        result.bottom = y;
-        // cause soft eject
-        x = width;
-        y = -1;
-      }
-    }
-  }
-
-  // find the first non-conforming column of pixels
-  for (int x = 0; x < width; ++x)
-  {
-    for (int y = 0; y < height; ++y) 
-    {
-      int offset = x * sizeof(Pixel) + y * stride;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the column
-      if (s != bgr)
-      {
-        result.left = x;
-        // cause soft eject
-        x = width;
-        y = height;
-      }
-    }
-  }
-
-  // find the last non-conforming column of pixels
-  for (int x = width - 1; x >= 0; --x)
-  {
-    for (int y = 0; y < height; ++y) 
-    {
-      int offset = x * sizeof(Pixel) + y * stride;
-      Pixel& s = *reinterpret_cast<Pixel*>(src + offset);
-      // if this pixel is non-conforming, so is the column
-      if (s != bgr)
-      {
-        result.right = x;
-        // cause soft eject
-        x = -1;
-        y = height;
-      }
-    }
-  }
-
-  int w = result.right - result.left;
-  int h = result.bottom - result.top;
-  if (w < 1) { result.left = 0; result.right = 1; }
-  if (h < 1) { result.top = 0; result.bottom = 1; }
-  return result;
-}
-
-MYAPI void Fold(BYTE* src, BYTE* dst, int dstWidth, int height, int srcStride, int dstStride)
-{
-  #pragma omp parallel for
-  for (int y = 0; y < height; ++y)
-  {
-    int src_y_offset = y * srcStride;
-    int dst_y_offset = y * dstStride;
-    for (int x = 0; x < dstWidth; ++x)
-    {
-      int dst_offset = x * sizeof(Pixel) + dst_y_offset;
-      Pixel& d = *reinterpret_cast<Pixel*>(dst + dst_offset);
-
-      int r_offset = x * 3 * sizeof(Pixel) + src_y_offset;
-      int g_offset = (x * 3 + 1) * sizeof(Pixel) + src_y_offset;
-      int b_offset = (x * 3 + 2) * sizeof(Pixel) + src_y_offset;
-      Pixel& r = *reinterpret_cast<Pixel*>(src + r_offset);
-      Pixel& g = *reinterpret_cast<Pixel*>(src + g_offset);
-      Pixel& b = *reinterpret_cast<Pixel*>(src + b_offset);
-
-      // let's do it
-      d.Alpha = 0xff;
-      d.Red = 0xff - r.Alpha;
-      d.Green = 0xff - g.Alpha;
-      d.Blue = 0xff - b.Alpha;
-    }
-  }
-}
-
-MYAPI void RenderMarkup(BYTE* dst, LPCWSTR markup, int width, int height, 
-                        int stride, LPCWSTR fontFamily, float fontSize,
-                        bool smallCaps, bool italic, bool contextualLigatures,
-                        bool standardLigatures, bool swash, int stylisticSet,
-                        float lineSpacing, float baseline)
-{
-  HRESULT hr = S_OK;
-
-  IWICImagingFactory *pWICFactory = NULL;
-  ID2D1Factory *pD2DFactory = NULL;
-  IDWriteFactory *pDWriteFactory = NULL;
-  IWICBitmap *pWICBitmap = NULL;
-  ID2D1RenderTarget *pRT = NULL;
-  IDWriteTextFormat *pTextFormat = NULL;
-  ID2D1SolidColorBrush *pBlackBrush = NULL;
-  IDWriteTextLayout *pTextLayout = NULL;
-  IDWriteTypography *pTypography = NULL;
-
-  vector<IDWriteTypography*> typographies;
-
-  // build the prototype markup element
-  MarkupElement prototype;
-  prototype.FontFamily = wstring(fontFamily);
-  prototype.Size = fontSize;
-  prototype.Italic = italic;
-  prototype.SmallCaps = smallCaps;
-  prototype.ContextualLigatures = contextualLigatures;
-  prototype.StandardLigatures = standardLigatures;
-  prototype.Swash = swash;
-  prototype.StylisticSet = stylisticSet;
-  prototype.LineSpacing = lineSpacing;
-  prototype.Baseline = baseline;
-  prototype.Right = false;
-  prototype.Color = 0;
-
-  // parse the markup
-  vector<MarkupElement> elements = MarkupParser::Parse(wstring(markup), prototype);
-
-  // get the total text
-  vector<wchar_t> vTemp;
-  for (vme::const_iterator it = elements.begin(); it != elements.end(); it++)
-  {
-    for (int i = 0; i < (*it).Text.length(); ++i)
-      vTemp.push_back((*it).Text[i]);
-  }
-  wstring allText(vTemp.begin(), vTemp.end());
-
-  hr = CoCreateInstance(
-    CLSID_WICImagingFactory,
-    NULL,
-    CLSCTX_INPROC_SERVER,
-    IID_IWICImagingFactory,
-    reinterpret_cast<void **>(&pWICFactory));
-
-  if (SUCCEEDED(hr))
-  {
-    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = DWriteCreateFactory(
-         DWRITE_FACTORY_TYPE_SHARED,
-         __uuidof(pDWriteFactory),
-         reinterpret_cast<IUnknown **>(&pDWriteFactory));
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pWICFactory->CreateBitmap(width, height,
-         GUID_WICPixelFormat32bppBGR,
-         WICBitmapCacheOnLoad, &pWICBitmap);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pD2DFactory->CreateWicBitmapRenderTarget(
-         pWICBitmap, D2D1::RenderTargetProperties(), &pRT);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pDWriteFactory->CreateTextFormat(
-          fontFamily,
-          NULL,
-          DWRITE_FONT_WEIGHT_NORMAL,
-          italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
-          DWRITE_FONT_STRETCH_NORMAL,
-          fontSize,
-          L"", //locale
-          &pTextFormat);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    if (elements.size() > 0)
-    {
-      // if first element has right-align marker, act accordingly
-      if (elements[0].Right)
-      {
-        pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_TRAILING);
-        pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_FAR);
-      } 
-      else
-      {
-        pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
-        pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
-      }
-
-      pTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_UNIFORM, 
-        elements[0].LineSpacing, elements[0].Baseline);
-    }
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    hr = pDWriteFactory->CreateTextLayout(allText.c_str(), allText.size(),
-      pTextFormat, width, height, &pTextLayout);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    pDWriteFactory->CreateTypography(&pTypography);
-  }
-
-  if (SUCCEEDED(hr))
-  {
-    // iteratively apply typography settings to range
-    int passedChars = 0;
-    for (vme::const_iterator it = elements.begin(); it != elements.end(); it++)
-    {
-      IDWriteTypography* t;
-      pDWriteFactory->CreateTypography(&t);
-      
-      // choose typography features
-      MarkupElement me = *it;