Example #1
0
 private IImageAdapter RenderGlyphs(GlyphBase[] glyphs, IImageAdapter renderSurface)
 {
     foreach (GlyphBase glyphBase in glyphs)
     {
         Point pt = new Point((int)(glyphBase.Position.X + .5), (int)(glyphBase.Position.Y + .5));
         renderSurface = ImageUtility.CopyImageAdapter(renderSurface, glyphBase.Render(), pt, glyphBase.Size, true);
     }
     return(renderSurface);
 }
Example #2
0
        /// <summary>
        /// Image of the text
        /// </summary>
        private IImageAdapter GetTypoResult()
        {
            int          maxX = 0;
            int          maxY = 0;
            ITypographer avtp = TypographerBroker.Instance;

            foreach (GlyphChar glyphChar in Glyphs)
            {
                int x = (int)(glyphChar.ComputedLayout.SizeF.Width + glyphChar.ComputedLayout.PositionF.X + .5);
                int y = (int)(glyphChar.ComputedLayout.SizeF.Height + glyphChar.ComputedLayout.PositionF.Y + .5);
                if (x > maxX)
                {
                    maxX = x;
                }
                if (y > maxY)
                {
                    maxY = y;
                }
            }
            IImageAdapter retVal = new ImageAdapter(maxX, maxY, BackgroundColor);

//                    IImageAdapter imageChar = null;
//                    for (int t = 0; t < _text.Count; t++)
            foreach (GlyphChar glyphChar in Glyphs)
            {
                // HACK : Call Render Char one more time but ignore Background color
                avtp.Text                = glyphChar.Character.ToString();
                avtp.FontSize            = Font.Size;
                avtp.FontName            = Font.Name;
                avtp.BackgroundColor     = BackgroundColor;
                avtp.ForegroundColor     = ForegroundColor;
                avtp.TextRenderingHint   = TextRenderingHint;
                glyphChar.GeneratedImage = avtp.Render();

                Point offset             = glyphChar.ComputedLayout.Position;
                System.Drawing.Size size = new System.Drawing.Size(glyphChar.GeneratedImage.Width, glyphChar.GeneratedImage.Height);
                retVal = ImageUtility.CopyImageAdapter(retVal, glyphChar.GeneratedImage, offset, size, true);
            }

            return(retVal);
        }
