public void WatermarkFileWithText(string inputFile, string outputFile, string text, Font font, int x, int y,
                                          bool renderOver,
                                          Brush under, Brush over, StringAlignment xAlignment,
                                          StringAlignment yAlignment)
        {
            Image imgPhoto = null;
            Image outputPhoto = null;
            try
            {
                try
                {
                    imgPhoto = Image.FromFile(inputFile);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Failed to open file \"" + inputFile + "\"", ex);
                }

                WatermarkImageWithText(imgPhoto, ref outputPhoto, SmoothingMode.AntiAlias, text, font, x, y, renderOver,
                                       under, over, xAlignment, yAlignment);

                imgPhoto.Dispose();
                imgPhoto = null;

                outputPhoto.Save(outputFile, ImageFormat.Jpeg);
            }
            finally
            {
                if (imgPhoto != null) imgPhoto.Dispose();
                if (outputPhoto != null) outputPhoto.Dispose();
            }
        }
示例#2
0
 public VMergedCell(int firstRow, int lastRow, StringAlignment alignment,
     StringAlignment lineAlignment)
     : this(firstRow, lastRow)
 {
     this.alignment = alignment;
     this.lineAlignment = lineAlignment;
 }
        internal MonthViewBoxEventArgs(Graphics g, Rectangle bounds, string text, StringAlignment textAlign, Color textColor, Color backColor, Color borderColor)
        {
            _graphics = g;
            _bounds = bounds;
            Text = text;
            TextColor = textColor;
            BackgroundColor = backColor;
            BorderColor = borderColor;

            switch (textAlign)
            {
                case StringAlignment.Center:
                    TextFlags |= TextFormatFlags.HorizontalCenter;
                    break;
                case StringAlignment.Far:
                    TextFlags |= TextFormatFlags.Right;
                    break;
                case StringAlignment.Near:
                    TextFlags |= TextFormatFlags.Left;
                    break;
                default:
                    break;
            }

            TextFlags |= TextFormatFlags.VerticalCenter;
        }
 protected override object GetTextBoxColumn(StringAlignment alignment)
 {
     var column = new DataGridTextColumn();
     // TODO: set alignment in style
     column.Width = alignment == StringAlignment.Near ? 160 : 80;
     return column;
 }
示例#5
0
 public SimpleLabel(
     string text = "",
     float x = 0.0f, float y = 0.0f,
     Font font = null, Brush brush = null,
     float width = float.MaxValue, float height = float.MaxValue,
     StringAlignment horizontalAlignment = StringAlignment.Near,
     StringAlignment verticalAlignment = StringAlignment.Near,
     IEnumerable<string> alternateText = null)
 {
     Text = text;
     X = x;
     Y = y;
     Font = font ?? new Font("Arial", 1.0f);
     Brush = brush ?? new SolidBrush(Color.Black);
     Width = width;
     Height = height;
     HorizontalAlignment = horizontalAlignment;
     VerticalAlignment = verticalAlignment;
     IsMonospaced = false;
     HasShadow = true;
     ShadowColor = Color.FromArgb(128, 0, 0, 0);
     ((List<string>)(AlternateText = new List<string>())).AddRange(alternateText ?? new string[0]);
     Format = new StringFormat
     {
         Alignment = HorizontalAlignment,
         LineAlignment = VerticalAlignment,
         FormatFlags = StringFormatFlags.NoWrap,
         Trimming = StringTrimming.EllipsisCharacter
     };
 }
示例#6
0
 /// <summary>
 /// converts two given alignment values to one content alignment
 /// </summary>
 public static ContentAlignment GetAlignmentFromStringAlignment(StringAlignment alignment,
     StringAlignment linealignment)
 {
     ContentAlignment ret;
     //horizontal
     switch(alignment)
     {
         case StringAlignment.Near:
             ret=anyleft; break;
         case StringAlignment.Center:
             ret=anycenter; break;
         default:
             ret=anyright; break;
     }
     //vertical
     switch(linealignment)
     {
         case StringAlignment.Near:
             ret&=anytop; break;
         case StringAlignment.Center:
             ret&=anymiddle; break;
         default:
             ret&=anybottom; break;
     }
     return ret;
 }
        private static Bitmap CreateInfomationBitmap(string content, int width, int height,
			StringAlignment hAlign = StringAlignment.Near,
			StringAlignment vAlign = StringAlignment.Near)
        {
            Bitmap b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);
            GraphicsPath path = new GraphicsPath();
            FontFamily fontFamily = new FontFamily("微软雅黑");
            StringFormat format = new StringFormat();
            format.Alignment = hAlign;
            format.LineAlignment = vAlign;
            path.AddString(content,
                fontFamily, (int)FontStyle.Bold, 16, new Rectangle(0, 0, width, height), format);
            fontFamily.Dispose();
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.Black, path);
            Pen pen = new Pen(Color.Black, 2);
            g.DrawPath(pen, path);
            g.Dispose();
            pen.Dispose();
            Bitmap infoBitmap = RenderUtils.BoxBlur(b, 1);
            g = Graphics.FromImage(infoBitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.White, path);
            g.Dispose();
            return infoBitmap;
        }
示例#8
0
    public HeadingButton(string aString, string aFontName, int pointSize, FontStyle style, int x, int y, int width, int height, StringAlignment align, StringAlignment lineAlign, uint txtColor, Graphic background)
		:base(aString,aFontName,pointSize,style, x,y,width,height,align,lineAlign,txtColor,background)
	{
        //GFont aFont = new GFont(aFontName, pointSize, Guid.NewGuid());
        //this.Font = aFont;
        Enabled = true;
	}
 public FixedWidthColumn(string name, int width, StringAlignment align, char blankChar)
 {
     this._name = name;
     this._w = width;
     this._align = align;
     this._blank = blankChar;
 }
示例#10
0
 public HMergedCell(int leftColumn, int rightColumn, StringAlignment alignment,
     StringAlignment lineAlignment)
     : this(leftColumn, rightColumn)
 {
     this.alignment = alignment;
     this.lineAlignment = lineAlignment;
 }
示例#11
0
        /* ==========================================================
         * PUBLIC METHODS
         * ==========================================================
         */
        public void addButton(int xPos, int yPos, int width, int height, string label = "", bool showText = true, StringAlignment alignment = StringAlignment.CENTER)
        {
            BasicButton button = new BasicButton(xPos, yPos, width, height, basicBox, buttonFontStyle1, label, alignment, showText);

            componentsOnScreen.Add(button);
            buttonsOnScreen.Add(button);
        }
示例#12
0
 public MprStlTxt(Font f, Color c, bool rtl, StringAlignment a, StringAlignment la)
 {
     Font = f;
     Color = c;
     DirectionRightToLeft = rtl;
     Alignment = a;
     LineAlignment = la;
 }
