Example #1
0
        public void SmallTextScaling()
        {
            // Set up a ScripturePublication of 4 on 6 pts (base character size on line spacing).
            m_pub.BaseFontSize    = 4000;
            m_pub.BaseLineSpacing = -6000;

            DummyScripturePublication scrPub = DummyScripturePublication.Create(m_pub,
                                                                                TeViewType.Scripture | TeViewType.PrintLayout, m_realStylesheet);
            InMemoryStyleSheet stylesheet = scrPub.StyleSheet as InMemoryStyleSheet;

            Assert.IsNotNull(stylesheet);

            ITsTextProps ttpNormalPara = stylesheet.GetStyleRgch(0, ScrStyleNames.NormalParagraph);
            int          nVar;

            // We expect that the normal style will have specified settings for the publication.
            Assert.AreEqual(4000,
                            ttpNormalPara.GetIntPropValues((int)FwTextPropType.ktptFontSize, out nVar));
            Assert.AreEqual(-6000,
                            ttpNormalPara.GetIntPropValues((int)FwTextPropType.ktptLineHeight, out nVar));
            scrPub.Dispose();

            // We expect that these styles will be overridden for font size at 40% their original size.
            ITsTextProps styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.IntroParagraph);

            Assert.AreEqual(4000, styleProps.GetIntPropValues((int)FwTextPropType.ktptFontSize, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.IntroSectionHead);
            Assert.AreEqual(4000, styleProps.GetIntPropValues((int)FwTextPropType.ktptFontSize, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.SectionHead);
            Assert.AreEqual(4000, styleProps.GetIntPropValues((int)FwTextPropType.ktptFontSize, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.MainBookTitle);
            Assert.AreEqual(8000, styleProps.GetIntPropValues((int)FwTextPropType.ktptFontSize, out nVar));

            // We expect that these styles will be overridden for line spacing at 50% their original size.
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.NormalFootnoteParagraph);
            Assert.AreEqual(5000, styleProps.GetIntPropValues((int)FwTextPropType.ktptLineHeight, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.IntroParagraph);
            Assert.AreEqual(-5500, styleProps.GetIntPropValues((int)FwTextPropType.ktptLineHeight, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.IntroSectionHead);
            Assert.AreEqual(-5000, styleProps.GetIntPropValues((int)FwTextPropType.ktptLineHeight, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.MainBookTitle);
            Assert.AreEqual(-12000, styleProps.GetIntPropValues((int)FwTextPropType.ktptLineHeight, out nVar));

            // We expect that these styles will be overridden for space before/after at 50% their original size.
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.MainBookTitle);
            Assert.AreEqual(18000, styleProps.GetIntPropValues((int)FwTextPropType.ktptSpaceBefore, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.MainBookTitle);
            Assert.AreEqual(6000, styleProps.GetIntPropValues((int)FwTextPropType.ktptSpaceAfter, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.SectionHead);
            Assert.AreEqual(4000, styleProps.GetIntPropValues((int)FwTextPropType.ktptSpaceBefore, out nVar));
            styleProps = stylesheet.GetStyleRgch(0, ScrStyleNames.SectionHead);
            Assert.AreEqual(2000, styleProps.GetIntPropValues((int)FwTextPropType.ktptSpaceAfter, out nVar));
        }
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Scales the given property based on the scaling factor and sets it in the in-memory
		/// stylesheet.
		/// </summary>
		/// <param name="stylesheet">The in-memory stylesheet used for overriding properties.
		/// </param>
		/// <param name="scalingFactor">The scaling factor.</param>
		/// <param name="styleName">Name of the style.</param>
		/// <param name="styleProps">The style props.</param>
		/// <param name="prop">The type of property to be scaled.</param>
		/// ------------------------------------------------------------------------------------
		private static void ScaleProperty(InMemoryStyleSheet stylesheet,
			decimal scalingFactor, string styleName, ITsTextProps styleProps,
			FwTextPropType prop)
		{
			int var;
			int propValue = styleProps.GetIntPropValues((int)prop, out var);
			if (propValue != -1 && var == (int)FwTextPropVar.ktpvMilliPoint)
			{
				if (prop == FwTextPropType.ktptFontSize)
				{
					Debug.Assert(propValue >= 4);
					// Calculate new value for this style, rounding to reasonable value.
					propValue = ScaleAndRoundProp(scalingFactor, propValue, 1000);
					// Adjusted font size must be at least 4 pts
					propValue = Math.Max(propValue, 4000);
				}
				else
					propValue = ScaleAndRoundProp(scalingFactor, propValue, 1);

				stylesheet.AddIntPropOverride(styleName, prop,
					FwTextPropVar.ktpvMilliPoint, propValue);
			}
		}