Example #3
0
        private ImageAdapter GetTransformedContent(IImageAdapter imageAdapter, double[] transformMatrix, int width, int height)
        {
            // validate the variation
            //extract the popup from the original
            GlyphModel glmodel = new GlyphModel();

            //todo work with the minsize bounding box - add the transfrom from XTC
            glmodel.Size = new System.Drawing.Size(width, height);

            GlyphImage glimage = new GlyphImage(glmodel);

            glmodel.Glyphs.Add(glimage);
            ImageUtility.ToImageFile(imageAdapter, "foo.png", ImageFormat.Png);
            glimage.Path                   = "foo.png";
            transformMatrix[1]             = -transformMatrix[1];
            transformMatrix[2]             = -transformMatrix[2];
            glimage.Panel.Transform.Matrix = transformMatrix;

            double[] ltrans = glimage.Panel.Transform.Matrix;
            double   minX   = double.MaxValue;
            double   minY   = double.MaxValue;
            double   maxX   = double.MinValue;
            double   maxY   = double.MinValue;

            double[,] tp = new double[, ] {
                { 0, 0 }, { imageAdapter.Width, 0 }, { 0, imageAdapter.Height }, { imageAdapter.Width, imageAdapter.Height }
            };

            for (int j = 0; j < 4; j++)
            {
                double lxp = ltrans[0] * tp[j, 0] + ltrans[1] * tp[j, 1] + ltrans[4];
                double lyp = ltrans[2] * tp[j, 0] + ltrans[3] * tp[j, 1] + ltrans[5];

                _contentLocation[j, 0] = lxp;
                _contentLocation[j, 1] = lyp;
                Console.WriteLine(lxp + "," + lyp);
                if (lxp > maxX)
                {
                    maxX = lxp;
                }

                if (lyp > maxY)
                {
                    maxY = lyp;
                }

                if (lxp < minX)
                {
                    minX = lxp;
                }

                if (lyp < minY)
                {
                    minY = lyp;
                }
            }

            _imageAdapterXmin = minX;
            _imageAdapterYmin = minY;
            Console.WriteLine(minX + " " + minY + "    " + maxX + " " + maxY);
            transformMatrix[1]             = -transformMatrix[1];
            transformMatrix[2]             = -transformMatrix[2];
            glimage.Panel.Transform.Matrix = transformMatrix;

            ImageAdapter res    = new ImageAdapter((int)(maxX - minX), (int)(maxY - minY));
            ImageAdapter buffer = new ImageAdapter(glmodel.Size.Width, glmodel.Size.Height);

            glimage.Render();
            Point pt = new Point((int)(glimage.Position.X + .5), (int)(glimage.Position.Y + .5));

            ImageUtility.CopyImageAdapter(buffer, glimage.GeneratedImage, pt, glimage.Size, true);

            int mixx = int.MaxValue;
            int mixy = int.MaxValue;

            for (int j = 0; j < buffer.Width; j++)
            {
                for (int i = 0; i < buffer.Height; i++)
                {
                    if (buffer[j, i].Alpha != 0)
                    {
                        if (j < mixx)
                        {
                            mixx = j;
                        }

                        if (i < mixy)
                        {
                            mixy = i;
                        }
                    }
                }
            }

            Console.WriteLine("comp " + mixx + " " + mixy);
            for (int j = 0; j < res.Width; j++)
            {
                for (int i = 0; i < res.Height; i++)
                {
                    if (j + mixx >= 0 && j + mixx < buffer.Width && i + mixy >= 0 && i + mixy < buffer.Height)
                    {
                        res[j, i] = buffer[j + mixx, i + mixy];
                    }
                }
            }
            string path = "TransPost.png";

#if DEBUG
            ImageUtility.ToImageFile(res, path);
#endif
            glimage.Path = path;
            return(res);
        }
Example #4
0
        /// <summary>
        /// Renders the glyph in an IImageAdapter
        /// </summary>
        public virtual IImageAdapter Render()
        {
            IImageAdapter retVal = _Render();

            // Apply potential transform and draw self
            if (Panel.Transform.Matrix.IsIdentity == false)
            {
                retVal = Panel.Transform.Process(retVal);
                Size   = new Size(retVal.Width, retVal.Height);
            }

            // Perform Layout
            Image2DTransforms layoutTransform = new Image2DTransforms(retVal);

            layoutTransform.ResizeToFitOutputImage = true;
            Matrix2D matrix = layoutTransform.Matrix;

            switch (Panel.PanelLayoutMode)
            {
            case PanelLayoutMode.None:
                break;

            case PanelLayoutMode.Center:
                float x = (Panel.Size.Width - Size.Width) / 2;
                float y = (Panel.Size.Height - Size.Height) / 2;
                Position = new PointF(Position.X + x, Position.Y + y);
                break;

            case PanelLayoutMode.Stretch:
                layoutTransform.ScaleTransform(Panel.Size.Width / Size.Width, Panel.Size.Height / Size.Height);
                break;

            case PanelLayoutMode.Zoom:
                double ratio = Math.Min(Panel.Size.Width / Size.Width, Panel.Size.Height / Size.Height);
                layoutTransform.ScaleTransform(ratio, ratio);
                break;

            case PanelLayoutMode.Tile:
                throw new NotImplementedException("Contact the Avalon tool team if you need this feature");

//                            break;
            default:
                throw new ArgumentException("Unexpected value for GlyphImageLayoutOut (Should never occur since value was checked in setter -- except if private value changed thru reflection)");
            }
            layoutTransform.ApplyTransforms();
            IImageAdapter transformed = layoutTransform.ImageTransformed;

            Point offset = new Point((int)(Position.X + .5), (int)(Position.Y + .5));

            retVal = new ImageAdapter((int)Panel.Size.Width, (int)Panel.Size.Height, Panel.Color);
            retVal = ImageUtility.CopyImageAdapter(retVal, transformed, offset, new Size(transformed.Width, transformed.Height), true);
            // Apply opacity if needed
            if (_panel.Opacity != 1.0)
            {
                for (int y = 0; y < retVal.Height; y++)
                {
                    for (int x = 0; x < retVal.Width; x++)
                    {
                        retVal[x, y].ExtendedAlpha *= _panel.Opacity;
                    }
                }
            }

            // update Image
            GeneratedImage = retVal;

            return(retVal);
        }