示例#13
0
 public ListColumnDefinition(string id, string text, string groupName, int width, StringAlignment align)
 {
     this.align = align;
     this.groupName = groupName;
     this.id = id;
     this.width = width;
     this.text = text;
 }
示例#14
0
		public StringFormat(StringFormatFlags options) {
			this.native = LibIGraph.CreateStringFormat
				(StringAlignment.Near, options, StringAlignment.Near, StringTrimming.None);
			this.trimming = StringTrimming.None;
			this.alignment = StringAlignment.Near;
			this.lineAlignment = StringAlignment.Near;
			this.stringFormatFlags = options;
		}
示例#15
0
 public TextField(string text) {
     Alignment = StringAlignment.Near;
     Outline = 0;
     OutlineColor = Color.Black;
     Text = text;
     TextColor = Color.White;
     VerticalAlignment = StringAlignment.Near;
 }
		public StringFormat(StringFormatFlags options, int lang) {
			_alignment = StringAlignment.Near;
			_digitSubstituteLanguage = lang;
			_digitSubstituteMethod = StringDigitSubstitute.User;
			_flags = options;
			_hotkeyPrefix = HotkeyPrefix.None;
			_lineAlignment = StringAlignment.Near;
			_trimming = StringTrimming.Character;
		}
示例#17
0
		public void AlignedString(MovieClip mc, string s, Brush brush, StringAlignment align, float size)
		{
			StringFormat sf = new StringFormat();
			sf.Alignment = align;
			sf.LineAlignment = align;
			Font f = new Font("Times", size);
			mc.Graphics.DrawString(s, f, brush, new Rectangle(0, 0, (int) (mc.Width * mc.Xscale), (int) (mc.Height * mc.Yscale)), sf);
		
		}
示例#18
0
 public static StringFormat BuildStringFormat(StringAlignment h, StringAlignment v)
 {
     StringFormat sf = new StringFormat();
     sf.Alignment = h;
     sf.LineAlignment = v;
     sf.FormatFlags = StringFormatFlags.NoWrap;
     sf.Trimming = StringTrimming.None;
     return sf;
 }
示例#19
0
        public TextLabel(int xPos, int yPos, SpriteFont fontStyle, string label = "", StringAlignment alignment = StringAlignment.CENTER)
        {
            this.xPos = xPos;
            this.yPos = yPos;

            this.fontStyle = fontStyle;
            this.alignment = alignment;

            Initialize();
        }
示例#20
0
        public static Bitmap TextToBitmapAligned(this string text, int width, int height, float fontSize,
			StringAlignment horizAlign, StringAlignment vertAlign)
        {
            var font = new Font ("Arial", fontSize);
            var brush = new SolidBrush (Color.Black);
            var stringFormat = new StringFormat ();
            stringFormat.Alignment = horizAlign;
            stringFormat.LineAlignment = vertAlign;
            return TextToBitmap (text, width, height, PixelFormat.Format32bppArgb, font, brush, stringFormat);
        }
示例#21
0
 public CustomListBoxColumn(int id, string name, bool visible)
 {
     _id					= id;
     _name				= name;
     _isVisible			= visible;
     _sizeMode			= ColumnSizeMode.Sizeable;
     _contentWidth		= -1;
     _contentAlignment	= StringAlignment.Near;
     _headerAlignment	= StringAlignment.Near;
 }
示例#22
0
        // -------------------------------------------------
        public Form_TextLimitedPositioning (Point ptScreenClick, Side textside, StringAlignment textalignment)
        {
            InitializeComponent ();
            //Font = new Font ("Timies New Roman", 14);

            ptMouseScreenInit = ptScreenClick;
            side = textside;
            alignment = textalignment;

        }
示例#23
0
 public ListaKontaktowUI(Font czcionkaTytul, Font czcionkaDetal, Size rozmiarIkony, 
                  StringAlignment ulozenie, StringAlignment ulozeniePionowe)
 {
     this.czcionkaTytul = czcionkaTytul;
     this.czcionkaDetal = czcionkaDetal;
     this.rozmiarIkony = rozmiarIkony;
     this.ItemHeight = rozmiarIkony.Height + this.Margin.Vertical;
     format = new StringFormat();
     format.Alignment = ulozenie;
     format.LineAlignment = ulozeniePionowe;
 }
示例#24
0
 public strTextos(int xi, int yi, string cTexto)
 {
     this.x1 = xi;
     this.y1 = yi;
     this.x2 = 0;
     this.y2 = 0;
     this.x3 = 0;
     this.y3 = 0;
     this.Texto = cTexto;
     this.Bold = false;
     this.Align = StringAlignment.Far;
 }
示例#25
0
 public strTextos(int xi1, int yi1, int xi2, int yi2, int xi3, int yi3, string cTexto, bool lBold, StringAlignment sAlign)
 {
     this.x1 = xi1;
     this.y1 = yi1;
     this.x2 = xi2;
     this.y2 = yi2;
     this.x3 = xi3;
     this.y3 = yi3;
     this.Texto = cTexto;
     this.Bold = lBold;
     this.Align = sAlign;
 }
		public StringFormat (StringFormat source) {
			if (source == null)
				throw new ArgumentNullException("format");

			_alignment = source.LineAlignment;
			_digitSubstituteLanguage = source.DigitSubstitutionLanguage;
			_digitSubstituteMethod = source.DigitSubstitutionMethod;
			_flags = source.FormatFlags;
			_hotkeyPrefix = source.HotkeyPrefix;
			_lineAlignment = source.LineAlignment;
			_trimming = source.Trimming;
		}
