Esempio n. 1
0
		internal void saveStringFormat(StringFormat sf)
		{
			if (sf == null)
			{
				writer.Write((int)0);
				return;
			}
			writer.Write((int)1);

			StringAlignment al;
			int dsl;
			StringDigitSubstitute dsm;
			StringFormatFlags sff;
			System.Drawing.Text.HotkeyPrefix hp;
			StringAlignment lal;
			StringTrimming tr;
			float fto;
			float[] ts;

			al = sf.Alignment;
			dsl = sf.DigitSubstitutionLanguage;
			dsm = sf.DigitSubstitutionMethod;
			sff = sf.FormatFlags;
			hp = sf.HotkeyPrefix;
			lal = sf.LineAlignment;
			tr = sf.Trimming;
			ts = sf.GetTabStops(out fto);

			writer.Write((int)al);
			writer.Write(dsl);
			writer.Write((int)dsm);
			writer.Write((int)sff);
			writer.Write((int)hp);
			writer.Write((int)lal);
			writer.Write((int)tr);
			writer.Write((double)fto);
			writer.Write(ts.GetLength(0));
			foreach (float f in ts)
				writer.Write((double)f);
		}
Esempio n. 2
0
		public void TabsStops() 
		{
			using (StringFormat smf = new StringFormat ()) {
				float firstTabOffset;
				float[] tabsSrc = { 100, 200, 300, 400 };
				float[] tabStops;

				smf.SetTabStops (200, tabsSrc);
				tabStops = smf.GetTabStops (out firstTabOffset);

				Assert.AreEqual (200, firstTabOffset);
				Assert.AreEqual (tabsSrc.Length, tabStops.Length);
				Assert.AreEqual (tabsSrc[0], tabStops[0]);
				Assert.AreEqual (tabsSrc[1], tabStops[1]);
				Assert.AreEqual (tabsSrc[2], tabStops[2]);
				Assert.AreEqual (tabsSrc[3], tabStops[3]);
			}
		}
            /// <summary>
            /// Gets a TextFormatFlags value from the specified StringFormat object.
            /// </summary>
            private static TextFormatFlags GetTextFormatFlagsFromStringFormat(StringFormat format)
            {
                TextFormatFlags glyphOverhangPadding = TextFormatFlags.GlyphOverhangPadding;
                if (format != null)
                {
                    float num;
                    if (format.GetTabStops(out num) != null)
                    {
                        glyphOverhangPadding |= TextFormatFlags.ExpandTabs;
                    }
                    if ((format.FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0)
                    {
                        glyphOverhangPadding |= TextFormatFlags.RightToLeft;
                    }
                    if ((format.FormatFlags & StringFormatFlags.FitBlackBox) != 0)
                    {
                        glyphOverhangPadding |= TextFormatFlags.NoPadding;
                    }
                    if ((format.FormatFlags & StringFormatFlags.NoWrap) != 0)
                    {
                        glyphOverhangPadding |= TextFormatFlags.SingleLine;
                    }
                    else
                    {
                        glyphOverhangPadding |= TextFormatFlags.WordBreak;
                    }
                    if ((format.FormatFlags & StringFormatFlags.LineLimit) != 0)
                    {
                        glyphOverhangPadding |= TextFormatFlags.TextBoxControl;
                    }
                    switch (format.Alignment)
                    {
                        case StringAlignment.Center:
                            glyphOverhangPadding |= TextFormatFlags.HorizontalCenter;
                            break;

                        case StringAlignment.Far:
                            glyphOverhangPadding |= TextFormatFlags.Right;
                            break;

                        default:
                            //glyphOverhangPadding = glyphOverhangPadding;
                            break;
                    }
                    switch (format.LineAlignment)
                    {
                        case StringAlignment.Center:
                            glyphOverhangPadding |= TextFormatFlags.VerticalCenter;
                            break;

                        case StringAlignment.Far:
                            glyphOverhangPadding |= TextFormatFlags.Bottom;
                            break;

                        default:
                            //glyphOverhangPadding = glyphOverhangPadding;
                            break;
                    }
                    switch (format.Trimming)
                    {
                        case StringTrimming.EllipsisCharacter:
                            glyphOverhangPadding |= TextFormatFlags.EndEllipsis | TextFormatFlags.TextBoxControl;
                            break;

                        case StringTrimming.EllipsisWord:
                            glyphOverhangPadding |= TextFormatFlags.EndEllipsis | TextFormatFlags.TextBoxControl;
                            break;

                        case StringTrimming.EllipsisPath:
                            glyphOverhangPadding |= TextFormatFlags.PathEllipsis | TextFormatFlags.TextBoxControl;
                            break;

                        default:
                            if ((format.FormatFlags & StringFormatFlags.NoClip) != 0)
                            {
                                glyphOverhangPadding |= TextFormatFlags.NoClipping;
                            }
                            break;
                    }
                    switch (format.HotkeyPrefix)
                    {
                        case HotkeyPrefix.None:
                            return (glyphOverhangPadding | TextFormatFlags.NoPrefix);

                        case HotkeyPrefix.Show:
                            return glyphOverhangPadding;

                        case HotkeyPrefix.Hide:
                            return (glyphOverhangPadding | TextFormatFlags.HidePrefix);
                    }
                }
                return glyphOverhangPadding;
            }