Exemplo n.º 1
0
        private void WriteFontAndParagraphRulesXml(ExportStyleInfo style, XmlWriter writer, string basedOnStyle, BaseStyleInfo nextStyle)
        {
            if (style.FontInfoForWs(-1) == null)
            {
                writer.WriteStartElement("font");
                writer.WriteEndElement();
                return;
            }
            // Generate the font info (the font element is required by the DTD even if it has no attributes)
            writer.WriteStartElement("font");
            IEnumerable <Tuple <string, string> > fontProps = CollectFontProps(style.FontInfoForWs(-1));

            if (fontProps.Any())
            {
                foreach (var prop in fontProps)
                {
                    writer.WriteAttributeString(prop.Item1, prop.Item2);
                }
            }
            foreach (var writingSystem in Cache.LangProject.AllWritingSystems)
            {
                var wsOverrideProps = CollectFontProps(style.FontInfoForWs(writingSystem.Handle));
                if (wsOverrideProps.Any())
                {
                    writer.WriteStartElement("override");
                    writer.WriteAttributeString("wsId", writingSystem.RFC5646);
                    foreach (var prop in wsOverrideProps)
                    {
                        writer.WriteAttributeString(prop.Item1, prop.Item2);
                    }
                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();             // font
            IEnumerable <Tuple <string, string> > paragraphProps = CollectParagraphProps(style, basedOnStyle, nextStyle);

            if (paragraphProps.Any())
            {
                writer.WriteStartElement("paragraph");
                foreach (var prop in paragraphProps)
                {
                    writer.WriteAttributeString(prop.Item1, prop.Item2);
                }
                writer.WriteEndElement();                 // paragraph
            }
        }
Exemplo n.º 2
0
		private bool WriteFontAttr(int ws, string sAttr, ExportStyleInfo esi, string sCss, bool fTopLevel)
		{
			FontInfo fi = esi.FontInfoForWs(ws);
			bool fInherited = false;
			string sInheritance = String.Empty;
			if (sCss == null && !fTopLevel)
				sInheritance = "\t/* inherited through cascaded environment */";
			if (sCss == null)
				sInheritance = "\t/* cascaded environment */";
			else if (!fTopLevel)
				sInheritance = "\t/* inherited */";
			switch (sAttr)
			{
				case "font-family":
					if (fi.m_fontName.ValueIsSet)
					{
						string sFontName = esi.RealFontNameForWs(ws);
						if (String.IsNullOrEmpty(sFontName))
							m_writer.WriteLine("    font-family: \"{0}\", serif;{1}", fi.m_fontName.Value, sInheritance);
						else
							m_writer.WriteLine("    font-family: \"{0}\", serif;{1}", sFontName, sInheritance);
						return true;
					}
					fInherited = fi.m_fontName.IsInherited;
					break;
				case "font-size":
					bool superSub = fi.m_superSub.ValueIsSet && fi.m_superSub.Value != FwSuperscriptVal.kssvOff;
					if (fi.m_fontSize.ValueIsSet)
					{
						var pointSize = fi.m_fontSize.Value;
						if (superSub)
							pointSize = pointSize*55/100;
						m_writer.WriteLine("    font-size: {0}pt;{1}", ConvertMptToPt(pointSize), sInheritance);
						return true;
					}
					if (superSub)
					{
						m_writer.WriteLine("    font-size: 55%;{0}", sInheritance);
						return true;
					}
					fInherited = fi.m_fontSize.IsInherited;
					break;
				case "font-weight":
					if (fi.m_bold.ValueIsSet)
					{
						m_writer.WriteLine("    font-weight: {0};{1}", fi.m_bold.Value ? "bold" : "normal", sInheritance);
						return true;
					}
					fInherited = fi.m_bold.IsInherited;
					break;
				case "font-style":
					if (fi.m_italic.ValueIsSet)
					{
						m_writer.WriteLine("    font-style: {0};{1}", fi.m_italic.Value ? "italic" : "normal", sInheritance);
						return true;
					}
					fInherited = fi.m_italic.IsInherited;
					break;
				case "color":
					if (fi.m_fontColor.ValueIsSet)
					{
						//Black as a font color is a default setting, we will ignore it (LT-10891)
						//however, if it is explicitly set we need to include it.
						if (fi.m_fontColor.Value != Color.Black || fi.m_fontColor.IsExplicit)
						{
							m_writer.WriteLine("    color: rgb({0},{1},{2});{3}",
											   fi.m_fontColor.Value.R,
											   fi.m_fontColor.Value.G,
											   fi.m_fontColor.Value.B,
											   sInheritance);
						}
						return true;
					}
					fInherited = fi.m_fontColor.IsInherited;
					break;
				case "background-color":
					if (fi.m_backColor.ValueIsSet)
					{
						//White as a background color is a default setting, we will ignore it (LT-10891)
						//however, if it is explicitly set we need to include it.
						if (fi.m_backColor.Value != Color.White || fi.m_fontColor.IsExplicit)
						{
							m_writer.WriteLine("    background-color: rgb({0},{1},{2});{3}",
											   fi.m_backColor.Value.R,
											   fi.m_backColor.Value.G,
											   fi.m_backColor.Value.B,
											   sInheritance);
						}
					return true;
					}
					fInherited = fi.m_backColor.IsInherited;
					break;
				case "vertical-align":
					if (fi.m_superSub.ValueIsSet)
					{
						m_writer.WriteLine("    vertical-align: {0};{1}", GetVerticalAlign(fi.m_superSub.Value), sInheritance);
						return true;
					}
					if (fi.m_offset.ValueIsSet)
					{
						m_writer.WriteLine("    vertical-align: {0}pt;{1}", ConvertMptToPt(fi.m_offset.Value), sInheritance);
						return true;
					}
					fInherited = fi.m_offset.IsInherited || fi.m_superSub.IsInherited;
					break;
				case "text-decoration":
					if (fi.m_underline.ValueIsSet)
					{
						m_writer.WriteLine("    text-decoration: {0};{1}",
							(fi.m_underline.Value == FwUnderlineType.kuntNone ? "none" : "underline"), sInheritance);
						return true;
					}
					fInherited = fi.m_underline.IsInherited;
					break;
			}
			if (fInherited)
			{
				string sBaseStyle = esi.InheritsFrom;
				BaseStyleInfo bsiBase;
				if (!String.IsNullOrEmpty(sBaseStyle) && m_styleTable.TryGetValue(GetValidCssClassName(sBaseStyle), out bsiBase))
				{
					if (WriteFontAttr(ws, sAttr, bsiBase as ExportStyleInfo, sCss, false))
						return true;
				}
				if (!String.IsNullOrEmpty(sCss))
				{
					List<string> rgsStyles;
					if (m_mapCssToStyleEnv.TryGetValue(sCss, out rgsStyles))
					{
						foreach (string sParaStyle in rgsStyles)
						{
							BaseStyleInfo bsiPara;
							if (m_styleTable.TryGetValue(GetValidCssClassName(sParaStyle), out bsiPara) &&
								WriteFontAttr(ws, sAttr, bsiPara as ExportStyleInfo, null, false))
							{
								return true;
							}
						}
					}
				}
			}
			return false;
		}
Exemplo n.º 3
0
        private void WriteFontAndParagraphRulesXml(ExportStyleInfo style, XmlWriter writer, string basedOnStyle, BaseStyleInfo nextStyle)
        {
            if (style.FontInfoForWs(-1) == null)
            {
                writer.WriteStartElement("font");
                writer.WriteEndElement();
                return;
            }
            // Generate the font info (the font element is required by the DTD even if it has no attributes)
            writer.WriteStartElement("font");
            IEnumerable <Tuple <string, string> > fontProps = CollectFontProps(style.FontInfoForWs(-1));

            if (fontProps.Any())
            {
                foreach (var prop in fontProps)
                {
                    writer.WriteAttributeString(prop.Item1, prop.Item2);
                }
            }
            foreach (var writingSystem in Cache.LangProject.AllWritingSystems)
            {
                var wsOverrideProps = CollectFontProps(style.FontInfoForWs(writingSystem.Handle));
                if (wsOverrideProps.Any())
                {
                    writer.WriteStartElement("override");
                    writer.WriteAttributeString("wsId", writingSystem.LanguageTag);
                    foreach (var prop in wsOverrideProps)
                    {
                        writer.WriteAttributeString(prop.Item1, prop.Item2);
                    }
                    writer.WriteEndElement();
                }
            }
            writer.WriteEndElement();             // font
            IEnumerable <Tuple <string, string> > paragraphProps = CollectParagraphProps(style, basedOnStyle, nextStyle);

            if (paragraphProps.Any())
            {
                writer.WriteStartElement("paragraph");
                foreach (var prop in paragraphProps)
                {
                    writer.WriteAttributeString(prop.Item1, prop.Item2);
                }

                //Bullet/Number FontInfo
                try
                {
                    IEnumerable <Tuple <string, string> > bulNumParaProperty = CollectBulletProps(style.BulletInfo);
                    foreach (var prop in bulNumParaProperty)
                    {
                        string propName = prop.Item1;
                        if (BulletPropertyMap.ContainsKey(propName.ToLower()))
                        {
                            propName = BulletPropertyMap[propName.ToLower()];
                        }
                        writer.WriteAttributeString(propName, prop.Item2);
                    }
                    // Generate the font info (the font element is required by the DTD even if it has no attributes)
                    writer.WriteStartElement("BulNumFontInfo");
                    IEnumerable <Tuple <string, string> > bulletFontInfoProperties = CollectFontProps(style.BulletInfo.FontInfo);
                    if (bulletFontInfoProperties.Any())
                    {
                        foreach (var prop in bulletFontInfoProperties)
                        {
                            writer.WriteAttributeString(prop.Item1, prop.Item2);
                        }
                    }
                    writer.WriteEndElement();                     // bullet
                }
                catch {}
                writer.WriteEndElement();                 // paragraph
            }
        }
Exemplo n.º 4
0
		private bool WriteFontAttr(int ws, string sAttr, ExportStyleInfo esi, string sCss, bool fTopLevel)
		{
			FontInfo fi = esi.FontInfoForWs(ws);
			bool fExplicit = false;
			bool fInherited = false;
			string sInheritance = String.Empty;
			if (sCss == null && !fTopLevel)
				sInheritance = "\t/* inherited through cascaded environment */";
			if (sCss == null)
				sInheritance = "\t/* cascaded environment */";
			else if (!fTopLevel)
				sInheritance = "\t/* inherited */";
			switch (sAttr)
			{
				case "font-family":
					if (fi.m_fontName.ValueIsSet)
					{
						string sFontName = esi.RealFontNameForWs(ws);
						if (String.IsNullOrEmpty(sFontName))
							m_writer.WriteLine("    font-family: \"{0}\", serif;{1}", fi.m_fontName.Value, sInheritance);
						else
							m_writer.WriteLine("    font-family: \"{0}\", serif;{1}", sFontName, sInheritance);
						return true;
					}
					fExplicit = fi.m_fontName.IsExplicit;
					fInherited = fi.m_fontName.IsInherited;
					break;
				case "font-size":
					if (fi.m_fontSize.ValueIsSet)
					{
						m_writer.WriteLine("    font-size: {0}pt;{1}", ConvertMptToPt(fi.m_fontSize.Value), sInheritance);
						return true;
					}
					fExplicit = fi.m_fontSize.IsExplicit;
					fInherited = fi.m_fontSize.IsInherited;
					break;
				case "font-weight":
					if (fi.m_bold.ValueIsSet)
					{
						m_writer.WriteLine("    font-weight: {0};{1}", fi.m_bold.Value ? "bold" : "normal", sInheritance);
						return true;
					}
					fExplicit = fi.m_bold.IsExplicit;
					fInherited = fi.m_bold.IsInherited;
					break;
				case "font-style":
					if (fi.m_italic.ValueIsSet)
					{
						m_writer.WriteLine("    font-style: {0};{1}", fi.m_italic.Value ? "italic" : "normal", sInheritance);
						return true;
					}
					fExplicit = fi.m_italic.IsExplicit;
					fInherited = fi.m_italic.IsInherited;
					break;
				case "color":
					if (fi.m_fontColor.ValueIsSet)
					{
						m_writer.WriteLine("    color: rgb({0},{1},{2});{3}",
							fi.m_fontColor.Value.R, fi.m_fontColor.Value.G, fi.m_fontColor.Value.B, sInheritance);
						return true;
					}
					fExplicit = fi.m_fontColor.IsExplicit;
					fInherited = fi.m_fontColor.IsInherited;
					break;
				case "background-color":
					if (fi.m_backColor.ValueIsSet)
					{
						m_writer.WriteLine("    background-color: rgb({0},{1},{2});{3}",
							fi.m_backColor.Value.R, fi.m_backColor.Value.G, fi.m_backColor.Value.B, sInheritance);
						return true;
					}
					fExplicit = fi.m_backColor.IsExplicit;
					fInherited = fi.m_backColor.IsInherited;
					break;
				case "vertical-align":
					if (fi.m_superSub.ValueIsSet)
					{
						m_writer.WriteLine("    vertical-align: {0};{1}", GetVerticalAlign(fi.m_superSub.Value), sInheritance);
						return true;
					}
					if (fi.m_offset.ValueIsSet)
					{
						m_writer.WriteLine("    vertical-align: {0}pt;{1}", ConvertMptToPt(fi.m_offset.Value), sInheritance);
						return true;
					}
					fExplicit = fi.m_offset.IsExplicit || fi.m_superSub.IsExplicit;
					fInherited = fi.m_offset.IsInherited || fi.m_superSub.IsInherited;
					break;
				case "text-decoration":
					if (fi.m_underline.ValueIsSet)
					{
						m_writer.WriteLine("    text-decoration: {0};{1}",
							(fi.m_underline.Value == FwUnderlineType.kuntNone ? "none" : "underline"), sInheritance);
						return true;
					}
					fExplicit = fi.m_underline.IsExplicit;
					fInherited = fi.m_underline.IsInherited;
					break;
			}
			if (fInherited)
			{
				string sBaseStyle = esi.InheritsFrom;
				BaseStyleInfo bsiBase;
				if (!String.IsNullOrEmpty(sBaseStyle) && m_styleTable.TryGetValue(sBaseStyle, out bsiBase))
				{
					if (WriteFontAttr(ws, sAttr, bsiBase as ExportStyleInfo, sCss, false))
						return true;
				}
				if (!String.IsNullOrEmpty(sCss))
				{
					List<string> rgsStyles;
					if (m_mapCssToStyleEnv.TryGetValue(sCss, out rgsStyles))
					{
						foreach (string sParaStyle in rgsStyles)
						{
							BaseStyleInfo bsiPara;
							if (m_styleTable.TryGetValue(sParaStyle, out bsiPara) &&
								WriteFontAttr(ws, sAttr, bsiPara as ExportStyleInfo, null, false))
							{
								return true;
							}
						}
					}
				}
			}
			return false;
		}