示例#27
0
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenWeekday"/> class.
		/// </summary>
		public NuGenWeekday(NuGenCalendar calendar)
		{
			m_calendar = calendar;
			m_backColor1 = Color.White;
			m_backColor2 = Color.White;
			m_gradientMode = NuGenGradientMode.None;
			m_textColor = Color.FromArgb(0, 84, 227);
			m_font = new Font("Microsoft Sans Serif", (float)8.25);
			m_dayFormat = NuGenDayFormat.Short;
			m_align = StringAlignment.Center;
			m_borderColor = Color.Black;
		}
 /// <summary>
 /// Constructor with defining parameters
 /// </summary>
 /// <param name="titleFont"></param>
 /// <param name="imageSize"></param>
 /// <param name="aligment"></param>
 /// <param name="lineAligment"></param>
 public CheckedListBoxWithImage(Font titleFont, Size imageSize,
                  StringAlignment aligment, StringAlignment lineAligment)
 {
     _imageSize = imageSize;
     _fmt = new StringFormat();
     _fmt.Alignment = aligment;
     _fmt.LineAlignment = lineAligment;
     this.ItemHeight = _imageSize.Height + this.Margin.Vertical;
     _fmt.Alignment = aligment;
     _fmt.LineAlignment = lineAligment;
     _titleFont = titleFont;
 }
 public exListBox(Font titleFont, Font detailsFont,
                  StringAlignment aligment, StringAlignment lineAligment )
 {
     _titleFont = titleFont;
     _detailsFont = detailsFont;
     this.ItemHeight = this.Margin.Vertical;
     _fmt = new StringFormat();
     _fmt.Alignment = aligment;
     _fmt.LineAlignment = lineAligment;
     _titleFont = titleFont;
     _detailsFont = detailsFont;
 }
        private Color _TextColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.

        #endregion Fields

        #region Constructors

        public MonoFlat_Button()
        {
            SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint), true);

            BackColor = Color.Transparent;
            DoubleBuffered = true;
            Font = new Font("Segoe UI", 12);
            ForeColor = Color.FromArgb(255, 255, 255);
            Size = new Size(146, 41);
            _TextAlignment = StringAlignment.Center;
            P1 = new Pen(Color.FromArgb(181, 41, 42)); // P1 = Border color
            P3 = new Pen(Color.FromArgb(165, 37, 37)); // P3 = Border color when pressed
        }
示例#31
0
        static public void DrawMorseText(Graphics g, GraphicsPath gp2, ref PointF pos, string sSplit, Font newFont, FontStyle fontStyle, StringAlignment stringAlign, RectangleF newLabelBounds)
        {
            string sText       = TextExpression.GetTextWithoutTag(sSplit);
            SizeF  stringfSize = g.MeasureString(sText, newFont);
            var    format      = new StringFormat {
                Alignment = StringAlignment.Near
            };

            PointF posText = new PointF(pos.X, pos.Y);

            float fHeightUsed      = stringfSize.Height;
            float fHeightUsedMorse = 0.0F;
            float fWidthUsed       = stringfSize.Width;
            Font  newFontMorse     = new Font(new FontFamily("CGXAERO-MorseCode"), TextExpression.GetSizeFromTag(sSplit, newFont.SizeInPoints));
            SizeF fSizeMorse       = g.MeasureString(sText, newFontMorse);
            float fMorsePos        = pos.Y;

            fWidthUsed += TextExpression.GetLargerMorseWidth(g, sText, TextExpression.GetSizeFromTag(sSplit, newFont.SizeInPoints));
            if (stringAlign == StringAlignment.Center)
            {
                posText = new PointF((pos.X + newLabelBounds.Width / 2) - (fWidthUsed / 2) + 1, pos.Y);
            }
            if (stringAlign == StringAlignment.Far)
            {
                posText = new PointF((pos.X + newLabelBounds.Width) - (fWidthUsed + 3), pos.Y);
            }

            PointF posMorse = new PointF(posText.X + stringfSize.Width, posText.Y);

            foreach (char c in sText)
            {
                //gp2.AddString(c.ToString(), new FontFamily("CGXAERO-MorseCode"), (int)fontStyle, newFont.Size * g.DpiY / 72F, posMorse, format);
                g.DrawString(c.ToString(), newFontMorse, new SolidBrush(Color.Black), posMorse, format);
                posMorse          = new PointF(posMorse.X, posMorse.Y + fSizeMorse.Height);
                fHeightUsedMorse += fSizeMorse.Height;
            }

            float fLargerHighOffset = fHeightUsed;

            if (fHeightUsedMorse > fHeightUsed)
            {
                posText           = new PointF(posText.X, posText.Y + (fHeightUsedMorse / 2) - stringfSize.Height / 2);
                fLargerHighOffset = fHeightUsedMorse;
            }


            //gp2.AddString(sText + " ", newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, posText, format);
            g.DrawString(sText + " ", newFont, new SolidBrush(Color.Black), posText, format);

            pos.Y += fLargerHighOffset;
        }
示例#32
0
            private static void DrawRect(IGraphics canvas, string id, Rectangle rect, StringAlignment horizontalAlignment, StringAlignment verticalAlignment)
            {
                var format = new StringFormat();

                format.Alignment     = horizontalAlignment;
                format.LineAlignment = verticalAlignment;
                format.FormatFlags   = StringFormatFlags.NoWrap | StringFormatFlags.NoClip;

                var pen = new Pen(new SolidBrush(Color.Black), 1);

                canvas.DrawRectangle(pen, rect);

                var aFont = Control.DefaultFont;
                var font  = new Font(aFont.Name, RectFontSize, aFont.Style, aFont.Unit);

                {
                    // Draw label
                    var labelFormat = new StringFormat();
                    labelFormat.Alignment     = StringAlignment.Near;
                    labelFormat.LineAlignment = StringAlignment.Center;
                    labelFormat.FormatFlags   = StringFormatFlags.NoWrap | StringFormatFlags.NoClip;
                    var labelRect = new Rectangle(rect.X, rect.Y - RectGap, RectGap, RectGap);
                    var labelFont = new Font(aFont.Name, RectFontSize * 0.8f, aFont.Style, aFont.Unit);
                    canvas.DrawString(id, labelFont, new SolidBrush(Color.Black), labelRect, labelFormat);
                }

                canvas.DrawString("Helloy", font, new SolidBrush(Color.Blue), rect, format);
            }
