/// ------------------------------------------------------------------------------------ /// <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); }
public void ConnectStyles() { IStStyle normal = AddTestStyle("Normal", ContextValues.Internal, StructureValues.Undefined, FunctionValues.Prose, false); IStStyle normalParaStyle = AddTestStyle("Paragraph", ContextValues.Text, StructureValues.Body, FunctionValues.Prose, false); IStStyle sectionHead = AddTestStyle("Section Head", ContextValues.Text, StructureValues.Heading, FunctionValues.Prose, false); IStStyle verseNumberStyle = AddTestStyle("Verse Number", ContextValues.Text, StructureValues.Body, FunctionValues.Verse, true); IStStyle mainTitleStyle = AddTestStyle("Title Main", ContextValues.Title, StructureValues.Body, FunctionValues.Prose, false); IStStyle footnoteParaStyle = AddTestStyle("Note General Paragraph", ContextValues.Note, StructureValues.Undefined, FunctionValues.Prose, false); IStStyle footnoteMarkerStyle = AddTestStyle("Note Marker", ContextValues.Internal, StructureValues.Undefined, FunctionValues.Prose, true); StyleInfoTable table = new StyleInfoTable(string.Empty, Cache.ServiceLocator.WritingSystemManager); ITsPropsBldr props; props = normal.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20000); props.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, 16000); props.SetIntPropValues((int)FwTextPropType.ktptOffset, (int)FwTextPropVar.ktpvMilliPoint, 10000); normal.Rules = props.GetTextProps(); table.Add("Normal", new DummyStyleInfo(normal)); props = normalParaStyle.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptBorderLeading, (int)FwTextPropVar.ktpvMilliPoint, 1000); props.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvMilliPoint, 2000); props.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, 3000); props.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 4000); props.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.FromKnownColor(KnownColor.Thistle))); normalParaStyle.Rules = props.GetTextProps(); normalParaStyle.BasedOnRA = normal; normalParaStyle.NextRA = normalParaStyle; table.Add("Paragraph", new DummyStyleInfo(normalParaStyle)); props = footnoteParaStyle.Rules.GetBldr(); footnoteParaStyle.BasedOnRA = normalParaStyle; footnoteParaStyle.NextRA = null; table.Add("Note General Paragraph", new DummyStyleInfo(footnoteParaStyle)); props = sectionHead.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvOff); props.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.FromKnownColor(KnownColor.Aquamarine))); props.SetStrPropValue((int)FwTextPropType.ktptFontFamily, StyleServices.DefaultFont); sectionHead.Rules = props.GetTextProps(); sectionHead.BasedOnRA = normal; sectionHead.NextRA = normalParaStyle; DummyStyleInfo sectionInfo = new DummyStyleInfo(sectionHead); int wsEn = Cache.WritingSystemFactory.GetWsFromStr("en"); sectionInfo.FontInfoForWs(wsEn).m_fontName.ExplicitValue = "Arial"; table.Add("Section Head", sectionInfo); props = mainTitleStyle.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); props.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvDefault, (int)FwTextAlign.ktalCenter); props.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 16000); props.SetIntPropValues((int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvMilliPoint, 0); mainTitleStyle.Rules = props.GetTextProps(); mainTitleStyle.BasedOnRA = sectionHead; mainTitleStyle.NextRA = mainTitleStyle; table.Add("Title Main", new DummyStyleInfo(mainTitleStyle)); props = verseNumberStyle.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvDefault, (int)FwTextToggleVal.kttvForceOn); props.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvDefault, (int)FwTextToggleVal.kttvForceOn); props.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSuper); props.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvEnum, (int)FwUnderlineType.kuntDouble); props.SetIntPropValues((int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.FromKnownColor(KnownColor.SteelBlue))); props.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.FromKnownColor(KnownColor.Tomato))); props.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Courier"); verseNumberStyle.Rules = props.GetTextProps(); verseNumberStyle.BasedOnRA = null; verseNumberStyle.NextRA = null; table.Add("Verse Number", new DummyStyleInfo(verseNumberStyle)); footnoteMarkerStyle.BasedOnRA = verseNumberStyle; footnoteMarkerStyle.NextRA = null; table.Add("Note Marker", new DummyStyleInfo(footnoteMarkerStyle)); table.ConnectStyles(); // Check "Paragraph" style // Explicit properties DummyStyleInfo entry = (DummyStyleInfo)table["Paragraph"]; Assert.AreEqual("Paragraph", entry.Name); Assert.IsTrue(entry.IsParagraphStyle); Assert.AreEqual(table["Normal"].StyleNumber, entry.BasedOnStyleNumber); Assert.AreEqual(entry.StyleNumber, entry.NextStyleNumber); Assert.AreEqual(1000, entry.BorderLeading); Assert.AreEqual(2000, entry.BorderTop); Assert.AreEqual(3000, entry.BorderTrailing); Assert.AreEqual(4000, entry.BorderBottom); Assert.AreEqual((Color.FromKnownColor(KnownColor.Thistle)).ToArgb(), entry.BorderColor.ToArgb()); // Inherited properties FontInfo fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsFalse(entry.ExplicitRightToLeftStyle); Assert.IsFalse(fontInfo.m_italic.Value); Assert.IsFalse(fontInfo.m_bold.Value); Assert.AreEqual(20000, fontInfo.m_fontSize.Value); Assert.AreEqual(10000, fontInfo.m_offset.Value); Assert.AreEqual(FwUnderlineType.kuntNone, fontInfo.m_underline.Value); Assert.IsTrue(fontInfo.m_underlineColor.IsInherited); Assert.AreEqual(Color.Black, fontInfo.m_underlineColor.Value); Assert.IsTrue(fontInfo.m_features.IsInherited); Assert.AreEqual(null, fontInfo.m_features.Value); Assert.IsTrue(fontInfo.m_backColor.IsInherited); Assert.AreEqual(Color.Empty, fontInfo.m_backColor.Value); Assert.IsTrue(fontInfo.m_fontColor.IsInherited); Assert.AreEqual(Color.Black, fontInfo.m_fontColor.Value); Assert.AreEqual("<default font>", fontInfo.m_fontName.Value); Assert.AreEqual(FwSuperscriptVal.kssvOff, fontInfo.m_superSub.Value); Assert.AreEqual(FwTextAlign.ktalLeading, entry.Alignment); Assert.AreEqual(0, entry.FirstLineIndent); Assert.AreEqual(16000, entry.LineSpacing.m_lineHeight); Assert.AreEqual(0, entry.LeadingIndent); Assert.AreEqual(0, entry.TrailingIndent); Assert.AreEqual(0, entry.SpaceAfter); Assert.AreEqual(0, entry.SpaceBefore); // Check Normal Footnote Paragraph style // Explicit properties entry = (DummyStyleInfo)table["Note General Paragraph"]; Assert.AreEqual("Note General Paragraph", entry.Name); Assert.IsTrue(entry.IsParagraphStyle); Assert.AreEqual(table["Paragraph"].StyleNumber, entry.BasedOnStyleNumber); Assert.AreEqual("Note General Paragraph", entry.NextStyle.Name); // Inherited properties fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsFalse(entry.ExplicitRightToLeftStyle); Assert.IsFalse(fontInfo.m_italic.Value); Assert.IsFalse(fontInfo.m_bold.Value); Assert.AreEqual(20000, fontInfo.m_fontSize.Value); Assert.AreEqual(10000, fontInfo.m_offset.Value); Assert.AreEqual(FwUnderlineType.kuntNone, fontInfo.m_underline.Value); Assert.AreEqual(Color.Black, fontInfo.m_underlineColor.Value); Assert.IsNull(fontInfo.m_features.Value); Assert.AreEqual(Color.Empty, fontInfo.m_backColor.Value); Assert.AreEqual(Color.Black, fontInfo.m_fontColor.Value); Assert.AreEqual("<default font>", fontInfo.m_fontName.Value); Assert.AreEqual(FwSuperscriptVal.kssvOff, fontInfo.m_superSub.Value); Assert.AreEqual(FwTextAlign.ktalLeading, entry.Alignment); Assert.AreEqual(0, entry.FirstLineIndent); Assert.AreEqual(16000, entry.LineSpacing.m_lineHeight); Assert.AreEqual(0, entry.LeadingIndent); Assert.AreEqual(0, entry.TrailingIndent); Assert.AreEqual(0, entry.SpaceAfter); Assert.AreEqual(0, entry.SpaceBefore); Assert.AreEqual(1000, entry.BorderLeading); Assert.AreEqual(2000, entry.BorderTop); Assert.AreEqual(3000, entry.BorderTrailing); Assert.AreEqual(4000, entry.BorderBottom); Assert.AreEqual((Color.FromKnownColor(KnownColor.Thistle)).ToArgb(), entry.BorderColor.ToArgb()); // Check Title Main style // Explicit properties entry = (DummyStyleInfo)table["Title Main"]; Assert.AreEqual("Title Main", entry.Name); Assert.IsTrue(entry.IsParagraphStyle); Assert.AreEqual(FwTextAlign.ktalCenter, entry.Alignment); Assert.AreEqual(0, entry.FirstLineIndent); fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsTrue(fontInfo.m_bold.Value); Assert.AreEqual(16000, fontInfo.m_fontSize.Value); Assert.AreEqual(table["Section Head"].StyleNumber, entry.BasedOnStyleNumber); Assert.AreEqual(entry.StyleNumber, entry.NextStyleNumber); // Inherited properties Assert.IsFalse(entry.ExplicitRightToLeftStyle); Assert.IsFalse(fontInfo.m_italic.Value); Assert.AreEqual(10000, fontInfo.m_offset.Value); Assert.AreEqual(FwUnderlineType.kuntNone, fontInfo.m_underline.Value); Assert.AreEqual(Color.Black, fontInfo.m_underlineColor.Value); Assert.IsNull(fontInfo.m_features.Value); Assert.AreEqual((Color.FromKnownColor(KnownColor.Aquamarine)).ToArgb(), fontInfo.m_backColor.Value.ToArgb()); Assert.AreEqual(Color.Black, fontInfo.m_fontColor.Value); Assert.AreEqual("<default font>", fontInfo.m_fontName.Value); Assert.AreEqual(16000, entry.LineSpacing.m_lineHeight); Assert.AreEqual(0, entry.LeadingIndent); Assert.AreEqual(0, entry.TrailingIndent); Assert.AreEqual(0, entry.SpaceAfter); Assert.AreEqual(0, entry.SpaceBefore); Assert.AreEqual(FwSuperscriptVal.kssvOff, fontInfo.m_superSub.Value); fontInfo = entry.FontInfoForWs(wsEn); Assert.AreEqual("Arial", fontInfo.m_fontName.Value); // Check Section Head style // Explicit properties entry = (DummyStyleInfo)table["Section Head"]; Assert.AreEqual("Section Head", entry.Name); Assert.IsTrue(entry.IsParagraphStyle); fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsFalse(fontInfo.m_italic.Value); Assert.AreEqual(FwUnderlineType.kuntNone, fontInfo.m_underline.Value); Assert.AreEqual(Color.Black, fontInfo.m_underlineColor.Value); Assert.IsNull(fontInfo.m_features.Value); Assert.AreEqual((Color.FromKnownColor(KnownColor.Aquamarine)).ToArgb(), fontInfo.m_backColor.Value.ToArgb()); Assert.AreEqual("<default font>", fontInfo.m_fontName.Value); Assert.AreEqual(table["Normal"].StyleNumber, entry.BasedOnStyleNumber); Assert.AreEqual(table["Paragraph"].StyleNumber, entry.NextStyleNumber); // Inherited properties Assert.IsFalse(entry.ExplicitRightToLeftStyle); Assert.AreEqual(FwTextAlign.ktalLeading, entry.Alignment); Assert.AreEqual(0, entry.FirstLineIndent); Assert.IsFalse(fontInfo.m_bold.Value); Assert.AreEqual(20000, fontInfo.m_fontSize.Value); Assert.AreEqual(10000, fontInfo.m_offset.Value); Assert.AreEqual(Color.Black, fontInfo.m_fontColor.Value); Assert.AreEqual(16000, entry.LineSpacing.m_lineHeight); Assert.AreEqual(0, entry.LeadingIndent); Assert.AreEqual(0, entry.TrailingIndent); Assert.AreEqual(0, entry.SpaceAfter); Assert.AreEqual(0, entry.SpaceBefore); Assert.AreEqual(FwSuperscriptVal.kssvOff, fontInfo.m_superSub.Value); // Check Verse Number style // Explicit properties entry = (DummyStyleInfo)table["Verse Number"]; Assert.AreEqual("Verse Number", entry.Name); Assert.IsFalse(entry.IsParagraphStyle); fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsTrue(fontInfo.m_bold.Value); Assert.IsTrue(fontInfo.m_italic.Value); Assert.AreEqual(FwSuperscriptVal.kssvSuper, fontInfo.m_superSub.Value); Assert.AreEqual(FwUnderlineType.kuntDouble, fontInfo.m_underline.Value); Assert.AreEqual((Color.FromKnownColor(KnownColor.SteelBlue)).ToArgb(), fontInfo.m_underlineColor.Value.ToArgb()); Assert.AreEqual((Color.FromKnownColor(KnownColor.Tomato)).ToArgb(), fontInfo.m_fontColor.Value.ToArgb()); Assert.AreEqual("Courier", fontInfo.m_fontName.Value); Assert.AreEqual(0, entry.BasedOnStyleNumber); // Inherited properties Assert.IsTrue(fontInfo.m_fontSize.IsInherited); Assert.IsTrue(fontInfo.m_offset.IsInherited); // Check Footnote Marker style // Explicit properties entry = (DummyStyleInfo)table["Note Marker"]; Assert.AreEqual("Note Marker", entry.Name); Assert.IsFalse(entry.IsParagraphStyle); Assert.AreEqual(table["Verse Number"].StyleNumber, entry.BasedOnStyleNumber); // Inherited properties fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsTrue(fontInfo.m_bold.Value); Assert.IsTrue(fontInfo.m_italic.Value); Assert.AreEqual(FwSuperscriptVal.kssvSuper, fontInfo.m_superSub.Value); Assert.AreEqual(FwUnderlineType.kuntDouble, fontInfo.m_underline.Value); Assert.AreEqual((Color.FromKnownColor(KnownColor.SteelBlue)).ToArgb(), fontInfo.m_underlineColor.Value.ToArgb()); Assert.AreEqual((Color.FromKnownColor(KnownColor.Tomato)).ToArgb(), fontInfo.m_fontColor.Value.ToArgb()); Assert.AreEqual("Courier", fontInfo.m_fontName.Value); // Inherited properties Assert.IsTrue(fontInfo.m_fontSize.IsInherited); Assert.IsTrue(fontInfo.m_offset.IsInherited); }