Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the type of the underline.
        /// </summary>
        /// <param name="fIsInherited">set to <c>true</c> if font position is inherited.</param>
        /// ------------------------------------------------------------------------------------
        public FwUnderlineType GetUnderlineType(out bool fIsInherited)
        {
            fIsInherited = IsInherited(m_cboUnderlineStyle);
            FwUnderlineType underlineType = FwUnderlineType.kuntMin;             // Init to make compiler happy

            if (!fIsInherited)
            {
                switch (m_cboUnderlineStyle.AdjustedSelectedIndex)
                {
                case 1: underlineType = FwUnderlineType.kuntNone; break;

                case 2: underlineType = FwUnderlineType.kuntSingle; break;

                case 3: underlineType = FwUnderlineType.kuntDouble; break;

                case 4: underlineType = FwUnderlineType.kuntDotted; break;

                case 5: underlineType = FwUnderlineType.kuntDashed; break;

                case 6: underlineType = FwUnderlineType.kuntStrikethrough; break;

                case -1: break;                         // nothing selected

                default:
                    Debug.Assert(false, "Unknown underline style");
                    break;
                }
            }
            return(underlineType);
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Saves the font info.
        /// </summary>
        /// <param name="fontInfo">The font info.</param>
        /// ------------------------------------------------------------------------------------
        void IFontDialog.SaveFontInfo(FontInfo fontInfo)
        {
            // Font name
            string newValue = GetInternalFontName(m_tbFontName.Text);

            fontInfo.IsDirty |= fontInfo.m_fontName.Save(false, newValue);

            // font size
            int fontSize = FontSize;

            fontInfo.IsDirty |= fontInfo.m_fontSize.Save(false, fontSize * 1000);

            // color
            bool  fIsInherited;
            Color color = m_FontAttributes.GetFontColor(out fIsInherited);

            fontInfo.IsDirty |= fontInfo.m_fontColor.Save(fIsInherited, color);

            // background color
            color             = m_FontAttributes.GetBackgroundColor(out fIsInherited);
            fontInfo.IsDirty |= fontInfo.m_backColor.Save(fIsInherited, color);

            // underline style
            FwUnderlineType underlineType = m_FontAttributes.GetUnderlineType(out fIsInherited);

            fontInfo.IsDirty |= fontInfo.m_underline.Save(fIsInherited, underlineType);

            // underline color
            color             = m_FontAttributes.GetUnderlineColor(out fIsInherited);
            fontInfo.IsDirty |= fontInfo.m_underlineColor.Save(fIsInherited, color);

            // bold, italic, superscript, subscript
            bool fFlag = m_FontAttributes.GetBold(out fIsInherited);

            fontInfo.IsDirty |= fontInfo.m_bold.Save(fIsInherited, fFlag);

            fFlag             = m_FontAttributes.GetItalic(out fIsInherited);
            fontInfo.IsDirty |= fontInfo.m_italic.Save(fIsInherited, fFlag);

            if (m_FontAttributes.AllowSuperSubScript)
            {
                FwSuperscriptVal superSub = m_FontAttributes.GetSubSuperscript(out fIsInherited);
                fontInfo.IsDirty |= fontInfo.m_superSub.Save(fIsInherited, superSub);

                // position
                int fontPos = m_FontAttributes.GetFontPosition(out fIsInherited);
                fontInfo.IsDirty |= fontInfo.m_offset.Save(fIsInherited, fontPos);
            }

            // features
            string fontFeatures = m_FontAttributes.GetFontFeatures(out fIsInherited);

            fontInfo.IsDirty |= fontInfo.m_features.Save(fIsInherited, fontFeatures);
        }
Пример #3
0
        /// <summary>
        /// Draw an underline from xdLeft to xdRight at ydTop, given the specified screen resolution,
        /// the desired colur and underline type, and (for aligning squiggles) the offset in the
        /// destination drawing rectangle.
        /// </summary>
        static void DrawUnderline(IVwGraphics pvg, int xdLeft, int xdRight, int ydTop,
                                  int dxScreenPix, int dyScreenPix, int clrUnder, FwUnderlineType unt, int xOffset)
        {
            int[] rgdx;
            pvg.ForeColor = clrUnder;
            int xStartPattern;

            switch (unt)
            {
            case FwUnderlineType.kuntSquiggle:
            {
                // BLOCK for var decls
                // ENHANCE JohnT: should we do some trick to make it look continuous
                // even if drawn in multiple chunks?
                // Note: going up as well as down from ydTop makes the squiggle
                // actually touch the bottom of typical letters. This is consistent
                // with Word; FrontPage puts the squiggle one pixel clear. If we want
                // the latter effect, just use ydTop + dyScreenPix.
                int dxdSeg = Math.Max(1, dxScreenPix * 2);
                int xdStartFromTrueLeft = ((xdLeft - xOffset) / dxdSeg) * dxdSeg; // aligns it to multiple of dxdSeg
                int xdStart             = xdStartFromTrueLeft + xOffset;          // back in drawing coords
                int dydStart            = -dyScreenPix;                           // toggle for up/down segs
                // Initial value is determined by whether xdStart is an odd or even multiple
                // of dxdSeg.
                if (xdStartFromTrueLeft % (dxdSeg * 2) != 0)
                {
                    dydStart = -dydStart;
                }
                while (xdStart < xdRight)
                {
                    int xdEnd = xdStart + dxdSeg;
                    pvg.DrawLine(xdStart, ydTop + dydStart, xdEnd, ydTop - dydStart);
                    dydStart = -dydStart;
                    xdStart  = xdEnd;
                }
            }
                // This uses diagonal lines so don't break and draw a straight one, return
                return;

            case FwUnderlineType.kuntDotted:
                rgdx = new [] { dxScreenPix *2, dxScreenPix *2 };
                break;

            case FwUnderlineType.kuntDashed:
                rgdx = new [] { dxScreenPix * 6, dxScreenPix * 3 };
                break;

            case FwUnderlineType.kuntStrikethrough:
            {
                int dydAscent = pvg.FontAscent;
                ydTop = ydTop - dydAscent / 3;
                rgdx  = new [] { int.MaxValue };
                break;
            }

            case FwUnderlineType.kuntDouble:
                xStartPattern = xdLeft;
                rgdx          = new [] { int.MaxValue };
                pvg.DrawHorzLine(xdLeft, xdRight, ydTop + dyScreenPix * 2, dyScreenPix,
                                 1, rgdx, ref xStartPattern);
                // continue to draw the upper line as well, just like a normal underline.
                break;

            case FwUnderlineType.kuntSingle:
            // For (some) forwards compatibility, treat any unrecognized underline
            // type as single.
            default:
                rgdx = new [] { int.MaxValue };
                break;
            }
            xStartPattern = xdLeft;
            pvg.DrawHorzLine(xdLeft, xdRight, ydTop, dyScreenPix,
                             rgdx.Length, rgdx, ref xStartPattern);
        }
Пример #4
0
		/// <summary>
		/// Draw an underline from xdLeft to xdRight at ydTop, given the specified screen resolution,
		/// the desired colur and underline type, and (for aligning squiggles) the offset in the
		/// destination drawing rectangle.
		/// </summary>
		static void DrawUnderline(IVwGraphics pvg, int xdLeft, int xdRight, int ydTop,
			int dxScreenPix, int dyScreenPix, int clrUnder, FwUnderlineType unt, int xOffset)
		{
			int[] rgdx;
			pvg.ForeColor = clrUnder;
			int xStartPattern;
			switch (unt)
			{
				case FwUnderlineType.kuntSquiggle:
					{
						// BLOCK for var decls
						// ENHANCE JohnT: should we do some trick to make it look continuous
						// even if drawn in multiple chunks?
						// Note: going up as well as down from ydTop makes the squiggle
						// actually touch the bottom of typical letters. This is consistent
						// with Word; FrontPage puts the squiggle one pixel clear. If we want
						// the latter effect, just use ydTop + dyScreenPix.
						int dxdSeg = Math.Max(1, dxScreenPix*2);
						int xdStartFromTrueLeft = ((xdLeft - xOffset)/dxdSeg)*dxdSeg; // aligns it to multiple of dxdSeg
						int xdStart = xdStartFromTrueLeft + xOffset; // back in drawing coords
						int dydStart = -dyScreenPix; // toggle for up/down segs
						// Initial value is determined by whether xdStart is an odd or even multiple
						// of dxdSeg.
						if (xdStartFromTrueLeft%(dxdSeg*2) != 0)
							dydStart = -dydStart;
						while (xdStart < xdRight)
						{
							int xdEnd = xdStart + dxdSeg;
							pvg.DrawLine(xdStart, ydTop + dydStart, xdEnd, ydTop - dydStart);
							dydStart = -dydStart;
							xdStart = xdEnd;
						}
					}
					// This uses diagonal lines so don't break and draw a straight one, return
					return;
				case FwUnderlineType.kuntDotted:
					rgdx = new [] {dxScreenPix*2, dxScreenPix*2};
					break;
				case FwUnderlineType.kuntDashed:
					rgdx = new [] { dxScreenPix * 6, dxScreenPix * 3 };
					break;
				case FwUnderlineType.kuntStrikethrough:
					{
						int dydAscent = pvg.FontAscent;
						ydTop = ydTop - dydAscent/3;
						rgdx = new [] {int.MaxValue};
						break;
					}
				case FwUnderlineType.kuntDouble:
					xStartPattern = xdLeft;
					rgdx = new [] { int.MaxValue };
					pvg.DrawHorzLine(xdLeft, xdRight, ydTop + dyScreenPix * 2, dyScreenPix,
						1, rgdx, ref xStartPattern);
					// continue to draw the upper line as well, just like a normal underline.
					break;
				case FwUnderlineType.kuntSingle:
					// For (some) forwards compatibility, treat any unrecognized underline
					// type as single.
				default:
					rgdx = new [] { int.MaxValue };
					break;
			}
			xStartPattern = xdLeft;
			pvg.DrawHorzLine(xdLeft, xdRight, ydTop, dyScreenPix,
				rgdx.Length, rgdx, ref xStartPattern);
		}
Пример #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Saves the font information to the styleInfo
        /// </summary>
        /// <param name="styleInfo">The style info.</param>
        /// ------------------------------------------------------------------------------------
        public void SaveToInfo(StyleInfo styleInfo)
        {
            CheckDisposed();

            FontInfo fontInfo = styleInfo.FontInfoForWs(m_currentWs);
            // Font name
            bool   newInherit = IsInherited(m_cboFontNames);
            string newValue   = string.Empty;

            switch (m_cboFontNames.AdjustedSelectedIndex)
            {
            case 1: newValue = StStyle.DefaultFont; break;

            case 2: newValue = StStyle.DefaultPubFont; break;

            case 3: newValue = StStyle.DefaultHeadingFont; break;

            default: newValue = m_cboFontNames.Text; break;
            }
            if (fontInfo.m_fontName.Save(newInherit, newValue))
            {
                styleInfo.Dirty = true;
            }

            // font size
            newInherit = IsInherited(m_cboFontSize);
            int fontSize = (m_cboFontSize.Text == string.Empty || newInherit) ? 0 : Int32.Parse(m_cboFontSize.Text);

            if (fontInfo.m_fontSize.Save(newInherit, fontSize * 1000))
            {
                styleInfo.Dirty = true;
            }

            // color
            Color color = m_FontAttributes.GetFontColor(out newInherit);

            if (fontInfo.m_fontColor.Save(newInherit, color))
            {
                styleInfo.Dirty = true;
            }

            // background color
            color = m_FontAttributes.GetBackgroundColor(out newInherit);
            if (fontInfo.m_backColor.Save(newInherit, color))
            {
                styleInfo.Dirty = true;
            }

            // underline style
            FwUnderlineType underlineType = m_FontAttributes.GetUnderlineType(out newInherit);

            if (fontInfo.m_underline.Save(newInherit, underlineType))
            {
                styleInfo.Dirty = true;
            }

            // underline color
            color = m_FontAttributes.GetUnderlineColor(out newInherit);
            if (fontInfo.m_underlineColor.Save(newInherit, color))
            {
                styleInfo.Dirty = true;
            }

            // bold, italic, superscript, subscript
            bool fFlag = m_FontAttributes.GetBold(out newInherit);

            if (fontInfo.m_bold.Save(newInherit, fFlag))
            {
                styleInfo.Dirty = true;
            }

            fFlag = m_FontAttributes.GetItalic(out newInherit);
            if (fontInfo.m_italic.Save(newInherit, fFlag))
            {
                styleInfo.Dirty = true;
            }

            FwSuperscriptVal superSub = m_FontAttributes.GetSubSuperscript(out newInherit);

            if (fontInfo.m_superSub.Save(newInherit, superSub))
            {
                styleInfo.Dirty = true;
            }

            // position
            int fontPos = m_FontAttributes.GetFontPosition(out newInherit);

            if (fontInfo.m_offset.Save(newInherit, fontPos))
            {
                styleInfo.Dirty = true;
            }

            // features
            string fontFeatures = m_FontAttributes.GetFontFeatures(out newInherit);

            if (fontInfo.m_features.Save(newInherit, fontFeatures))
            {
                styleInfo.Dirty = true;
            }
        }
Пример #6
0
		/// <summary>
		/// Return an object which, when passed to WithProperties, will return an assembled styles
		/// with the specified underline type.
		/// </summary>
		public static PropSetter UnderlineSetter(FwUnderlineType unt)
		{
			var result = new UnderlinePropSetter();
			result.SetToValue = (int)unt;
			return result;
		}
Пример #7
0
		public AssembledStyles WithUnderline(FwUnderlineType underlineType)
		{
			return m_styleCache.GetDerivedStyle(this, (int)FwTextPropType.ktptUnderline, underlineType,
												(newStyles, w) => newStyles.m_chrp.unt = (int)underlineType);
		}
Пример #8
0
 /// <summary>
 /// Fluent language: return this, but the contents of the flow have the specified underline type and color.
 /// </summary>
 public Flow Underline(FwUnderlineType unt, Color color)
 {
     AddSetter(AssembledStyles.UnderlineSetter(unt));
     AddSetter(AssembledStyles.UnderlineColorSetter(color));
     return(this);
 }
Пример #9
0
 /// <summary>
 /// Fluent language: return this, but the contents of the flow have the specified underline type.
 /// </summary>
 public Flow Underline(FwUnderlineType unt)
 {
     AddSetter(AssembledStyles.UnderlineSetter(unt));
     return(this);
 }