示例#33
0
        private void picSlider_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(BackColor);

            // Any messages in case of any errors
            string errorMessage = null;

            if (Animation == null)
            {
                errorMessage = "No animation! Create or select animation to start editing.";
            }
            else if (Animation.DirectXAnimation.KeyFrames.Count == 0)
            {
                errorMessage = "No frames! Add some frames to start editing.";
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                using (var b = new SolidBrush(Colors.DisabledText))
                    e.Graphics.DrawString(errorMessage, Font, b, ClientRectangle,
                                          new StringFormat {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                return;
            }

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            // Draw state change ranges
            foreach (var sch in Animation.WadAnimation.StateChanges)
            {
                foreach (var disp in sch.Dispatches)
                {
                    int realOutFrame = disp.OutFrame >= realFrameCount ? realFrameCount - 1 : disp.OutFrame;
                    e.Graphics.FillRectangle(_stateChangeBrush, new RectangleF(picSlider.Padding.Left + (disp.InFrame * frameStep),
                                                                               picSlider.Padding.Top,
                                                                               (realOutFrame - disp.InFrame) * frameStep,
                                                                               picSlider.ClientSize.Height / _stateChangeMarkerThicknessDivider - picSlider.Padding.Bottom - 2));
                }
            }

            int halfCursorWidth = (int)Math.Round(_cursorWidth / 2.0f);

            // Shift the cursor at start/stop positions to prevent clipping
            int addShift = -halfCursorWidth;

            if (Value == 0)
            {
                addShift += halfCursorWidth;
            }
            else if (Value == Maximum)
            {
                addShift += -halfCursorWidth;
            }

            // Draw selection and highlight in 2 passes
            for (int passes = 0; passes < 2; passes++)
            {
                int x     = passes == 0 ? Selection.X : _highlightStart;
                int y     = passes == 0 ? Selection.Y : _highlightEnd;
                int realX = ValueToX(x);
                int realY = ValueToX(y);
                int size  = realY - realX;

                if ((passes == 0 && !SelectionIsEmpty) || (passes == 1 && _highlightTimer.Enabled))
                {
                    int       width = size == 0 ? _cursorWidth : size + _cursorWidth;
                    Rectangle rect  = new Rectangle(realX + picSlider.Padding.Left - halfCursorWidth, picSlider.Padding.Top, width, picSlider.ClientSize.Height - picSlider.Padding.Bottom);;

                    if (size == 0)
                    {
                        if (y != Minimum && y == Maximum)
                        {
                            rect.X -= halfCursorWidth;
                        }
                        else if (x == Minimum)
                        {
                            rect.X += halfCursorWidth;
                        }
                    }
                    else
                    {
                        if (x == Minimum)
                        {
                            rect.X     += halfCursorWidth;
                            rect.Width -= halfCursorWidth;
                        }
                        if (y == Maximum)
                        {
                            rect.Width -= halfCursorWidth;
                        }
                    }

                    if (passes == 0)
                    {
                        e.Graphics.FillRectangle(_selectionBrush, rect);
                        e.Graphics.DrawRectangle(_selectionPen, rect);
                    }
                    else
                    {
                        using (SolidBrush currBrush = (SolidBrush)_highlightBrush.Clone())
                        {
                            currBrush.Color = Color.FromArgb((int)((float)currBrush.Color.A * _highlightCounter), currBrush.Color);
                            e.Graphics.FillRectangle(currBrush, rect);
                        }
                    }
                }
            }

            // Measure maximum label size
            SizeF maxLabelSize = TextRenderer.MeasureText(realFrameCount.ToString(), Font,
                                                          new Size(picSlider.Width - picSlider.Padding.Horizontal, picSlider.Height - picSlider.Padding.Vertical),
                                                          TextFormatFlags.WordBreak);

            // Precache animcommands so we don't iterate them every drawn frame
            var acList = new List <KeyValuePair <int, WadAnimCommand> >();

            foreach (var ac in Animation.WadAnimation.AnimCommands.Where(ac => ac.FrameBased))
            {
                acList.Add(new KeyValuePair <int, WadAnimCommand>(ac.Parameter1, ac));
            }


            // Precache some variables for speeding up renderer with ultra-long animations (5000+ frames)
            var step          = frameStep;
            var padding       = picSlider.Padding;
            var drawStepWidth = _keyFrameBorderPen.Width * 4;

            // Draw frame-specific animcommands, numericals and dividers
            for (int passes = 0; passes < 2; passes++)
            {
                for (int i = 0; i < realFrameCount; ++i)
                {
                    int  currX      = (int)MathC.Round(step * i) + padding.Left;
                    bool isKeyFrame = (i % (Animation.WadAnimation.FrameRate == 0 ? 1 : Animation.WadAnimation.FrameRate) == 0);
                    bool first      = i == 0;
                    bool last       = i >= realFrameCount - 1;

                    if (passes == 0)
                    {
                        int count = 0;

                        // Draw animcommands
                        if (acList.Count > 0)
                        {
                            foreach (var acPair in acList)
                            {
                                var       ac         = acPair.Value;
                                Rectangle currRect   = new Rectangle(currX - _animCommandMarkerRadius / 2, padding.Top - _animCommandMarkerRadius / 2 + (_animCommandMarkerRadius / 3 * count), _animCommandMarkerRadius, _animCommandMarkerRadius);
                                float     startAngle = !first ? (!last ? 0 : 90) : 0;
                                float     endAngle   = !first ? (!last ? 180 : 90) : 90;

                                if (ac.Parameter1 == i)
                                {
                                    using (SolidBrush currBrush = (SolidBrush)(ac.Type == WadAnimCommandType.PlaySound ? _animCommandSoundBrush : _animCommandFlipeffectBrush).Clone())
                                    {
                                        currBrush.Color = Color.FromArgb((int)((float)currBrush.Color.A / (1.0f + ((float)count / 3.0f))), currBrush.Color);
                                        e.Graphics.FillPie(currBrush, currRect, startAngle, endAngle);
                                        count++;
                                    }
                                }
                            }
                            acList.RemoveAll(ac => ac.Key == i); // Remove already drawn animcommands from list
                        }

                        // Determine if current line should be drawn.
                        bool drawCurrentLine = true;
                        if (step < drawStepWidth)
                        {
                            int period = (int)MathC.Round(drawStepWidth / step);
                            if (i % period != 0 && i != realFrameCount - 1)
                            {
                                drawCurrentLine = false;
                            }
                        }

                        if (drawCurrentLine)
                        {
                            // Draw frame lines
                            e.Graphics.SmoothingMode = SmoothingMode.Default;

                            var lineHeight = picSlider.Height / (isKeyFrame ? 2 : 3);
                            if (isKeyFrame)
                            {
                                e.Graphics.DrawLine(_keyFrameBorderPen, currX, padding.Top, currX, lineHeight);  // Draw keyframe
                            }
                            else
                            {
                                e.Graphics.DrawLine(_frameBorderPen, currX, padding.Top, currX, lineHeight);  // Draw ordinary frame
                            }
                            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                        }
                    }

                    // Draw cursor on 2nd pass's first occurence (only for real animations, not for single-frame ones)
                    if (i == 0 && passes == 1 && realFrameCount > 1)
                    {
                        e.Graphics.FillRectangle(_cursorBrush, new RectangleF(ValueToX(Value) + addShift + padding.Left, padding.Top, _cursorWidth, picSlider.ClientSize.Height - padding.Bottom - 2));
                    }

                    // Draw labels
                    bool drawCurrentLabel = true;
                    if ((passes == 0 && !isKeyFrame) || (passes != 0 && isKeyFrame))
                    {
                        // Determine if labels are overlapping and decide on drawing
                        if (step < maxLabelSize.Width * 1.25)
                        {
                            int period = (int)MathC.Round(maxLabelSize.Width * 1.25 / step);
                            if (i % period != 0)
                            {
                                drawCurrentLabel = false;
                            }
                        }

                        if (drawCurrentLabel)
                        {
                            // Align first and last numerical entries so they are not concealed by control border
                            StringAlignment align = StringAlignment.Center;
                            int             shift = 0;
                            if (first)
                            {
                                shift -= padding.Left;
                                align  = StringAlignment.Near;
                            }
                            else if (last)
                            {
                                shift += padding.Left;
                                align  = StringAlignment.Far;
                            }

                            // Finally draw it after all these tests
                            e.Graphics.DrawString(i.ToString(), Font, (isKeyFrame ? _lblKeyframeBrush : _lblFrameBrush), currX + shift, picSlider.Height,
                                                  new StringFormat {
                                Alignment = align, LineAlignment = StringAlignment.Far
                            });
                        }
                    }
                }
            }

            // Draw horizontal guide (only for real anims, for single-frame anims we wouldn't wanna show that
            if (realFrameCount > 1)
            {
                e.Graphics.SmoothingMode = SmoothingMode.Default;
                e.Graphics.DrawLine(_keyFrameBorderPen, padding.Left, padding.Top + 1, picSlider.ClientSize.Width - padding.Left, padding.Top + 1);
            }
        }
示例#34
0
 public void AddTextBlock(StringAlignment alignment, List <string> content)
 {
     AddTextBlock(new TextBlock {
         Alignment = alignment, Content = content
     });
 }
示例#35
0
 public static void DrawText(string text, QFont font, Color color, Vector4 bounds,
                             StringAlignment vAlign = StringAlignment.Near,
                             StringAlignment hAlign = StringAlignment.Near)
 {
     DrawText(text, font, color, new RectangleF(bounds.X, bounds.Y, bounds.Z, bounds.W), vAlign, hAlign);
 }
示例#36
0
 public static void DrawString(this Graphics graphics, string text, Font font, Brush brush, Rectangle layoutRectangle, StringAlignment alignment, StringTrimming trimming)
 {
     graphics.DrawString(text, font, brush, layoutRectangle, new StringFormat {
         Trimming = trimming, LineAlignment = alignment, Alignment = alignment
     });
 }
示例#37
0
        /// <summary>Retrieves the appropriate string format.</summary>
        /// <param name="orientation">The orientation.</param>
        /// <param name="alignment">The alignment.</param>
        /// <param name="lineAlignment">The line Alignment.</param>
        /// <returns>The <see cref="StringFormat" />.</returns>
        public static StringFormat GetOrientedStringFormat(Orientation orientation, StringAlignment alignment, StringAlignment lineAlignment)
        {
            StringFormat orientedStringFormat;

            switch (orientation)
            {
            case Orientation.Horizontal:
            {
                orientedStringFormat = new StringFormat {
                    Alignment = alignment, LineAlignment = lineAlignment
                };
                break;
            }

            case Orientation.Vertical:
            {
                orientedStringFormat = new StringFormat(StringFormatFlags.DirectionVertical);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(orientedStringFormat);
        }
示例#38
0
        private static void annotate(XGraphics graphics, Palette palette, LineSegment lineSegment, TextBlock text, StringAlignment alignment)
        {
            Vector point;
            var    delta = lineSegment.Delta;

            switch (alignment)
            {
            default:
                point = lineSegment.Start;
                delta.Negate();
                break;

            case StringAlignment.Center:
                point = lineSegment.Mid;
                break;

            case StringAlignment.Far:
                point = lineSegment.End;
                break;
            }

            var bounds = new Rect(point, Vector.Zero);

            bounds.Inflate(Settings.TextOffsetFromConnection);

            float angle;
            var   compassPoint = CompassPointHelper.DirectionFromAngle(out angle, delta);

            var pos    = bounds.GetCorner(compassPoint);
            var format = new XStringFormat();

            Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, compassPoint);
            if (alignment == StringAlignment.Center && Numeric.InRange(angle, -10, 10))
            {
                // HACK: if the line segment is pretty horizontal and we're drawing mid-line text,
                // move text below the line to get it out of the way of any labels at the ends,
                // and center the text so it fits onto a line between two proximal rooms.
                pos = bounds.GetCorner(CompassPoint.South);
                format.Alignment     = XStringAlignment.Center;
                format.LineAlignment = XLineAlignment.Near;
            }


            if (!Settings.DebugDisableTextRendering)
            {
                text.Draw(graphics, Settings.SubtitleFont, palette.LineTextBrush, pos, Vector.Zero, format);
            }
        }
示例#39
0
        static StringFormat CreateTipStringFormat(StringAlignment horizontalAlignment, StringAlignment verticalAlignment)
        {
            StringFormat format = (StringFormat)StringFormat.GenericTypographic.Clone();

            format.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.MeasureTrailingSpaces;
            // note: Align Near, Line Center seemed to do something before

            format.Alignment     = horizontalAlignment;
            format.LineAlignment = verticalAlignment;

            return(format);
        }
示例#40
0
        /// <summary>
        /// Draws hand-drawn-looking highlighter color stick lines on top of text. The text itself is not drawn.
        /// Text may span multiple lines
        /// </summary>
        /// <param name="gr">Graphical context</param>
        /// <param name="rect">Bounding rectangle</param>
        /// <param name="font">Font to measure text in</param>
        /// <param name="text">Text to measure, the text is not drawn rather charecters position is determined</param>
        /// <param name="align">Text alignment</param>
        /// <param name="color">Color of highlighter including opacity</param>
        public static void DrawTextHighlight(System.Drawing.Graphics gr,
                                             Rectangle rect,
                                             Font font,
                                             string text,
                                             StringAlignment align,
                                             Color color)
        {
            Rectangle textRect;
            int       lineHeight;

            using (StringFormat fmt = new StringFormat())
            {
                fmt.Alignment = align;
                SizeF size = gr.MeasureString(text, font, new SizeF(rect.Width, rect.Height), fmt);
                lineHeight = (int)gr.MeasureString("`~_W", font).Height;

                if (//RIGHT
                    (align == StringAlignment.Near && Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft) ||
                    (align == StringAlignment.Far)
                    )
                {
                    textRect = new Rectangle(rect.Right - (int)size.Width,
                                             rect.Top,
                                             (int)size.Width, (int)size.Height);
                }
                else
                if (align == StringAlignment.Center)
                {
                    textRect = new Rectangle(rect.Left + (rect.Width / 2) - (int)size.Width / 2,
                                             rect.Location.Y,
                                             (int)size.Width, (int)size.Height);
                }
                else//LEFT
                {
                    textRect = new Rectangle(rect.Left, rect.Top, (int)size.Width, (int)size.Height);
                }
            }

            textRect.Inflate(lineHeight, 0);
            if (textRect.Left < rect.Left)
            {
                textRect.X = rect.Left;
            }
            if (textRect.Right > rect.Right)
            {
                textRect.Width -= textRect.Right - rect.Right;
            }

            Rectangle brRect = textRect;//gets rid of brush wrap

            brRect.Inflate(lineHeight / 2, lineHeight / 2);

            using (LinearGradientBrush br =
                       new LinearGradientBrush(brRect,
                                               color,
                                               Color.FromArgb(16, Color.Silver),
                                               (align == StringAlignment.Far) ? 180f : 360f))
            {
                gr.SmoothingMode = SmoothingMode.AntiAlias;
                Random rnd = new Random();
                //gr.DrawRectangle(Pens.Red, textRect);

                int y = textRect.Top + lineHeight / 2;

                Point[] pnt = new Point[4];

                while (y /*+ lineHeight / 2*/ < textRect.Bottom)
                {
                    pnt[0] = new Point(textRect.Left, y - lineHeight / 2);
                    pnt[1] = new Point(textRect.Right - lineHeight / 2, y - lineHeight / 2);
                    pnt[2] = new Point(textRect.Right - lineHeight, y + lineHeight / 2);
                    pnt[3] = new Point(textRect.Left + lineHeight / 2, y + lineHeight / 2);

                    for (int i = 0; i < pnt.Length; i++)
                    {
                        pnt[i].Offset(rnd.Next(0, 2), rnd.Next(-2, 2));
                    }


                    gr.FillClosedCurve(br, pnt, FillMode.Alternate, 0.07f + (float)(rnd.NextDouble() / 6d));
                    y += lineHeight + 2;//1 px padding top and bottom
                }
            }//using brush
        }
示例#41
0
 protected static void DrawString(Graphics graphics, RectangleF layoutRectangle, Font font, Color fontColor, string strText, RightToLeft rightToLeft, StringAlignment stringAlignment)
 {
     if (graphics == null)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, new object[1]
         {
             typeof(Graphics).Name
         }));
     }
     using (SolidBrush brush = new SolidBrush(fontColor))
     {
         using (StringFormat stringFormat = new StringFormat())
         {
             stringFormat.FormatFlags = StringFormatFlags.NoWrap;
             if (rightToLeft == RightToLeft.Yes)
             {
                 stringFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
             }
             stringFormat.Trimming      = StringTrimming.EllipsisCharacter;
             stringFormat.LineAlignment = StringAlignment.Center;
             stringFormat.Alignment     = stringAlignment;
             graphics.DrawString(strText, font, brush, layoutRectangle, stringFormat);
         }
     }
 }
