Example #1
0
 public static void MergeArtOverlay(Graphics graphics, BlockDefinition overlay)
 {
     using (Bitmap temp = GraphicUtils.LoadImage(overlay.src, PixelFormat.Format32bppArgb))
     {
         graphics.DrawImage(temp, overlay.location.x, overlay.location.y, overlay.wordwrap.width, overlay.wordwrap.height);
     }
 }
Example #2
0
 public void AddBlock(BlockDefinition block)
 {
     if (ContainsBlock(block))
     {
         blocks.Remove(block);
     }
     blocks.Add(block);
 }
Example #3
0
        public bool ContainsBlock(BlockDefinition block)
        {
            bool ret = false;

            foreach (BlockDefinition findBlock in blocks)
            {
                if (findBlock.id == block.id)
                {
                    return (true);
                }
            }

            return (ret);
        }
        public static new BlockDefinition LoadSectionDefinition(BlockManager manager, XmlNode node)
        {
            BlockDefinition ret = new BlockDefinition();
            ret.Manager = manager;

            ret.type = "overlay";

            foreach (XmlNode prop in node.ChildNodes)
            {
                if (TemplateDefinition.SkipNode(prop))
                {
                    continue;
                }
                if (prop.Name.Equals("location"))
                {
                    ret.location.x = int.Parse(prop.Attributes["x"].Value);
                    ret.location.y = int.Parse(prop.Attributes["y"].Value);
                    //if (prop.Attributes["rotate"] != null)
                    //{
                    //    ret.location.rotate = int.Parse(prop.Attributes["rotate"].Value);
                    //}
                    //if (prop.Attributes["altrotate"] != null)
                    //{
                    //    ret.location.altrotate = bool.Parse(prop.Attributes["altrotate"].Value);
                    //}
                    //if (prop.Attributes["flip"] != null)
                    //{
                    //    ret.location.flip = bool.Parse(prop.Attributes["flip"].Value);
                    //}
                }
                if(prop.Name.Equals("size"))
                {
                    ret.wordwrap.height = int.Parse(prop.Attributes["height"].Value);
                    ret.wordwrap.width = int.Parse(prop.Attributes["width"].Value);
                }
            }
            return (ret);
        }
Example #5
0
        public static GraphicsPath GetTextPath(BlockDefinition section, string text, Graphics graphics)
        {
            GraphicsPath myPath = new GraphicsPath();
            FontFamily family = new FontFamily("Arial");
            FontStyle fontStyle = FontStyle.Regular;
            if (section.text.font != null && File.Exists(Path.Combine(section.Manager.RootPath, section.text.font)))
            {
                PrivateFontCollection col = new PrivateFontCollection();
                col.AddFontFile(Path.Combine(section.Manager.RootPath, section.text.font));
                family = col.Families[0];
                bool fontStyleFound = false;
                foreach (var fontstyleEnum in Enum.GetValues(typeof(FontStyle)))
                {
                    if (family.IsStyleAvailable(((FontStyle)fontstyleEnum)))
                    {
                        fontStyle = (FontStyle)fontstyleEnum;
                        fontStyleFound = true;
                        break;
                    }
                    foreach (var secondStyle in Enum.GetValues(typeof(FontStyle)))
                    {
                        var combinedStyle = ((FontStyle)fontstyleEnum) | ((FontStyle)secondStyle);
                        if (family.IsStyleAvailable(combinedStyle))
                        {
                            fontStyle = combinedStyle;
                            fontStyleFound = true;
                            break;
                        }
                    }
                }
                if (!fontStyleFound)
                {
                    family = new FontFamily("Arial");
                }
            }
            int size = section.text.size;

            int minsize = 6;

            Point location = section.location.ToPoint();
            StringFormat format = StringFormat.GenericDefault;
            if (section.wordwrap.height > 0)
            {
                format = new StringFormat();
                format.Alignment = GetAlignment(section.wordwrap.align);
                format.LineAlignment = GetAlignment(section.wordwrap.valign);
                Size block = section.wordwrap.ToSize();
                Rectangle rect = new Rectangle(location, block);
                if (section.wordwrap.shrinkToFit)
                {
                    GraphicsUnit original = graphics.PageUnit;
                    graphics.PageUnit = GraphicsUnit.Point;  // Convert the PageUnit to Point just long enough to get an accurate measurement.
                    Font tempfont = new Font(family, size, fontStyle); // Create the font for the measurement.
                    SizeF unwrappedSize = graphics.MeasureString(text, tempfont);
                    if (unwrappedSize.Height > section.wordwrap.height)
                    {
                        if (unwrappedSize.Width > section.wordwrap.width)
                        {
                            int sizePerIncrement = (int)Math.Round((double)(unwrappedSize.Width / size), MidpointRounding.ToEven);
                            size = (int)Math.Round((double)(rect.Width / sizePerIncrement), MidpointRounding.ToEven);
                            size = (size < minsize) ? minsize : size;
                            tempfont = new Font(family, size, fontStyle);
                        }
                    }
                    else
                    {

                        float measuredHeight = graphics.MeasureString(text, tempfont, rect.Width, format).Height;
                        if (rect.Height < measuredHeight)
                        {
                             int sizePerIncrement = (int)Math.Round((double)(measuredHeight / unwrappedSize.Height), MidpointRounding.ToEven); //unwrappedSize.Height seems to be a better method of getting sizePerIncrement.
                            size = (int)Math.Round((double)(rect.Height / sizePerIncrement), MidpointRounding.ToEven);
                            size = (size < minsize) ? minsize : size;
                            tempfont = new Font(family, size, fontStyle);
                        }
                    }
                    while (size > minsize && rect.Height < graphics.MeasureString(text, tempfont, rect.Width, format).Height) // Compare the height of the rendered text to the bounding box.  If it's larger
                    {
                        size -= 1; // Reduce the size, test again.
                        tempfont = new Font(family, size, fontStyle); // REcreate the font in the new size
                    }
                    // end addition
                    graphics.PageUnit = original; // Change the PageUnit back to display.
                }
                myPath.AddString(text,
                family,
                (int)fontStyle,
                size,
                rect,
                format);
            }
            else
            {
                myPath.AddString(text,
                family,
                (int)fontStyle,
                size,
                location,
                format);
            }
            return myPath;
        }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="section"></param>
        /// <param name="value"></param>
        public static void WriteString(Graphics graphics, BlockDefinition section, string value)
        {
            if (value == null || value == string.Empty)
            {
                return;
            }

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            value = System.Web.HttpUtility.HtmlDecode(value);
            GraphicsPath path = GetTextPath(section, value, graphics);

            if (section.location.flip)
            {
                using (Matrix matrix = new Matrix())
                {

                    matrix.Scale(-1, 1, MatrixOrder.Append);
                    path.Transform(matrix);
                }
                using (Matrix matrix = new Matrix())
                {
                    float min = path.PathPoints.Min(p => p.X);
                    matrix.Translate(((-min)+section.location.x), 0);
                    path.Transform(matrix);
                }
            }

            if (section.location.rotate > 0)
            {
                int rotateMod = section.location.rotate % 360;

                if (!section.location.altrotate)
                {
                    float centerX = 0;
                    float centerY = 0;
                    centerX = section.location.x;
                    centerY = section.location.y;

                    using (Matrix mat = new Matrix())
                    {
                        mat.RotateAt(rotateMod, new PointF(centerX, centerY), MatrixOrder.Append);
                        path.Transform(mat);
                    }
                }
                else
                {
                    using (Matrix matrix = new Matrix())
                    {
                        matrix.Rotate(rotateMod, MatrixOrder.Append);
                        path.Transform(matrix);
                    }
                    using (Matrix matrix = new Matrix())
                    {
                        float minX = path.PathPoints.Min(p => p.X);
                        float minY = path.PathPoints.Min(p => p.Y);
                        matrix.Translate(((-minX) + section.location.x), ((-minY) + section.location.y));
                        path.Transform(matrix);
                    }
                }
            }

            SolidBrush b = new SolidBrush(section.text.color);

            if (section.border.size > 0)
            {
                Pen p = new Pen(section.border.color, section.border.size);
                graphics.DrawPath(p, path);
                graphics.FillPath(b, path);
                p.Dispose();
            }
            else
            {
                graphics.FillPath(b, path);
            }
            b.Dispose();
            path.Dispose();
        }
