Пример #1
0
        /// <summary>
        /// Vyrenderuje dodaný text jako náhradní ikonu
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="sizeType"></param>
        /// <param name="imageSize"></param>
        /// <returns></returns>
        public static Image CreateCaptionImage(string caption, ResourceImageSizeType?sizeType, Size?imageSize)
        {
            var    realSize = imageSize ?? DxComponent.GetImageSize((sizeType ?? ResourceImageSizeType.Large), true);
            bool   isDark   = DxComponent.IsDarkTheme;
            Bitmap bitmap   = new Bitmap(realSize.Width, realSize.Height);

            using (var graphics = Graphics.FromImage(bitmap))
            {
                RectangleF bounds = new RectangleF(0, 0, realSize.Width, realSize.Height);
                graphics.FillRectangle((isDark ? Brushes.MidnightBlue : Brushes.MintCream), bounds);
                string text = DxComponent.GetCaptionForIcon(caption);
                if (text.Length > 0)
                {
                    var font       = SystemFonts.MenuFont;
                    var textSize   = graphics.MeasureString(text, font);
                    var textBounds = textSize.AlignTo(bounds, ContentAlignment.MiddleCenter);
                    graphics.DrawString(text, font, (isDark ? Brushes.White : Brushes.Black), textBounds.Location);
                }
            }
            return(bitmap);
        }
Пример #2
0
        /// <summary>
        /// Vytvoří <see cref="SvgImage"/> pro daný text, namísto chybějící ikony.
        /// Pokud vrátí null, zkusí se provést <see cref="CreateCaptionImage(string, ResourceImageSizeType?, Size?)"/>.
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="sizeType"></param>
        /// <param name="imageSize"></param>
        /// <returns></returns>
        public static SvgImage CreateCaptionVector(string caption, ResourceImageSizeType?sizeType, Size?imageSize)
        {
            string text = DxComponent.GetCaptionForIcon(caption).ToUpper();

            if (text.Length > 2)
            {
                text = text.Substring(0, 2);
            }
            bool   isWidth     = (text == "MM" || text == "OO" || text == "WW" || text == "QQ" || text == "AA");
            string fillClass   = "White";
            string borderClass = "Blue";
            string textClass   = "Black";
            string sizePx      = (isWidth ? "16px" : "18px");
            string textY       = (isWidth ? "20" : "22");
            string weight      = (isWidth ? "600" : "800"); // bold
            string svgContent  = @"<?xml version='1.0' encoding='UTF-8'?>
<svg x='0px' y='0px' viewBox='0 0 32 32' 
        version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' 
        id='Layer_1' 
        style='enable-background:new 0 0 32 32'>
  <style type='text/css'>
	.White{fill:#FFFFFF;}
	.Red{fill:#D11C1C;}
	.Green{fill:#039C23;}
	.Blue{fill:#1177D7;}
	.Yellow{fill:#FFB115;}
	.Black{fill:#727272;}
	.st0{opacity:0.75;}
	.st1{opacity:0.5;}
  </style>
  <g id='icon" + text + @"' style='font-size: " + sizePx + @"; text-anchor: middle; font-family: serif; font-weight: " + weight + @"'>
    <path d='M31,0H1C0.5,0,0,0.5,0,1v30c0,0.5,0.5,1,1,1h30c0.5,0,1-0.5,1-1V1C32,0.5,31.5,0,31,0z M30,30H2V2h28V30z' class='" + borderClass + @"' />
    <path d='M30,30H2V2h28V30z' class='" + fillClass + @"' />
    <text x='16' y='" + textY + @"' class='" + textClass + @"'>" + text + @"</text>
  </g>
</svg>";

            svgContent = svgContent.Replace("'", "\"");
            return(DxSvgImage.Create(caption, DxSvgImagePaletteType.Explicit, svgContent));

            /*
             *
             * <?xml version='1.0' encoding='UTF-8'?>
             * <svg x="0px" y="0px" viewBox="0 0 32 32"
             * version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
             * id="Layer_1"
             * style="enable-background:new 0 0 32 32">
             * <style type="text/css">
             * .Red{fill:#D11C1C;}
             * .Green{fill:#039C23;}
             * .Blue{fill:#1177D7;}
             * .Yellow{fill:#FFB115;}
             * .Black{fill:#727272;}
             * .st0{opacity:0.75;}
             * .st1{opacity:0.5;}
             * </style>
             * <g id="iconAB" style="font-size: 16px; text-anchor: middle; font-family: serif; font-weight: bold">
             * <path d="M31,0H1C0.5,0,0,0.5,0,1v30c0,0.5,0.5,1,1,1h30c0.5,0,1-0.5,1-1V1C32,0.5,31.5,0,31,0z M30,30H2V2h28V30z" class="Black" />
             * <!--  path d="M0,0L31,0L31,31L0,31L0,0Z" class="Black" / -->
             * <text x="16" y="20" class="Blue">MM</text>
             * </g>
             * </svg>
             *
             */
        }