示例#42
0
        private bool HitTest1D(ref float point, float location, float size, float maxSize, StringAlignment alignment)
        {
            if (alignment == StringAlignment.Far)
            {
                location += maxSize - size;
            }
            else if (alignment == StringAlignment.Center)
            {
                location += (maxSize - size) * 0.5f;
            }
            float old = point;

            point = Range.PutInRange(point, location, location + size);
            return(point == old);
        }
示例#43
0
 public void SetJustify(StringAlignment horizontal, StringAlignment vertical = StringAlignment.Near)
 {
     Justify = Justification(horizontal, vertical);
 }
示例#44
0
 private static StatusBarElement createStatusBarElement(StatusBarElementType elementType, StatusBarElementSize statusBarElementSize, StatusBarElementAlignment statusBarElementAlignment, int width, StringAlignment textAlignment = StringAlignment.Near)
 {
    var statusBarElement = new StatusBarElement(elementType, statusBarElementSize, statusBarElementAlignment, width, textAlignment)
    {
       Index = _allElements.Count
    };
    _allElements.Add(statusBarElement);
    return statusBarElement;
 }
示例#45
0
 static public void Label(Rectangle rect, string text, StringAlignment sa)
 {
     Label(rect, text, 20, sa);
 }
示例#46
0
        public void DrawStringLine(Graphics g, string text, Font font, Rectangle textRect, Color textColor, StringAlignment align = StringAlignment.Near, StringAlignment lineAlign = StringAlignment.Center, StringTrimming trimming = StringTrimming.EllipsisCharacter)
        {
            if (textRect.Width < 1 || textRect.Height < 1)
            {
                return;
            }
            if (text == null)
            {
                return;
            }

            // Expand text rect, because DrawString stops too soon
            textRect.Y     += GetFontYOffset(font);
            textRect.Width += DrawStringWidthAdd;
            textRect.Height = Math.Max(textRect.Height, font.Height);

            bool manualEllipsis = trimming == StringTrimming.EllipsisCharacter || trimming == StringTrimming.EllipsisWord;

            if (trimming == StringTrimming.EllipsisCharacter)
            {
                trimming = StringTrimming.Character;
            }
            if (trimming == StringTrimming.EllipsisWord)
            {
                trimming = StringTrimming.Word;
            }

            if (manualEllipsis)
            {
                textRect.Width -= 5;
            }
            StringFormat nameLabelFormat = StringFormat.GenericDefault;

            nameLabelFormat.Alignment     = align;
            nameLabelFormat.LineAlignment = lineAlign;
            nameLabelFormat.Trimming      = trimming;
            nameLabelFormat.FormatFlags  |= StringFormatFlags.NoWrap;

            int   charsFit, lines;
            SizeF nameLabelSize    = g.MeasureString(text, font, textRect.Size, nameLabelFormat, out charsFit, out lines);
            bool  isEllipsisActive = charsFit < text.Length && manualEllipsis;

            if (textRect.Width >= 1)
            {
                g.DrawString(text, font, new SolidBrush(textColor), textRect, nameLabelFormat);
            }

            if (isEllipsisActive)
            {
                Pen ellipsisPen = new Pen(textColor);
                ellipsisPen.DashStyle = DashStyle.Dot;
                g.DrawLine(ellipsisPen,
                           textRect.Right - DrawStringWidthAdd,
                           (textRect.Y + textRect.Height * 0.5f) + (nameLabelSize.Height * 0.3f),
                           textRect.Right - DrawStringWidthAdd + 3,
                           (textRect.Y + textRect.Height * 0.5f) + (nameLabelSize.Height * 0.3f));
            }
        }