Example #5
0
        override internal IImageAdapter _Render()
        {
            IImageAdapter retVal = null;

            // Render ever glyph hosted by this container
            foreach (GlyphBase glyph in Glyphs)
            {
                glyph.Render();
            }

            // Perform Layout
            LayoutEngine.Container = this;
            LayoutEngine.ArrangeGlyphs();
            LayoutEngine.Container = null;

            // Compute final Image Size
            if (Panel.Size == SizeF.Empty)
            {
                float maxWidth  = 0f;
                float maxHeight = 0f;
                foreach (GlyphBase glyph in Glyphs)
                {
                    if (glyph.ComputedLayout.PositionF.X + glyph.ComputedLayout.SizeF.Width > maxWidth)
                    {
                        maxWidth = glyph.ComputedLayout.PositionF.X + glyph.ComputedLayout.SizeF.Width;
                    }
                    if (glyph.ComputedLayout.PositionF.Y + glyph.ComputedLayout.SizeF.Height > maxHeight)
                    {
                        maxHeight = glyph.ComputedLayout.PositionF.Y + glyph.ComputedLayout.SizeF.Height;
                    }
                }
                retVal = new ImageAdapter((int)(maxWidth + .5f), (int)(maxHeight + .5f), BackgroundColor);
            }
            else
            {
                retVal = new ImageAdapter((int)(Panel.Size.Width + .5f), (int)(Panel.Size.Width + .5f), BackgroundColor);
            }

            //Render final Image
            foreach (GlyphBase glyph in Glyphs)
            {
                retVal = ImageUtility.CopyImageAdapter(retVal, glyph.GeneratedImage, glyph.ComputedLayout.Position, glyph.ComputedLayout.Size, true);
            }

            return(retVal);


/*
 *                  LayoutEngine.ArrangeGlyphs((GlyphBase[])Glyphs.ToArray(typeof(GlyphBase)));
 *
 *                  IImageAdapter retVal = null;
 *                  int maxWidth = 0;
 *                  int maxHeight = 0;
 *                  // Determine the size of IImageAdapter
 *                  foreach (GlyphBase glyph in Glyphs)
 *                  {
 *                      if (glyph.Layout.PositionF.X + glyph.Layout.SizeF.Width > maxWidth) { maxWidth = (int)(glyph.Layout.PositionF.X + glyph.Layout.SizeF.Width); }
 *                      if (glyph.Layout.PositionF.Y + glyph.Layout.SizeF.Height > maxHeight) { maxHeight = (int)(glyph.Layout.PositionF.Y + glyph.Layout.SizeF.Height); }
 *                  }
 *                  retVal = new ImageAdapter(maxWidth, maxHeight, ColorByte.Empty);
 *
 *
 *                  foreach(GlyphBase glyph in Glyphs)
 *                  {
 *                      IImageAdapter image = glyph._Render();
 *                      retVal = ImageUtility.CopyImageAdapter(retVal, image, glyph.Layout.Position, glyph.Layout.Size, true);
 *                  }
 *
 *                  // Update Image
 *                  Image = retVal;
 *
 *                  return retVal;
 */
        }