Example #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="overlay"></param>
 public static void MergeOverlay(Graphics graphics, BlockDefinition overlay)
 {
     using (Image temp = GraphicUtils.LoadImage(overlay.src))
     {
         Bitmap b = ((Bitmap)temp).Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb);
         //b.MakeTransparent();
         graphics.DrawImage(b,overlay.location.x, overlay.location.y, b.Width, b.Height);
         b.Dispose();
     }
 }
Example #8
0
        public static BlockDefinition LoadSectionDefinition(BlockManager manager, XmlNode node)
        {
            BlockDefinition ret = new BlockDefinition();
            ret.Manager = manager;

            ret.id = node.Attributes["id"].Value;
            ret.type = node.Attributes["type"].Value;
            if (node.Attributes["src"] != null)
            {
                ret.src = node.Attributes["src"].Value;
            }
            foreach (XmlNode prop in node.ChildNodes)
            {
                if (TemplateDefinition.SkipNode(prop))
                {
                    continue;
                }
                if (prop.Name.Equals("location"))
                {
                    ret.location.x = int.Parse(prop.Attributes["x"].Value);
                    ret.location.y = int.Parse(prop.Attributes["y"].Value);
                    if (prop.Attributes["rotate"] != null)
                    {
                        ret.location.rotate = int.Parse(prop.Attributes["rotate"].Value);
                    }
                    if (prop.Attributes["altrotate"] != null)
                    {
                        ret.location.altrotate = bool.Parse(prop.Attributes["altrotate"].Value);
                    }
                    if (prop.Attributes["flip"] != null)
                    {
                        ret.location.flip = bool.Parse(prop.Attributes["flip"].Value);
                    }
                }
                if (prop.Name.Equals("text"))
                {
                    ret.text.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value);
                    ret.text.size = int.Parse(prop.Attributes["size"].Value);
                    if (prop.Attributes["font"] != null)
                    {
                        string relativePath = prop.Attributes["font"].Value;
                        string rootPath = manager.RootPath;
                        string combined = Path.Combine(rootPath, relativePath);
                        if (File.Exists(combined))
                        {
                            ret.text.font = relativePath;
                        }
                    }
                }
                if (prop.Name.Equals("border"))
                {
                    ret.border.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value);
                    ret.border.size = int.Parse(prop.Attributes["size"].Value);
                }
                if (prop.Name.Equals("wordwrap"))
                {
                    ret.wordwrap.height = int.Parse(prop.Attributes["height"].Value);
                    ret.wordwrap.width = int.Parse(prop.Attributes["width"].Value);
                    if (prop.Attributes["align"] != null)
                    {
                        ret.wordwrap.align = prop.Attributes["align"].Value;
                    }
                    if (prop.Attributes["valign"] != null)
                    {
                        ret.wordwrap.valign = prop.Attributes["valign"].Value;
                    }
                    if (prop.Attributes["shrinktofit"] != null)
                    {
                        ret.wordwrap.shrinkToFit = bool.Parse(prop.Attributes["shrinktofit"].Value);
                    }
                }
            }

            return (ret);
        }