示例#47
0
 public override bool ProcessMarkup(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
 {
     m_ePreviousStringAlignment          = zProcessData.CurrentStringAlignment;
     zProcessData.CurrentStringAlignment = MarkupAlignment;
     return(false);
 }
 internal MonthViewBoxEventArgs(Graphics g, Rectangle bounds, string text, StringAlignment textAlign, Color textColor)
     : this(g, bounds, text, textAlign, textColor, Color.Empty, Color.Empty)
 {
 }
示例#49
0
        public static void Label(System.Windows.Forms.PaintEventArgs pe, Rectangle area, string text, Font font, StringAlignment horizontalAlignment, StringAlignment verticalAlignment, Color color, bool selected)
        {
            StringFormat format = new StringFormat();

            format.Alignment     = horizontalAlignment;
            format.LineAlignment = verticalAlignment;

            pe.Graphics.DrawString(text, font, new SolidBrush(color), area, format);

            if (selected)
            {
                pe.Graphics.DrawRectangle(new System.Drawing.Pen(Color.Blue, 1f), area);
            }
        }
示例#50
0
 public IStringLayout CreateStringLayout(string pString, string pFont, float pSize, StringAlignment pAlignment)
 {
     return(new OpenGLStringLayout(pString, pFont, pSize, pAlignment));
 }
示例#51
0
        /// <summary>Renders the text reflection.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="orientation">The orientation.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font to  draw.</param>
        /// <param name="color">The fore color.</param>
        /// <param name="clientRectangle">The client rectangle.</param>
        /// <param name="spacing">The reflection spacing.</param>
        /// <param name="offset">The location offset.</param>
        /// <param name="alignment">The alignment.</param>
        /// <param name="lineAlignment">The line Alignment.</param>
        public static void RenderTextReflection(Graphics graphics, Orientation orientation, string text, Font font, Color color, Rectangle clientRectangle, int spacing, Point offset, StringAlignment alignment, StringAlignment lineAlignment)
        {
            Point    reflectionLocation;
            Bitmap   reflectionBitmap = new Bitmap(clientRectangle.Width, clientRectangle.Height);
            Graphics imageGraphics    = Graphics.FromImage(reflectionBitmap);

            // Setup text render
            imageGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            // Rotate reflection
            switch (orientation)
            {
            case Orientation.Horizontal:
            {
                imageGraphics.TranslateTransform(0, StringUtil.MeasureText(text, font, graphics).Height);
                imageGraphics.ScaleTransform(1, -1);

                reflectionLocation = new Point(0, offset.Y - (StringUtil.MeasureText(text, font, graphics).Height / 2) - spacing);
                break;
            }

            case Orientation.Vertical:
            {
                imageGraphics.ScaleTransform(-1, 1);
                reflectionLocation = new Point((offset.X - (StringUtil.MeasureText(text, font, graphics).Width / 2)) + spacing, 0);
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(orientation));
            }
            }

            // Draw reflected string
            imageGraphics.DrawString(text, font, new SolidBrush(color), reflectionLocation, GetOrientedStringFormat(orientation, alignment, lineAlignment));

            // Draw the reflection image
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.DrawImage(reflectionBitmap, clientRectangle, 0, 0, reflectionBitmap.Width, reflectionBitmap.Height, GraphicsUnit.Pixel);
            graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
        }
