/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:BulletInfo"/> class. /// </summary> /// <param name="other">The other bullet info to copy from.</param> /// ------------------------------------------------------------------------------------ public BulletInfo(BulletInfo other) { m_numberScheme = other.m_numberScheme; m_start = other.m_start; m_textBefore = other.m_textBefore; m_textAfter = other.m_textAfter; m_fontInfo = new FontInfo(other.FontInfo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Appends the font and background color information to the description /// </summary> /// <param name="fontInfo"></param> /// <param name="text">The text.</param> /// ------------------------------------------------------------------------------------ private static void AppendFontColor(FontInfo fontInfo, StringBuilder text) { if (fontInfo.m_fontColor.IsInherited) AppendToString(text, String.Format(FwCoreDlgControls.ksBackgroundIsX, ColorUtil.ColorToName(fontInfo.m_backColor.Value))); else if (fontInfo.m_backColor.IsInherited) AppendToString(text, String.Format(FwCoreDlgControls.ksTextIsX, ColorUtil.ColorToName(fontInfo.m_fontColor.Value))); else AppendToString(text, string.Format(FwCoreDlgControls.ksTextIsXonY, ColorUtil.ColorToName(fontInfo.m_fontColor.Value), ColorUtil.ColorToName(fontInfo.m_backColor.Value))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy constructor /// </summary> /// ------------------------------------------------------------------------------------ public FontInfo(FontInfo copyFrom) { m_fontName = new InheritableStyleProp<string>(copyFrom.m_fontName); m_fontSize = new InheritableStyleProp<int>(copyFrom.m_fontSize); m_fontColor = new InheritableStyleProp<Color>(copyFrom.m_fontColor); m_backColor = new InheritableStyleProp<Color>(copyFrom.m_backColor); m_bold = new InheritableStyleProp<bool>(copyFrom.m_bold); m_italic = new InheritableStyleProp<bool>(copyFrom.m_italic); m_superSub = new InheritableStyleProp<FwSuperscriptVal>(copyFrom.m_superSub); m_underline = new InheritableStyleProp<FwUnderlineType>(copyFrom.m_underline); m_underlineColor = new InheritableStyleProp<Color>(copyFrom.m_underlineColor); m_offset = new InheritableStyleProp<int>(copyFrom.m_offset); m_features = new InheritableStyleProp<string>(copyFrom.m_features); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the specified font info. /// </summary> /// <param name="fontInfo">The font info.</param> /// <param name="fAllowSubscript"><c>true</c> to allow super/subscripts, <c>false</c> /// to disable the controls (used when called from Borders and Bullets tab)</param> /// <param name="ws">The default writing system (usually UI ws)</param> /// <param name="wsf">The writing system factory</param> /// <param name="styleSheet">The style sheet.</param> /// <param name="fAlwaysDisableFontFeatures"><c>true</c> to disable the Font Features /// button even when a Graphite font is selected.</param> /// ------------------------------------------------------------------------------------ void IFontDialog.Initialize(FontInfo fontInfo, bool fAllowSubscript, int ws, ILgWritingSystemFactory wsf, FwStyleSheet styleSheet, bool fAlwaysDisableFontFeatures) { m_DefaultWs = ws; m_preview.WritingSystemFactory = wsf; m_preview.WritingSystemCode = ws; m_preview.StyleSheet = styleSheet; m_tbFontName.Text = fontInfo.UIFontName(); FontSize = fontInfo.m_fontSize.Value / 1000; m_tbFontSize.Text = FontSize.ToString(CultureInfo.InvariantCulture); m_FontAttributes.UpdateForStyle(fontInfo); m_FontAttributes.AllowSuperSubScript = fAllowSubscript; m_FontAttributes.AlwaysDisableFontFeatures = fAlwaysDisableFontFeatures; UpdatePreview(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets all properties to inherited. /// </summary> /// <param name="basedOnFontInfo">The font info from which to get the inherited values. /// </param> /// ------------------------------------------------------------------------------------ internal void SetAllPropertiesToInherited(FontInfo basedOnFontInfo) { m_fontName.ResetToInherited(basedOnFontInfo.m_fontName); m_fontSize.ResetToInherited(basedOnFontInfo.m_fontSize); m_fontColor.ResetToInherited(basedOnFontInfo.m_fontColor); m_backColor.ResetToInherited(basedOnFontInfo.m_backColor); m_bold.ResetToInherited(basedOnFontInfo.m_bold); m_italic.ResetToInherited(basedOnFontInfo.m_italic); m_superSub.ResetToInherited(basedOnFontInfo.m_superSub); m_underline.ResetToInherited(basedOnFontInfo.m_underline); m_underlineColor.ResetToInherited(basedOnFontInfo.m_underlineColor); m_offset.ResetToInherited(basedOnFontInfo.m_offset); m_features.ResetToInherited(basedOnFontInfo.m_features); }
/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Appends the underline information to the description. /// </summary> /// <param name="fontInfo"></param> /// <param name="text">The text.</param> /// ------------------------------------------------------------------------------------ private static void AppendUnderline(FontInfo fontInfo, StringBuilder text) { string sUnder = ""; if (fontInfo.m_underlineColor.IsExplicit) { string sColor = ColorUtil.ColorToName(fontInfo.m_underlineColor.Value); if (fontInfo.m_underline.IsExplicit) { switch (fontInfo.m_underline.Value) { case FwUnderlineType.kuntNone: sUnder = String.Format(FwCoreDlgControls.ksNoColorUnderline, sColor); break; case FwUnderlineType.kuntSingle: sUnder = String.Format(FwCoreDlgControls.ksSingleColorUnderline, sColor); break; case FwUnderlineType.kuntDouble: sUnder = String.Format(FwCoreDlgControls.ksDoubleColorUnderline, sColor); break; case FwUnderlineType.kuntDotted: sUnder = String.Format(FwCoreDlgControls.ksDottedColorUnderline, sColor); break; case FwUnderlineType.kuntDashed: sUnder = String.Format(FwCoreDlgControls.ksDashedColorUnderline, sColor); break; case FwUnderlineType.kuntStrikethrough: sUnder = String.Format(FwCoreDlgControls.ksColorStrikethrough, sColor); break; } } else { sUnder = String.Format(FwCoreDlgControls.ksColorUnderline, sColor); } } else if (fontInfo.m_underline.IsExplicit) { switch (fontInfo.m_underline.Value) { case FwUnderlineType.kuntNone: sUnder = FwCoreDlgControls.ksNoUnderline; break; case FwUnderlineType.kuntSingle: sUnder = FwCoreDlgControls.ksSingleUnderline; break; case FwUnderlineType.kuntDouble: sUnder = FwCoreDlgControls.ksDoubleUnderline; break; case FwUnderlineType.kuntDotted: sUnder = FwCoreDlgControls.ksDottedUnderline; break; case FwUnderlineType.kuntDashed: sUnder = FwCoreDlgControls.ksDashedUnderline; break; case FwUnderlineType.kuntStrikethrough: sUnder = FwCoreDlgControls.ksStrikethrough; break; } } AppendToString(text, sUnder); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Decodes the font info. /// </summary> /// <param name="blob">The BLOB.</param> /// <returns>The font information represented in the BLOB.</returns> /// ------------------------------------------------------------------------------------ private static FontInfo DecodeFontInfo(string blob) { FontInfo fontInfo = new FontInfo(); fontInfo.SetAllDefaults(); if (blob != null) { for (int i = 0; i < blob.Length; ) { int iPropLim = blob.IndexOf('\0', i); if (iPropLim < 0) iPropLim = blob.Length; FwTextPropType tpt = (FwTextPropType)blob[i++]; if (tpt == FwTextPropType.ktptFontFamily) { fontInfo.m_fontName.ExplicitValue = blob.Substring(i, iPropLim - i); i += (iPropLim - i + 1); break; } else if (tpt == FwTextPropType.ktptFontVariations) { fontInfo.m_features.ExplicitValue = blob.Substring(i, iPropLim - i); i += (iPropLim - i + 1); break; } int nVal = (int)blob[i] + (int)(blob[i + 1] << 16); i += 2; switch (tpt) { case FwTextPropType.ktptBold: fontInfo.m_bold.ExplicitValue = nVal == 1; break; case FwTextPropType.ktptItalic: fontInfo.m_italic.ExplicitValue = nVal == 1; break; case FwTextPropType.ktptSuperscript: fontInfo.m_superSub.ExplicitValue = (FwSuperscriptVal)nVal; break; case FwTextPropType.ktptUnderline: fontInfo.m_underline.ExplicitValue = (FwUnderlineType)nVal; break; case FwTextPropType.ktptFontSize: fontInfo.m_fontSize.ExplicitValue = nVal; break; case FwTextPropType.ktptOffset: fontInfo.m_offset.ExplicitValue = nVal; break; case FwTextPropType.ktptBackColor: fontInfo.m_backColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal); break; case FwTextPropType.ktptForeColor: fontInfo.m_fontColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal); break; case FwTextPropType.ktptUnderColor: fontInfo.m_underlineColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal); break; } } } return fontInfo; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Encodes the font info as a string BLOB suitable for storing in the database. /// </summary> /// <param name="fontInfo">The font information.</param> /// <returns>Font info BLOB</returns> /// ------------------------------------------------------------------------------------ private static string EncodeFontInfo(FontInfo fontInfo) { List<char> binaryProps = new List<char>(); SetIntProp(binaryProps, fontInfo.m_backColor.IsExplicit, FwTextPropType.ktptBackColor, ColorUtil.ConvertColorToBGR(fontInfo.m_backColor.Value)); SetIntProp(binaryProps, fontInfo.m_bold.IsExplicit, FwTextPropType.ktptBold, Convert.ToUInt32(fontInfo.m_bold.Value)); SetIntProp(binaryProps, fontInfo.m_fontColor.IsExplicit, FwTextPropType.ktptForeColor, ColorUtil.ConvertColorToBGR(fontInfo.m_fontColor.Value)); SetIntProp(binaryProps, fontInfo.m_fontSize.IsExplicit, FwTextPropType.ktptFontSize, (uint)fontInfo.m_fontSize.Value); SetIntProp(binaryProps, fontInfo.m_italic.IsExplicit, FwTextPropType.ktptItalic, Convert.ToUInt32(fontInfo.m_italic.Value)); SetIntProp(binaryProps, fontInfo.m_underline.IsExplicit, FwTextPropType.ktptUnderline, (uint)fontInfo.m_underline.Value); SetIntProp(binaryProps, fontInfo.m_underlineColor.IsExplicit, FwTextPropType.ktptUnderColor, ColorUtil.ConvertColorToBGR(fontInfo.m_underlineColor.Value)); SetIntProp(binaryProps, fontInfo.m_offset.IsExplicit, FwTextPropType.ktptOffset, (uint)fontInfo.m_offset.Value); SetIntProp(binaryProps, fontInfo.m_superSub.IsExplicit, FwTextPropType.ktptSuperscript, (uint)fontInfo.m_superSub.Value); SetStrProp(binaryProps, fontInfo.m_fontName.IsExplicit, FwTextPropType.ktptFontFamily, fontInfo.m_fontName.Value); SetStrProp(binaryProps, fontInfo.m_features.IsExplicit, FwTextPropType.ktptFontVariations, fontInfo.m_features.Value); StringBuilder bldr = new StringBuilder(); bldr.Append(binaryProps.ToArray()); return bldr.ToString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the form based on a style being selected. /// </summary> /// <param name="styleInfo">The style info.</param> /// ------------------------------------------------------------------------------------ public void UpdateForStyle(StyleInfo styleInfo) { CheckDisposed(); #if __MonoCS__ // On Mono, the sequence of events when changing styles can cause this to be // called even when switching to a character style. See FWNX-870. if (!styleInfo.IsParagraphStyle) return; #endif m_dontUpdateInheritance = true; bool fDifferentStyle = m_StyleInfo == null ? true : (styleInfo.Name != m_StyleInfo.Name); // Don't use a 0 size bullet. Fixes FWNX-575. if (styleInfo != null && styleInfo.IBullet != null) if (styleInfo.IBullet.Value.FontInfo.FontSize.Value == 0) styleInfo.IBullet.Value.FontInfo.m_fontSize = new InheritableStyleProp<int>(FontInfo.kDefaultFontSize); m_StyleInfo = styleInfo; m_preview.IsRightToLeft = m_StyleInfo.DirectionIsRightToLeft == TriStateBool.triNotSet ? m_DefaultTextDirectionRtoL : m_StyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue; m_preview.WritingSystemFactory = m_StyleInfo.Cache.WritingSystemFactory; m_preview.WritingSystemCode = m_StyleInfo.Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle; VwBulNum bulletType; // Note: don't assign m_currentStyleBulletInfo until the end of this method // since setting some of the values change m_currentStyleBulletInfo before we have set // everything. BulletInfo bulletInfo = new BulletInfo(styleInfo.IBullet.Value); bulletType = bulletInfo.m_numberScheme; // If we have a different style, we have to reload the font info. If it is the same // style we were here before so we keep the font info that we already have. if (fDifferentStyle) { if ((int)bulletType >= (int)VwBulNum.kvbnBulletBase) { // use font from style for bullets m_BulletsFontInfo = bulletInfo.FontInfo; // create a number font based on the font for bullets m_NumberFontInfo = new FontInfo(m_BulletsFontInfo); m_NumberFontInfo.m_fontName.ResetToInherited(styleInfo.FontInfoForWs(-1).UIFontName()); } else { // use font from style for numbers m_NumberFontInfo = bulletInfo.FontInfo; if (bulletType == VwBulNum.kvbnNone) { m_NumberFontInfo.m_fontName.ResetToInherited(styleInfo.FontInfoForWs(-1).UIFontName()); } // create a bullets font based on the font for numbers m_BulletsFontInfo = new FontInfo(m_NumberFontInfo); // The font for bullets is hard-coded in the views code, so there is no point // in letting the user select any other font for bullets. m_BulletsFontInfo.m_fontName.ResetToInherited("Quivira"); m_BulletsFontInfo.m_fontName.SetDefaultValue("Quivira"); } } m_nudStartAt.Value = bulletInfo.m_start; m_chkStartAt.Checked = (bulletInfo.m_start != 1); m_tbTextBefore.Text = bulletInfo.m_textBefore; m_tbTextAfter.Text = bulletInfo.m_textAfter; m_rbUnspecified.Enabled = styleInfo.Inherits; if (styleInfo.IBullet.IsInherited && styleInfo.Inherits) m_rbUnspecified.Checked = true; else if (bulletType == VwBulNum.kvbnNone) m_rbNone.Checked = true; else if ((int)bulletType >= (int)VwBulNum.kvbnBulletBase) m_rbBullet.Checked = true; else // NumberBase m_rbNumber.Checked = true; m_cboBulletScheme.SelectedIndex = GetBulletIndexForType(bulletType); m_cboNumberScheme.SelectedIndex = GetNumberSchemeIndexForType(bulletType); m_currentStyleBulletInfo = bulletInfo; UpdateBulletSchemeComboBox(); m_dontUpdateInheritance = false; }
public void MergeWritingSystemWithStyleDefnForToWs_DoesNotConvertStyleDefinition() { IWritingSystem fromWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs); IWritingSystem toWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs); EnsureAnalysisWs(new[] { fromWs, toWs }); var style1 = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style1); var fontOverrides = new Dictionary<int, FontInfo>(); var fontOverride = new FontInfo(); fontOverride.m_italic.ExplicitValue = true; fontOverrides[fromWs.Handle] = fontOverride; fontOverride = new FontInfo(); fontOverride.m_bold.ExplicitValue = true; fontOverrides[toWs.Handle] = fontOverride; var bldr = TsPropsBldrClass.Create(); BaseStyleInfo.SaveFontOverridesToBuilder(fontOverrides, bldr); style1.Rules = bldr.GetTextProps(); m_actionHandler.EndUndoTask(); UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler, () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs)); var styleInfo = new BaseStyleInfo(style1); var overrideInfo = styleInfo.OverrideCharacterStyleInfo(toWs.Handle); Assert.IsNotNull(overrideInfo); Assert.That(overrideInfo.Bold.Value, Is.True); Assert.That(overrideInfo.Italic.ValueIsSet, Is.False); }