当前位置: 首页>>代码示例>>C#>>正文


C# ProjectLayoutElement.GetVerticalAlignment方法代码示例

本文整理汇总了C#中CardMaker.XML.ProjectLayoutElement.GetVerticalAlignment方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectLayoutElement.GetVerticalAlignment方法的具体用法?C# ProjectLayoutElement.GetVerticalAlignment怎么用?C# ProjectLayoutElement.GetVerticalAlignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CardMaker.XML.ProjectLayoutElement的用法示例。


在下文中一共展示了ProjectLayoutElement.GetVerticalAlignment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawGraphic

        private static void DrawGraphic(Graphics zGraphics, string sFile, ProjectLayoutElement zElement)
        {
            string sPath = sFile;
            if (sPath.Equals("none", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }
            if (!File.Exists(sPath))
            {
                sPath = ProjectManager.Instance.ProjectPath + sFile;
            }
            if (File.Exists(sPath))
            {
                var zBmp = 255 != zElement.opacity
                    ? LoadOpacityImageFromCache(sPath, zElement)
                    : LoadImageFromCache(sPath);

                int nWidth = zElement.width;
                int nHeight = zElement.height;

                if (zElement.keeporiginalsize)
                {
                    DrawGraphicOriginalSize(zGraphics, zBmp, zElement);
                    return;
                }

                if (zElement.lockaspect)
                {
                    var fAspect = (float)zBmp.Tag;

                    var nTargetHeight = (int)((float)nWidth / fAspect);
                    if (nTargetHeight < nHeight)
                    {
                        nHeight = (int)((float)nWidth / fAspect);
                    }
                    else
                    {
                        nWidth = (int)((float)nHeight * fAspect);
                    }
                }

                int nX = 0;
                int nY = 0;

                // standard alignment adjustment
                UpdateAlignmentValue(zElement.GetHorizontalAlignment(), ref nX, zElement.width, nWidth);
                UpdateAlignmentValue(zElement.GetVerticalAlignment(), ref nY, zElement.height, nHeight);

                zGraphics.DrawImage(zBmp, nX, nY, nWidth, nHeight);

            }
            else
            {
                IssueManager.Instance.FireAddIssueEvent("Image file not found: " + sFile);
            }
            // draw nothing
        }
开发者ID:nhmkdev,项目名称:cardmaker,代码行数:57,代码来源:DrawGraphic.cs

示例2: DrawText

        public void DrawText(Graphics zGraphics, ProjectLayoutElement zElement, string sInput, Brush zBrush, Font zFont, Color colorFont)
        {
            if (null == zFont) // default to something!
            {
                // font will show up in red if it's not yet set
                zFont = DrawItem.DefaultFont;
                zBrush = Brushes.Red;
            }
            var zFormat = new StringFormat
            {
                LineAlignment = zElement.GetVerticalAlignment(),
                Alignment = zElement.GetHorizontalAlignment()
            };

            if (255 != zElement.opacity)
            {
                zBrush = new SolidBrush(Color.FromArgb(zElement.opacity, colorFont));
            }

            if (zElement.autoscalefont)
            {
                SizeF zSize = zGraphics.MeasureString(sInput, zFont, new SizeF(zElement.width, int.MaxValue), zFormat);

                if (zSize.Height > zElement.height || zSize.Width > zElement.width)
                {
                    float newSizeRatio;
                    if ((zSize.Height - zElement.height) > (zSize.Width - zElement.width))
                    {
                        newSizeRatio = (float)zElement.height / (float)zSize.Height;
                    }
                    else
                    {
                        newSizeRatio = (float)zElement.width / (float)zSize.Width;
                    }

                    var scaledFont = new Font(zFont.FontFamily, newSizeRatio * zFont.Size, zFont.Style);
                    //Support.IO.Logger.AddLogLine(scaledFont.Size + " was [" + zFont.Size + "]");
                    zFont = scaledFont;

            #if true            // the preprocessing above will get the font size close but not perfect, the slow code below further refines the size
                    // slow mode - but perfect precision (well arguably with the Graphics.MeasureString)
                    bool bUpscaled = false;
                    if (0 < sInput.Trim().Length)
                    {
                        while (true)
                        {
                            zSize = zGraphics.MeasureString(sInput, zFont, new SizeF(zElement.width, int.MaxValue), zFormat);
                            if (zSize.Height > zElement.height || zSize.Width > zElement.width)
                            {
                                if (zFont.Size == 1)
                                    break;
                                zFont = new Font(zFont.FontFamily, zFont.Size - 1, zFont.Style);
                                if (bUpscaled)
                                    break;
                            }
                            else
                            {
                                zFont = new Font(zFont.FontFamily, zFont.Size + 1, zFont.Style);
                                bUpscaled = true;
                            }
                        }
                        //Support.IO.Logger.AddLogLine("[" + zFont.Size + "]");
                    }
            #endif
                }
                // else -- font size is fine for this element
            }
            else
            {
                zFormat.Trimming = StringTrimming.EllipsisCharacter;
            }

            var fEmSize = zFont.Size;

            switch (zFont.Unit)
            {
                case GraphicsUnit.Point:
                    fEmSize = zGraphics.DpiY * (zFont.Size / 72f);
                    break;
                default:
                    Logger.AddLogLine("This font is using the Unit: {0} (not currently supported)".FormatString(zFont.Unit.ToString()));
                    break;
            }

            if (0 == zElement.outlinethickness)
            {
                try
                {
                    zGraphics.DrawString(sInput, zFont, zBrush,
                        new RectangleF(0, 0, zElement.width, zElement.height), zFormat);
                }
                catch (Exception)
                {
                    Logger.AddLogLine("Unable to render text (font issue?)");
                }
            }
            else
            {
                // prepare to draw text
                var zPath = new GraphicsPath();
//.........这里部分代码省略.........
开发者ID:nhmkdev,项目名称:cardmaker,代码行数:101,代码来源:DrawTextGraphics.cs

示例3: DrawGraphicOriginalSize

        /// <summary>
        /// Draws the image cropped based on alignment. The image is always drawn in proper aspect by this method
        /// </summary>
        /// <param name="zGraphics"></param>
        /// <param name="zBmp"></param>
        /// <param name="zElement"></param>
        private static void DrawGraphicOriginalSize(Graphics zGraphics, Bitmap zBmp, ProjectLayoutElement zElement)
        {
            int nSourceX = 0;
            int nSourceY = 0;

            int nX = 0;
            int nY = 0;

            // determine if the update is needed for drawing source X or target X
            if (zBmp.Width > zElement.width)
            {
                UpdateAlignmentValue(zElement.GetHorizontalAlignment(), ref nSourceX, zBmp.Width, zElement.width);
            }
            else
            {
                UpdateAlignmentValue(zElement.GetHorizontalAlignment(), ref nX, zElement.width, zBmp.Width);
            }
            // determine if the update is needed for drawing source Y or target Y
            if (zBmp.Height > zElement.height)
            {
                UpdateAlignmentValue(zElement.GetVerticalAlignment(), ref nSourceY, zBmp.Height, zElement.height);
            }
            else
            {
                UpdateAlignmentValue(zElement.GetVerticalAlignment(), ref nY, zElement.height, zBmp.Height);
            }
            zGraphics.DrawImage(zBmp, nX, nY, new Rectangle(nSourceX, nSourceY, zElement.width, zElement.height), GraphicsUnit.Pixel);
        }
开发者ID:nhmkdev,项目名称:cardmaker,代码行数:34,代码来源:DrawGraphic.cs

示例4: DrawText

        public void DrawText(Graphics zGraphics, ProjectLayoutElement zElement, string sInput, Brush zBrush, Font zFont, Color colorFont)
        {
            if (null == zFont) // default to something!
            {
                // font will show up in red if it's not yet set
                zFont = DrawItem.DefaultFont;
                zBrush = Brushes.Red;
            }

            TextFormatFlags zFormatFlags =
                TextFormatFlags.WordBreak
                | TextFormatFlags.NoClipping;

            switch (zElement.GetVerticalAlignment())
            {
                case StringAlignment.Center:
                    zFormatFlags |= TextFormatFlags.VerticalCenter;
                    break;
                case StringAlignment.Far:
                    zFormatFlags |= TextFormatFlags.Bottom;
                    break;
            }

            switch (zElement.GetHorizontalAlignment())
            {
                case StringAlignment.Center:
                    zFormatFlags |= TextFormatFlags.HorizontalCenter;
                    break;
                case StringAlignment.Far:
                    zFormatFlags |= TextFormatFlags.Right;
                    break;
            }

            #warning TextRenderer apparently does not support opactiy?!
            Bitmap zOpacityBitmap = null;
            if (255 != zElement.opacity)
            {
                zOpacityBitmap = new Bitmap(zElement.width, zElement.height, PixelFormat.Format32bppArgb);
                zOpacityBitmap.SetResolution(zGraphics.DpiY, zGraphics.DpiY);
            }

            if (zElement.autoscalefont)
            {

                var zSize = TextRenderer.MeasureText(sInput, zFont, new Size(zElement.width, int.MaxValue), zFormatFlags);

                if (zSize.Height > zElement.height || zSize.Width > zElement.width)
                {
                    float newSizeRatio;
                    if ((zSize.Height - zElement.height) > (zSize.Width - zElement.width))
                    {
                        newSizeRatio = (float)zElement.height / (float)zSize.Height;
                    }
                    else
                    {
                        newSizeRatio = (float)zElement.width / (float)zSize.Width;
                    }

                    var scaledFont = new Font(zFont.FontFamily, newSizeRatio * zFont.Size, zFont.Style);
                    Logger.AddLogLine(scaledFont.Size + " was [" + zFont.Size + "]");
                    zFont = scaledFont;

            #if true            // the preprocessing above will get the font size close but not perfect, the slow code below further refines the size
                    // slow mode - but perfect precision (well arguably with the Graphics.MeasureString)
                    bool bUpscaled = false;
                    const float FONT_SCALE_ADJUST = 0.25f;
                    if (0 < sInput.Trim().Length)
                    {
                        while (true)
                        {
                            zSize = TextRenderer.MeasureText(sInput, zFont, new Size(zElement.width, int.MaxValue), zFormatFlags);
                            if (zSize.Height > zElement.height || zSize.Width > zElement.width)
                            {
                                if (zFont.Size <= 1)
                                {
                                    break;
                                }
                                zFont = new Font(zFont.FontFamily, zFont.Size - FONT_SCALE_ADJUST, zFont.Style);
                                Logger.AddLogLine("ADJ A [" + zFont.Size + "]");
                                if (bUpscaled)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                zFont = new Font(zFont.FontFamily, zFont.Size + FONT_SCALE_ADJUST, zFont.Style);
                                Logger.AddLogLine("ADJ B [" + zFont.Size + "]");
                                bUpscaled = true;
                            }
                        }
                    }
            #endif
                }
                // else -- font size is fine for this element
            }
            else
            {
                zFormatFlags |= TextFormatFlags.EndEllipsis;
            }
//.........这里部分代码省略.........
开发者ID:nhmkdev,项目名称:cardmaker,代码行数:101,代码来源:DrawTextRenderer.cs


注:本文中的CardMaker.XML.ProjectLayoutElement.GetVerticalAlignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。