示例#52
0
        private static void PrintImage(Surface surface, float left, float width, Line line, StringAlignment alignment)
        {
            Graphics g     = surface.Graphics;
            Image    image = ((ImageNode)line.Node).Image;
            float    w     = image.Width;
            float    h     = image.Height;

            float x = left;

            if (w < width)
            {
                switch (alignment)
                {
                case StringAlignment.Near:
                    break;

                case StringAlignment.Center:
                    x += (width - image.Width) / 2;
                    break;

                case StringAlignment.Far:
                    x += (width - image.Width);
                    break;
                }
            }
            else // Scale down image to fit into available width
            {
                h = h * (width / w);
                w = width;
            }
            g.DrawImage(image, x, surface.CurrentY, w, h);
            surface.CurrentY += h;
        }
示例#53
0
 // Token: 0x060003BD RID: 957 RVA: 0x000036DF File Offset: 0x000018DF
 static void smethod_17(StringFormat stringFormat_2, StringAlignment stringAlignment_0)
 {
     stringFormat_2.LineAlignment = stringAlignment_0;
 }
示例#54
0
        /// <summary>
        /// Create content based on text data. Chinese won't be rotated.
        /// </summary>
        /// <param name="text">Text data.</param>
        /// <param name="autoFit">Auto fit.</param>
        /// <param name="aligment">Alignment.</param>
        /// <returns>The btimap</returns>
        public Bitmap CreateContent(string text, bool autoFit = true, StringAlignment aligment = StringAlignment.Center)
        {
            //int calWidth = Horizontal ? Width : Height;
            //int calHeight = Horizontal ? Height : Width;
            //Bitmap textBitmap = new Bitmap(Width, Height);
            Horizontal = true;
            int      calWidth   = 80;
            int      calHeight  = 64;
            Bitmap   textBitmap = Horizontal ? new Bitmap(calWidth, calHeight) : new Bitmap(calHeight, calWidth);
            Font     font       = new Font("宋体", 9f);
            Graphics textG      = Graphics.FromImage(textBitmap);

            textG.FillRectangle(new SolidBrush(Color.Black), 0, 0, textBitmap.Width, textBitmap.Height);
            textG.DrawString(text, font, Brushes.White, new PointF()
            {
                X = 0, Y = 0
            });

            string b = string.Join("", Enumerable.Range(0, 5120).Select(a => new { x = a % 80, y = a / 80 })
                                   .Select(x => textBitmap.GetPixel(x.x, x.y).GetBrightness() > 0.5f ? "1" : "0"));

            //textBox5.Text += b;
            textBitmap.Save("1.bmp");

            DisplayFont = new Font("宋体", 12, FontStyle.Regular);
            Font  textFont = DisplayFont;
            SizeF textSize = textG.MeasureString(text, textFont);
            Font  tempFont = DisplayFont;

            if (autoFit)
            {
                if (textSize.Width < calWidth && textSize.Height < calHeight)
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size + (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Width < calWidth && textSize.Height < calHeight);
                    textSize = textG.MeasureString(text, textFont);
                }
                else
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size - (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Width >= calHeight || textSize.Height >= calHeight);
                    textFont = tempFont;
                }
            }
            else
            {
                if (textSize.Height < DisplayFont.Size)
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size + (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Height < DisplayFont.Size);
                    textFont = tempFont;
                }
                else
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size - (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Height >= DisplayFont.Size);
                    textFont = tempFont;
                }
            }

            StringFormat textFormat = new StringFormat();

            textFormat.Alignment     = aligment;
            textFormat.LineAlignment = StringAlignment.Center;
            if (Horizontal) // 横屏
            {
                float x = 0.0f;
                float y = textBitmap.Height / 2 + textBitmap.Height / 16;
                switch (aligment)
                {
                case StringAlignment.Near:
                    x = 1;
                    break;

                case StringAlignment.Center:
                    x = textBitmap.Width / 2;
                    break;

                case StringAlignment.Far:
                    x = textBitmap.Width - 1;
                    break;
                }

                textG.DrawString(
                    text,
                    textFont,
                    new SolidBrush(ForeColor),
                    x,
                    y,
                    textFormat);
            }
            else        // 竖屏
            {
                //float x = textBitmap.Width / 2 - textBitmap.Width / 16;
                float x = textBitmap.Width / 2;
                float y = 0.0f;
                switch (aligment)
                {
                case StringAlignment.Near:
                    y = 2;
                    break;

                case StringAlignment.Center:
                    y = textBitmap.Height / 2;
                    break;

                case StringAlignment.Far:
                    y = textBitmap.Height - 2;
                    break;
                }

                textFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                textG.DrawString(
                    text,
                    textFont,
                    new SolidBrush(ForeColor),
                    x,
                    y,
                    textFormat);
            }

            // 竖屏
            if (!Horizontal)
            {
                textBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
            }

            return(textBitmap);
        }
示例#55
0
 public StringFormat SetPosition(StringAlignment horizontal = StringAlignment.Center, StringAlignment vertical = StringAlignment.Center)
 {
     return(new StringFormat
     {
         Alignment = horizontal,
         LineAlignment = vertical
     });
 }
示例#56
0
        /// <summary>
        /// Create content based on text data. Chinese will be rotated.
        /// </summary>
        /// <param name="text">Text data.</param>
        /// <param name="autoFit">Auto fit.</param>
        /// <param name="aligment">Alignment.</param>
        /// <returns>The btimap</returns>
        public Bitmap CreateContent2(string text, bool autoFit = true, StringAlignment aligment = StringAlignment.Center)
        {
            Bitmap textBitmap = new Bitmap(Width, Height);

            Graphics textG = Graphics.FromImage(textBitmap);

            textG.FillRectangle(new SolidBrush(Color.Black), 0, 0, textBitmap.Width, textBitmap.Height);

            Font  textFont = DisplayFont;
            SizeF textSize = textG.MeasureString(text, textFont);
            Font  tempFont = DisplayFont;

            if (autoFit)
            {
                if (textSize.Width < Width && textSize.Height < Height)
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size + (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Width < Width && textSize.Height < Height);
                    textSize = textG.MeasureString(text, textFont);
                }
                else
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size - (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Width >= Width || textSize.Height >= Height);
                    textFont = tempFont;
                }
            }
            else
            {
                if (textSize.Height < DisplayFont.Size)
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size + (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Height < DisplayFont.Size);
                    textFont = tempFont;
                }
                else
                {
                    do
                    {
                        textFont = tempFont;
                        tempFont = new Font(DisplayFont.FontFamily, textFont.Size - (float)0.2);
                        textSize = textG.MeasureString(text, tempFont);
                    }while (textSize.Height >= DisplayFont.Size);
                    textFont = tempFont;
                }
            }

            StringFormat textFormat = new StringFormat();

            textFormat.Alignment     = aligment;
            textFormat.LineAlignment = StringAlignment.Center;

            // 横屏
            float x = 0.0f;
            float y = textBitmap.Height / 2 + textBitmap.Height / 16;

            switch (aligment)
            {
            case StringAlignment.Near:
                x = 1;
                break;

            case StringAlignment.Center:
                x = textBitmap.Width / 2;
                break;

            case StringAlignment.Far:
                x = textBitmap.Width - 1;
                break;
            }

            textG.DrawString(
                text,
                textFont,
                new SolidBrush(ForeColor),
                x,
                y,
                textFormat);

            // 竖屏
            if (!Horizontal)
            {
                textBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
            }

            return(textBitmap);
        }
示例#57
0
 /// <summary>
 /// Resets the PanelBorder property to its default value.
 /// </summary>
 public void ResetAlignment()
 {
     Alignment = StringAlignment.Near;
 }
示例#58
0
 static public void Label(Rectangle rect, string text, int fontSize, StringAlignment sa)
 {
     Label(rect, text, fontSize, sa, Color.White);
 }
示例#59
0
        public int PickCharStringLine(string text, Font font, Rectangle textRect, Point pickLoc, StringAlignment align = StringAlignment.Near, StringAlignment lineAlign = StringAlignment.Center)
        {
            if (text == null)
            {
                return(-1);
            }
            if (!textRect.Contains(pickLoc))
            {
                return(-1);
            }

            // Expand text rect, because DrawString stops too soon
            textRect.Width += DrawStringWidthAdd;
            textRect.Height = Math.Max(textRect.Height, font.Height);

            // Assume manual ellipsis
            textRect.Width -= 5;
            StringFormat nameLabelFormat = StringFormat.GenericDefault;

            nameLabelFormat.Alignment     = align;
            nameLabelFormat.LineAlignment = lineAlign;
            nameLabelFormat.Trimming      = StringTrimming.Character;
            nameLabelFormat.FormatFlags  |= StringFormatFlags.LineLimit;
            nameLabelFormat.FormatFlags  |= StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces;

            RectangleF pickRect = new RectangleF(textRect.X, textRect.Y, pickLoc.X - textRect.X, textRect.Height);

            using (var image = new Bitmap(1, 1)) { using (var g = Graphics.FromImage(image)) {
                                                       // Pick chars
                                                       float oldUsedWidth = 0.0f;
                                                       SizeF usedSize     = SizeF.Empty;
                                                       for (int i = 0; i <= text.Length; i++)
                                                       {
                                                           oldUsedWidth = usedSize.Width;
                                                           nameLabelFormat.SetMeasurableCharacterRanges(new [] { new CharacterRange(0, i) });
                                                           Region[] usedSizeRegions = g.MeasureCharacterRanges(text, font, textRect, nameLabelFormat);
                                                           usedSize = usedSizeRegions.Length > 0 ? usedSizeRegions[0].GetBounds(g).Size : SizeF.Empty;
                                                           if (usedSize.Width > pickRect.Width)
                                                           {
                                                               if (Math.Abs(oldUsedWidth - pickRect.Width) < Math.Abs(usedSize.Width - pickRect.Width))
                                                               {
                                                                   return(i - 1);
                                                               }
                                                               else
                                                               {
                                                                   return(i);
                                                               }
                                                           }
                                                       }
                                                   } }

            return(-1);
        }
示例#60
0
        public Region[] MeasureStringLine(Graphics g, string text, CharacterRange[] measureRanges, Font font, Rectangle textRect, StringAlignment align = StringAlignment.Near, StringAlignment lineAlign = StringAlignment.Center)
        {
            // Expand text rect, because DrawString stops too soon
            textRect.Width += DrawStringWidthAdd;
            textRect.Height = Math.Max(textRect.Height, font.Height);

            // Assume manual ellipsis
            textRect.Width -= 5;
            StringFormat nameLabelFormat = StringFormat.GenericDefault;

            nameLabelFormat.Alignment     = align;
            nameLabelFormat.LineAlignment = lineAlign;
            nameLabelFormat.Trimming      = StringTrimming.Character;
            nameLabelFormat.FormatFlags  |= StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces;
            nameLabelFormat.SetMeasurableCharacterRanges(measureRanges);

            return(g.MeasureCharacterRanges(text, font, textRect, nameLabelFormat));
        }