1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519 |
- using DocumentFormat.OpenXml;
- using HTEXLib.Models.Inner;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Xml;
- using System.Xml.Linq;
- using DocumentFormat.OpenXml.Presentation;
- using DocumentFormat.OpenXml.Drawing;
- using HTEXLib.Models;
- using ColorType = DocumentFormat.OpenXml.Drawing.ColorType;
- using System.Linq;
- using DocumentFormat.OpenXml.Packaging;
- namespace HTEXLib.Helpers.ShapeHelpers
- {
- public class SlideColor
- {
- public string LineColor { get; set; }
- public string FillColor { get; set; }
- public string EffectColor { get; set; }
- public string FontColor { get; set; }
- }
-
- public static class PPTXHelper
- {
- // StyleMatrixReferenceType
- ///处理边框
- //
- // 摘要:
- // LineReference.
- // Represents the following element tag in the schema: a:lnRef.
- //public LineReference LineReference { get; set; }
- //
- // 摘要:
- // FillReference.
- // Represents the following element tag in the schema: a:fillRef.
- // public FillReference FillReference { get; set; }
- //
- // 摘要:
- // EffectReference.
- // Represents the following element tag in the schema: a:effectRef.
- //
- // 摘要:
- // Font Reference.
- // Represents the following element tag in the schema: a:fontRef.
- // public FontReference FontReference { get; set; }
- /// <summary>
- /// 处理 LineReference 轮廓 a:lnRef
- /// 处理 FillReference 填充 a:fillRef
- /// 处理 EffectReference 效果 a:effectRef
- /// 处理 FontReference 字体 a:fontRef
- /// </summary>
- /// <param name="shapeStyle"></param>
- public static SlideColor DoShapeStyle(DocumentFormat.OpenXml.Presentation.ShapeStyle shapeStyle, PPTSlide slide, string type) {
- if (shapeStyle == null) {
- return null;
- }
- string LineColor = DoMatrixReferenceColors(shapeStyle.LineReference, slide);
- string FillColor = DoMatrixReferenceColors(shapeStyle.FillReference, slide);
- string EffectColor = DoMatrixReferenceColors(shapeStyle.EffectReference, slide);
- string FontColor = FontReferenceColors(shapeStyle.FontReference, slide);
- return new SlideColor { LineColor = LineColor, FillColor = FillColor, EffectColor = EffectColor, FontColor = FontColor };
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(GroupShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
- {
- //Outline
- var lnNode = shapeProperties.GetFirstChild<Outline>();
- Border border = null;
- if (lnNode != null)
- {
- border = DoOutline(lnNode, slide, type);
- }
- Fill fill = new Fill() { type = -1 };
- var gradFill = shapeProperties.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = shapeProperties.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = shapeProperties.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = shapeProperties.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = shapeProperties.GetFirstChild<GroupFill>();
- if (groupFill != null)
- {
- fill.type = 5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
- if (blipFill != null)
- {
- fill.type = 3;
- fill.blipFill = DoBlipFill(blipFill, slide, partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
- var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
- var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
- return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border };
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoTableProperties(TableProperties shapeProperties, PPTSlide slide, string type, string partForm)
- {
- Fill fill = new Fill() { type = -1 };
- var gradFill = shapeProperties.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = shapeProperties.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = shapeProperties.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = shapeProperties.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = shapeProperties.GetFirstChild<GroupFill>();
- if (groupFill != null)
- {
- fill.type = 5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
- if (blipFill != null)
- {
- fill.type = 3;
- fill.blipFill = DoBlipFill(blipFill, slide, partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- var TableStyle = shapeProperties.GetFirstChild<TableStyle>();
- var TableStyleId = shapeProperties.GetFirstChild<TableStyleId>();
- var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.ExtensionList>();
- return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill};
- }
- public static void DoTableStyle(TableStyle tableStyle, PPTSlide slide, string type, string partForm) {
- var TableBackground = tableStyle.TableBackground;
- if (TableBackground != null)
- {
- var shapeProperties = TableBackground.GetFirstChild<FillProperties>();
- Fill fill = DoFillProperties(shapeProperties , partForm,slide );
- var FillReference = TableBackground.GetFirstChild<FillReference>();
- DoFillReference(slide, fill, FillReference);
- //TODO
- TableBackground.GetFirstChild<EffectPropertiesType>();
- TableBackground.GetFirstChild<EffectReference>();
- }
- //TablePartStyleType
- var WholeTable = tableStyle.WholeTable;
- if (WholeTable != null) {
- DoTablePartStyleType(WholeTable, slide, type, partForm);
- }
- var Band1Horizontal = tableStyle.Band1Horizontal;
- if (Band1Horizontal != null)
- {
- DoTablePartStyleType(Band1Horizontal, slide, type, partForm);
- }
- var Band2Horizontal = tableStyle.Band2Horizontal;
- if (Band2Horizontal != null)
- {
- DoTablePartStyleType(Band2Horizontal, slide, type, partForm);
- }
- var Band1Vertical = tableStyle.Band1Vertical;
- if (Band1Vertical != null)
- {
- DoTablePartStyleType(Band1Vertical, slide, type, partForm);
- }
- var Band2Vertical = tableStyle.Band2Vertical;
- if (Band2Vertical != null)
- {
- DoTablePartStyleType(Band2Vertical, slide, type, partForm);
- }
- var LastColumn = tableStyle.LastColumn;
- if (LastColumn != null)
- {
- DoTablePartStyleType(LastColumn, slide, type, partForm);
- }
- var FirstColumn = tableStyle.FirstColumn;
- if (FirstColumn != null)
- {
- DoTablePartStyleType(FirstColumn, slide, type, partForm);
- }
- var FirstRow = tableStyle.FirstRow;
- if (FirstRow != null)
- {
- DoTablePartStyleType(FirstRow, slide, type, partForm);
- }
- var LastRow = tableStyle.LastRow;
- if (LastRow != null)
- {
- DoTablePartStyleType(LastRow, slide, type, partForm);
- }
- var SoutheastCell = tableStyle.SoutheastCell;
- if (SoutheastCell != null)
- {
- DoTablePartStyleType(SoutheastCell, slide, type, partForm);
- }
- var SouthwestCell = tableStyle.SouthwestCell;
- if (SouthwestCell != null)
- {
- DoTablePartStyleType(SouthwestCell, slide, type, partForm);
- }
- var NortheastCell = tableStyle.NortheastCell;
- if (NortheastCell != null)
- {
- DoTablePartStyleType(NortheastCell, slide, type, partForm);
- }
- var NorthwestCell = tableStyle.NorthwestCell;
- if (NorthwestCell != null)
- {
- DoTablePartStyleType(NorthwestCell, slide, type, partForm);
- }
- var ExtensionList = tableStyle.ExtensionList;
- }
- private static void DoFillReference(PPTSlide slide, Fill fill, FillReference FillReference)
- {
- if (FillReference != null)
- {
- if (fill.type == -1)
- {
- string color = null;
- if (FillReference.RgbColorModelPercentage != null)
- {
- color = ReadColor(FillReference.RgbColorModelPercentage);
- }
- if (FillReference.RgbColorModelHex != null)
- {
- color = ReadColor(FillReference.RgbColorModelHex);
- }
- if (FillReference.HslColor != null)
- {
- color = ReadColor(FillReference.HslColor);
- }
- if (FillReference.SystemColor != null)
- {
- color = ReadColor(FillReference.SystemColor, slide);
- }
- if (FillReference.SchemeColor != null)
- {
- color = ReadColor(FillReference.SchemeColor, slide);
- }
- if (FillReference.PresetColor != null)
- {
- color = ReadColor(FillReference.PresetColor);
- }
- fill.solidFill = color;
- fill.type = 2;
- }
- }
- }
- private static Fill DoFillProperties(FillProperties shapeProperties , string partForm, PPTSlide slide)
- {
- Fill fill = new Fill() { type = -1 };
- if (shapeProperties != null)
- {
- var gradFill = shapeProperties.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = shapeProperties.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = shapeProperties.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = shapeProperties.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = shapeProperties.GetFirstChild<GroupFill>();
- if (groupFill != null)
- {
- fill.type = 5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
- if (blipFill != null)
- {
- fill.type = 3;
- fill.blipFill = DoBlipFill(blipFill, slide, partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- }
- return fill;
- }
- public static void DoTablePartStyleType(TablePartStyleType tablePartStyleType, PPTSlide slide, string type, string partForm) {
- //表格单元格文本样式。
- var TableCellTextStyle = tablePartStyleType.GetFirstChild<TableCellTextStyle>();
- if (TableCellTextStyle != null) {
- FontStyle fontStyle = new FontStyle { };
- //字体加粗以及斜体
- if (TableCellTextStyle.Bold != null && TableCellTextStyle.Bold.Value == BooleanStyleValues.On)
- {
- fontStyle.bold = true;
- }
- else {
- fontStyle.bold = false;
- }
- if (TableCellTextStyle.Italic != null && TableCellTextStyle.Italic.Value == BooleanStyleValues.On)
- {
- fontStyle.italic = true;
- }
- //字体颜色
- string color = null;
- var RgbColorModelPercentage = TableCellTextStyle.GetFirstChild<RgbColorModelPercentage>();
- if (RgbColorModelPercentage != null)
- {
- color = ReadColor(RgbColorModelPercentage);
- }
- var RgbColorModelHex = TableCellTextStyle.GetFirstChild<RgbColorModelHex>();
- if (RgbColorModelHex != null)
- {
- color = ReadColor(RgbColorModelHex);
- }
- var HslColor = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.HslColor>();
- if (HslColor != null)
- {
- color = ReadColor(HslColor);
- }
- var SystemColor = TableCellTextStyle.GetFirstChild<SystemColor>();
- if (SystemColor != null)
- {
- color = ReadColor(SystemColor, slide);
- }
- var SchemeColor = TableCellTextStyle.GetFirstChild<SchemeColor>();
- if (SchemeColor != null)
- {
- color = ReadColor(SchemeColor, slide);
- }
- var PresetColor = TableCellTextStyle.GetFirstChild<PresetColor>();
- if (PresetColor != null)
- {
- color = ReadColor(PresetColor);
- }
- fontStyle.color = color;
- var FontReference = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.FontReference>();
- if (color == null && FontReference != null)
- {
- if (FontReference.RgbColorModelPercentage != null)
- {
- color = ReadColor(FontReference.RgbColorModelPercentage);
- }
- if (FontReference.RgbColorModelHex != null)
- {
- color = ReadColor(FontReference.RgbColorModelHex);
- }
- if (FontReference.HslColor != null)
- {
- color = ReadColor(FontReference.HslColor);
- }
- if (FontReference.SystemColor != null)
- {
- color = ReadColor(FontReference.SystemColor, slide);
- }
- if (FontReference.SchemeColor != null)
- {
- color = ReadColor(FontReference.SchemeColor, slide);
- }
- if (FontReference.PresetColor != null)
- {
- color = ReadColor(FontReference.PresetColor);
- }
- fontStyle.color = color;
- }
- //字体属性
- var font = TableCellTextStyle.GetFirstChild<DocumentFormat.OpenXml.Drawing.Fonts>();
- var LatinFont= font.LatinFont;
- var EastAsianFont= font.EastAsianFont;
- var ComplexScriptFont= font.ComplexScriptFont;
- if (EastAsianFont != null)
- {
- fontStyle.family= DoTextFontType(EastAsianFont,slide);
- }
- if (ComplexScriptFont != null)
- {
- fontStyle.family = DoTextFontType(ComplexScriptFont, slide);
- }
- if (LatinFont != null)
- {
- fontStyle.family = DoTextFontType(LatinFont, slide);
- }
- var SupplementalFont= font.GetFirstChild<SupplementalFont>();
- if (SupplementalFont != null) {
- fontStyle.family = SupplementalFont.Typeface;
- }
- }
- //表格单元格样式。
- var TableCellStyle = tablePartStyleType.GetFirstChild<TableCellStyle>();
- if (TableCellStyle != null)
- {
- var TableCellBorders= TableCellStyle.TableCellBorders;
- if (TableCellBorders != null) {
- var LeftBorder = TableCellBorders.LeftBorder;
- if (LeftBorder != null) {
- Border border= DoOutline(LeftBorder.Outline, slide, "tbl");
- if (LeftBorder.LineReference!=null&& border.color.type == -1) {
- border.color.solidFill=DoMatrixReferenceColors(LeftBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var RightBorder = TableCellBorders.RightBorder;
- if (RightBorder != null)
- {
- Border border = DoOutline(RightBorder.Outline, slide, "tbl");
- if (RightBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(RightBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var TopBorder = TableCellBorders.TopBorder;
- if (TopBorder != null)
- {
- Border border = DoOutline(TopBorder.Outline, slide, "tbl");
- if (TopBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var BottomBorder = TableCellBorders.BottomBorder;
- if (BottomBorder != null)
- {
- Border border = DoOutline(BottomBorder.Outline, slide, "tbl");
- if (BottomBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(BottomBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var InsideHorizontalBorder = TableCellBorders.InsideHorizontalBorder;
- if (InsideHorizontalBorder != null)
- {
- Border border = DoOutline(InsideHorizontalBorder.Outline, slide, "tbl");
- if (InsideHorizontalBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(InsideHorizontalBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var InsideVerticalBorder = TableCellBorders.InsideVerticalBorder;
- if (InsideVerticalBorder != null)
- {
- Border border = DoOutline(InsideVerticalBorder.Outline, slide, "tbl");
- if (InsideVerticalBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(InsideVerticalBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var TopLeftToBottomRightBorder = TableCellBorders.TopLeftToBottomRightBorder;
- if (TopLeftToBottomRightBorder != null)
- {
- Border border = DoOutline(TopLeftToBottomRightBorder.Outline, slide, "tbl");
- if (TopLeftToBottomRightBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopLeftToBottomRightBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- var TopRightToBottomLeftBorder = TableCellBorders.TopRightToBottomLeftBorder;
- if (TopRightToBottomLeftBorder != null)
- {
- Border border = DoOutline(TopRightToBottomLeftBorder.Outline, slide, "tbl");
- if (TopRightToBottomLeftBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopRightToBottomLeftBorder.LineReference, slide);
- border.color.type = 2;
- }
- }
- }
- var FillProperties = TableCellStyle.GetFirstChild<FillProperties>();
- Fill fill = DoFillProperties(FillProperties, partForm, slide);
- var FillReference = TableCellStyle.GetFirstChild<FillReference>();
- DoFillReference(slide, fill, FillReference);
- //TODO
- var Cell3DProperties = TableCellStyle.GetFirstChild<Cell3DProperties>();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="shapeProperties"></param>
- /// <param name="slide"></param>
- public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm) {
- //Outline
- var lnNode = shapeProperties.GetFirstChild<Outline>();
- Border border = null;
- if (lnNode != null)
- {
- border = DoOutline(lnNode, slide,type);
- }
- Fill fill = new Fill() { type = -1 };
- var gradFill = shapeProperties.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = shapeProperties.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = shapeProperties.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = shapeProperties.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = shapeProperties.GetFirstChild<GroupFill>();
- if (groupFill != null)
- {
- fill.type =5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
- if (blipFill != null)
- {
- fill.type = 3;
- fill.blipFill = DoBlipFill(blipFill, slide,partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var EffectList= shapeProperties.GetFirstChild<EffectList>();
- var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
- var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
- var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
- return new HTEXLib.Models.HTEX.ShapeStyle {fill=fill,border= border };
- }
- public static Fill DoBackgroundProperties(DocumentFormat.OpenXml.Presentation.BackgroundProperties shapeProperties, PPTSlide slide, string partForm)
- {
-
- Fill fill = new Fill() { type = -1 };
- var gradFill = shapeProperties.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = shapeProperties.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = shapeProperties.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = shapeProperties.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = shapeProperties.GetFirstChild<GroupFill>();
- if (groupFill != null)
- {
- fill.type = 5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.BlipFill>();
- if (blipFill != null)
- {
- fill.type = 3;
- fill.blipFill = DoBlipFill(blipFill, slide,partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- //var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
- //var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
- //var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
- return fill;
- }
- public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Drawing.BlipFill blipFill, PPTSlide slide,string partForm) {
- HtexBlipFill htexBlipFill = new HtexBlipFill();
- SourceRectangle source= blipFill.SourceRectangle; ///源矩形 srcRect可能无用
- htexBlipFill.dip = blipFill.Dpi;
- if (blipFill.RotateWithShape != null) {
- htexBlipFill.rotWithShape = blipFill.RotateWithShape;
- }
- { htexBlipFill.rotWithShape =true; }
-
- var fillRect = blipFill.GetTextByPath("a:stretch/a:fillRect");///拉伸
- if (fillRect != null) {
- htexBlipFill.fillRect = new Vector
- {
- t = fillRect.Attribute("t") != null ? int.Parse(fillRect.Attribute("t").Value) / 1000 : 0,
- l = fillRect.Attribute("l") != null ? int.Parse(fillRect.Attribute("l").Value) / 1000 : 0,
- r = fillRect.Attribute("r") != null ? int.Parse(fillRect.Attribute("r").Value) / 1000 : 0,
- b = fillRect.Attribute("b") != null ? int.Parse(fillRect.Attribute("b").Value) / 1000 : 0
- };
- }
- var alphaModFix = blipFill.Blip.GetTextByPath("a:alphaModFix");
- if (alphaModFix != null) {
- if (alphaModFix.Attribute("amt") != null) {
- htexBlipFill.opacity = int.Parse(alphaModFix.Attribute("amt").Value) * 1.0 / 1000;
- }
- }
- Tile tile= blipFill.GetFirstChild <Tile>();
- if (tile != null) {
- ///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
- htexBlipFill.tile = new HtexTile { algn=tile.Alignment,flip=tile.Flip,sx=tile.HorizontalRatio,sy=tile.VerticalRatio,tx=tile.HorizontalOffset,ty=tile.VerticalOffset};
- }
- var Embed = blipFill.Blip.Embed;
- var Link = blipFill.Blip.Link;
- //slide.SlideLayoutPart
- IdPartPair part = null;
- if (partForm == "slide")
- {
- part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (partForm == "layout")
- {
- part = slide.SlideLayoutPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (partForm == "master")
- {
- part = slide.slideMasterPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (part != null) {
- var url= part.OpenXmlPart.Uri .ToString().Replace("../","/ppt/");
- var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
- if (thumbnail != null)
- {
- var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
- var data = thumbnail.Value;
- url = "data:" + contentType + ";base64," + data;
- url = url.Replace("\r\n", "");
- htexBlipFill.url = url;
- htexBlipFill.urlType = "base64";
- htexBlipFill.contentType = contentType;
- }
- }
- //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
- return htexBlipFill;
- }
- public static HtexBlipFill DoBlipFill(DocumentFormat.OpenXml.Presentation.BlipFill blipFill, PPTSlide slide, string partForm)
- {
- HtexBlipFill htexBlipFill = new HtexBlipFill();
- SourceRectangle source = blipFill.SourceRectangle; ///源矩形 srcRect可能无用
- htexBlipFill.dip = blipFill.Dpi;
- if (blipFill.RotateWithShape != null)
- {
- htexBlipFill.rotWithShape = blipFill.RotateWithShape;
- }
- { htexBlipFill.rotWithShape = true; }
- var fillRect = blipFill.GetTextByPath("a:stretch/a:fillRect");///拉伸
- if (fillRect != null)
- {
- htexBlipFill.fillRect = new Vector
- {
- t = fillRect.Attribute("t") != null ? int.Parse(fillRect.Attribute("t").Value) / 1000 : 0,
- l = fillRect.Attribute("l") != null ? int.Parse(fillRect.Attribute("l").Value) / 1000 : 0,
- r = fillRect.Attribute("r") != null ? int.Parse(fillRect.Attribute("r").Value) / 1000 : 0,
- b = fillRect.Attribute("b") != null ? int.Parse(fillRect.Attribute("b").Value) / 1000 : 0
- };
- }
- var alphaModFix = blipFill.Blip.GetTextByPath("a:alphaModFix");
- if (alphaModFix != null)
- {
- if (alphaModFix.Attribute("amt") != null)
- {
- htexBlipFill.opacity = int.Parse(alphaModFix.Attribute("amt").Value) * 1.0 / 1000;
- }
- }
- Tile tile = blipFill.GetFirstChild<Tile>();
- if (tile != null)
- {
- ///algn (Alignment) flip (Tile Flipping) sx (Horizontal Ratio) sy (Vertical Ratio) tx (Horizontal Offset) ty (Vertical Offset)
- }
- var Embed = blipFill.Blip.Embed;
- var Link = blipFill.Blip.Link;
- //slide.SlideLayoutPart
- IdPartPair part = null;
- if (partForm == "slide") {
- part = slide.SlidePart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (partForm == "layout")
- {
- part = slide.SlideLayoutPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (partForm == "master")
- {
- part = slide.slideMasterPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (part != null)
- {
- var url = part.OpenXmlPart.Uri.ToString().Replace("../", "/ppt/");
- var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
- if (thumbnail != null)
- {
- var contentType = thumbnail.Attribute("{http://schemas.microsoft.com/office/2006/xmlPackage}contentType").Value;
- var data = thumbnail.Value;
- url = "data:" + contentType + ";base64," + data;
- url = url.Replace("\r\n", "");
- htexBlipFill.url = url;
- htexBlipFill.urlType = "base64";
- htexBlipFill.contentType = contentType;
- }
- }
- //TODO 图片元素的更多信息需要后期继续实现,如滤镜,裁剪,图片颜色,图片校正等
- return htexBlipFill;
- }
-
- /// <summary>
- /// a:ln 图形的外边
- /// </summary>
- /// <param name="shapeProperties"></param>
- /// <param name="slide"></param>
- public static Border DoOutline(DocumentFormat.OpenXml.Drawing.Outline outline, PPTSlide slide,string Shapetype) {
- Border border = new Border() {color= new Fill { type=-1} };
- //20.1.10.35 EMUs. 1 pt = 12700 EMUs.
- double? Width = null;
- if (outline.Width != null)
- {
- Width = double.Parse(outline.Width) * 1.0 * Globals.px96 / Globals.px914400;
- }
- else {
- if (Shapetype == "CxnSp") {
- Width = 0.75;
- }
-
- }
- // Center = 0,
- // Insert = 1
- //20.1.10.39
- int? algn = null;
- if (outline.Alignment != null) {
- algn = Convert.ToInt32(outline.Alignment);
- }
- /* 20.1.10.15 复合类型
- Single = 0, 单线 默认
- Double = 1, 双细线
- ThickThin = 2, 粗到细
- ThinThick = 3, 细到粗
- Triple = 4 三线
- */
- int? cmpd = null ;
- if (outline.CompoundLineType!=null) {
- cmpd = Convert.ToInt32(outline.CompoundLineType);
- }
-
- /* 20.1.10.31 线端类型
- Round = 0, 方
- Square = 1,圆
- Flat = 2 平
- */
- int? cap =null;
- if (outline.CapType != null) {
- cap = Convert.ToInt32(outline.CapType);
- }
- border.outline = new HtexOutline { Width = Width, algn = algn, cmpd = cmpd, cap = cap };
- var gradFill = outline.GetFirstChild<GradientFill>();
- if (gradFill != null)
- {
- border.color.type = 2;
- border.color.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = outline.GetFirstChild<NoFill>();
- if (noFill != null)
- {
- border.color.type = 0;
- }
- var pattFill = outline.GetFirstChild<PatternFill>();
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- border.color.type = 4;
- border.color.pattFill = htexPattFill;
- }
- var solidFill = outline.GetFirstChild<SolidFill>();
- if (solidFill != null)
- {
- border.color.type = 1;
- border.color.solidFill = DoSolidFill(solidFill, slide);
- }
- if (Width!=null && Width > 0) {
- border.type = "solid";
- border.stroke = "0";
- }
- var prstDash= outline.GetFirstChild<PresetDash>(); //预设连接符
- if (prstDash != null) {
- // PresetDash
- var (type, stroke) = DoPrstDash(prstDash);
- border.type = type;
- border.stroke = stroke;
- }
- if (outline.GetFirstChild<Bevel>() != null) {
- // 棱台切角
- border.corner = "bevel";
- }
- if (outline.GetFirstChild<Round>()!=null) {
- //圆角
- border.corner = "round";
- }
- if (outline.GetFirstChild<Miter>() != null) {
- //斜角
- border.corner = "miter";
- }
- var headEndNodeAttrs = outline.GetFirstChild<HeadEnd>(); //连接符开始符号
- if (headEndNodeAttrs != null)
- {
- border.headEnd = headEndNodeAttrs.Type;
- }
- var tailEndNodeAttrs = outline.GetFirstChild<TailEnd>();//末端连接符
- if (tailEndNodeAttrs != null)
- {
- border.tailEnd = tailEndNodeAttrs.Type;
- }
- //TODO
- //outline.GetTextByPath("//a:extLst");
- var custDash = outline.GetFirstChild<CustomDash>();//自定义连接线
- if (custDash != null) {
- var(type, stroke) = DoCustDash(custDash);
- border.type = type;
- border.stroke = stroke;
- }
- return border;
- }
- /// <summary>
- ///自定义连线符
- /// </summary>
- /// <param name="custDash"></param>
- /// <returns></returns>
- public static (string type, string stroke) DoCustDash(CustomDash custDash) {
- string type = "cust";
- string stroke = "";
- IEnumerable<XElement> elements= custDash.GetTextByPathList("ds");
- if (elements != null) {
- foreach (XElement element in elements) {
- var d= element.Attribute("d");//线段长度
- if (d != null) {
- stroke =stroke+ d.Value + ",";
- }
- var sp= element.Attribute("sp");//空白间距长度
- if (sp != null) {
- stroke =stroke+ sp.Value + ",";
- }
- }
- }
- if (string.IsNullOrEmpty(stroke)) {
- stroke = "0";
- }
- if (stroke.EndsWith(",")) {
- stroke.Substring(0, stroke.Length - 1);
- }
- return (type,stroke);
- }
- /// <summary>
- /// 预设连线符
- /// </summary>
- /// <param name="presetDash"></param>
- /// <returns></returns>
- public static (string type, string stroke) DoPrstDash(PresetDash presetDash)
- {
- Border border = new Border();
- string type = "solid";
- string stroke = "0";
- //PresetLineDashValues 枚举
- string val = presetDash.Val;
- switch (val)
- {
- case "solid":
- border.type = "solid";
- border.stroke = "0";
- break;
- case "dash":
- border.type += "dashed";
- border.stroke = "5";
- break;
- case "dashDot":
- border.type = "dashed";
- border.stroke = "5, 5, 1, 5";
- break;
- case "dot":
- border.type = "dotted";
- border.stroke = "1, 5";
- break;
- case "lgDash":
- border.type = "dashed";
- border.stroke = "10, 5";
- break;
- case "lgDashDotDot":
- border.type = "dashed";
- border.stroke = "10, 5, 1, 5, 1, 5";
- break;
- case "sysDash":
- border.type = "dashed";
- border.stroke = "5, 2";
- break;
- case "sysDashDot":
- border.type = "dashed";
- border.stroke = "5, 2, 1, 5";
- break;
- case "sysDashDotDot":
- border.type = "dashed";
- border.stroke = "5, 2, 1, 5, 1, 5";
- break;
- case "sysDot":
- border.type = "dotted";
- border.stroke = "2, 5";
- break;
- case null:
- //console.log(borderType);
- default:
- border.type = "solid";
- border.stroke = "0";
- break;
- }
-
- return (type,stroke);
- }
- public static HtexPattFill DoPattFill(DocumentFormat.OpenXml.Drawing.PatternFill patternFill , PPTSlide slide) {
- HtexPattFill htexPattFill = new HtexPattFill();
- if (patternFill.ForegroundColor != null)
- {
- htexPattFill.fgClr = ColorTypeColors(patternFill.ForegroundColor, slide);
- }
- if (patternFill.BackgroundColor != null)
- {
- htexPattFill.bgClr = ColorTypeColors(patternFill.BackgroundColor, slide);
- }
- htexPattFill.prst = patternFill.Preset;
- return htexPattFill;
- }
- /// <summary>
- /// 渐变颜色
- /// GradientStopList (渐变停止列表)(默认)
- /// LinearGradientFill(线性渐变填充)
- /// PathGradientFill (路径渐变)根据具体形状描边式
- /// TileRectangle (平铺矩形) 右下角是一个举行
- /// </summary>
- /// <param name="GradientFill"></param>
- /// <returns></returns>
- public static HtexGradientFill DoGradientFill(DocumentFormat.OpenXml.Drawing.GradientFill GradientFill, PPTSlide slide)
- {
- HtexGradientFill gradientFill = new HtexGradientFill();
- ///右下角弧形模式
- string type = "";
- ///平铺翻转模式
- ///Horizontal 水平
- ///HorizontalAndVertical 水平和垂直。
- ///Vertical 垂直
- ///None 无
- string name = "None";
- if (GradientFill.Flip != null) {
- name = GradientFill.Flip.Value.ToString();
- }
- gradientFill.flip = name;
- List<ColorPosition> colors = new List<ColorPosition>();
- bool RotateWithShape = true;
- if (GradientFill.RotateWithShape != null)
- {
- RotateWithShape = GradientFill.RotateWithShape;
- }
- gradientFill.RotateWithShape = RotateWithShape;
- foreach (GradientStop gradientStop in GradientFill.GradientStopList)
- {
- colors.Add(new ColorPosition
- {
- Color = ColorTypeColors(gradientStop, slide),
- Position = gradientStop.Position *1.0/ 1000 /// 位置,色带的位置 百分比0-100
- });
- }
- gradientFill.colors = colors;
- var lin = GradientFill.GetTextByPath("//a:lin");
- double? rot = null;
- string scaled = "";
- //线性模式
- if (lin != null) {
- rot = 90;
- type = "line";
- var ang = lin.Attribute("ang");
- var scaledNode = lin.Attribute("scaled");
- if (ang != null) {
- rot= ShapeHelper.AngleToDegrees(ang.Value) + 90;
- }
- if (scaledNode != null) {
- scaled = scaledNode.Value;
- }
- gradientFill.rot = rot;
- gradientFill.scaled = scaled;
- }
- var path = GradientFill.GetTextByPath("//a:path");
- if (path != null) {
- type = "path";
- ///circle
- ///rect
- ///shape
- gradientFill.pathType= path.Attribute("path").Value;
- var fillToRect=path.GetTextByPath("//a:fillToRect");
- if (fillToRect != null) {
- Vector vector= new Vector();
- var bnode = fillToRect.Attribute("b");
- var lnode = fillToRect.Attribute("l");
- var rnode = fillToRect.Attribute("r");
- var tnode = fillToRect.Attribute("t");
- if (bnode != null)
- {
- vector.b= int.Parse(bnode.Value) / 1000;
- }
- if (lnode != null)
- {
- vector.l = int.Parse(lnode.Value) / 1000;
- }
- if (rnode != null)
- {
- vector.r = int.Parse(rnode.Value) / 1000;
- }
- if (tnode != null)
- {
- vector.t = int.Parse(tnode.Value) / 1000;
- }
- gradientFill.fillToRect = vector;
- }
- }
- var tileRect = GradientFill.GetTextByPath("//a:tileRect");
- if (tileRect != null) {
- ///四个方向的偏移量,矩形的下边缘。例如50000/1000= 50% ,辐射百分比
- Vector vector = new Vector();
- var bnode = tileRect.Attribute("b");
- var lnode = tileRect.Attribute("l");
- var rnode = tileRect.Attribute("r");
- var tnode = tileRect.Attribute("t");
- if (bnode != null)
- {
- vector.b = int.Parse(bnode.Value) / 1000;
- }
- if (lnode != null)
- {
- vector.l = int.Parse(lnode.Value) / 1000;
- }
- if (rnode != null)
- {
- vector.r = int.Parse(rnode.Value) / 1000;
- }
- if (tnode != null)
- {
- vector.t = int.Parse(tnode.Value) / 1000;
- }
- gradientFill.tileRect = vector;
- }
- gradientFill.type = type;
- return gradientFill;
- }
-
- public static string ColorTypeColors(GradientStop Color, PPTSlide slide)
- {
- string FontColor = "";
- if (Color.RgbColorModelHex != null)
- {
- FontColor = ReadColor(Color.RgbColorModelHex);
- }
- else if (Color.RgbColorModelPercentage != null)
- {
- FontColor = ReadColor(Color.RgbColorModelPercentage);
- }
- else if (Color.SystemColor != null)
- {
- FontColor = ReadColor(Color.SystemColor, slide);
- }
- if (Color.SchemeColor != null)
- {
- FontColor = ReadColor(Color.SchemeColor, slide);
- }
- if (Color.HslColor != null)
- {
- FontColor = ReadColor(Color.HslColor);
- }
- if (Color.PresetColor != null)
- {
- FontColor = ReadColor(Color.PresetColor);
- }
- return FontColor;
- }
- public static string ColorTypeColors(ColorType Color, PPTSlide slide)
- {
- string FontColor = "";
- if (Color.RgbColorModelHex != null)
- {
- FontColor = ReadColor(Color.RgbColorModelHex);
- }
- else if (Color.RgbColorModelPercentage != null)
- {
- FontColor = ReadColor(Color.RgbColorModelPercentage);
- }
- else if (Color.SystemColor != null)
- {
- FontColor = ReadColor(Color.SystemColor, slide);
- }
- if (Color.SchemeColor != null)
- {
- FontColor = ReadColor(Color.SchemeColor, slide);
- }
- if (Color.HslColor != null)
- {
- FontColor = ReadColor(Color.HslColor);
- }
- if (Color.PresetColor != null)
- {
- FontColor = ReadColor(Color.PresetColor);
- }
- return FontColor;
- }
- public static string FontReferenceColors(FontReference Color, PPTSlide slide)
- {
- string FontColor = "";
- if (Color.RgbColorModelHex != null)
- {
- FontColor = ReadColor(Color.RgbColorModelHex);
- }
- else if (Color.RgbColorModelPercentage != null)
- {
- FontColor = ReadColor(Color.RgbColorModelPercentage);
- }
- else if (Color.SystemColor != null)
- {
- FontColor = ReadColor(Color.SystemColor, slide);
- }
- if (Color.SchemeColor != null)
- {
- FontColor = ReadColor(Color.SchemeColor, slide);
- }
- if (Color.HslColor != null)
- {
- FontColor = ReadColor(Color.HslColor);
- }
- if (Color.PresetColor != null)
- {
- FontColor = ReadColor(Color.PresetColor);
- }
- return FontColor;
- }
- public static string DoMatrixReferenceColors(StyleMatrixReferenceType Color, PPTSlide slide) {
- string FontColor = "";
- if (Color == null) {
- return FontColor;
- }
- if (Color.RgbColorModelHex != null)
- {
- FontColor = ReadColor(Color.RgbColorModelHex);
- }
- else if (Color.RgbColorModelPercentage != null)
- {
- FontColor = ReadColor(Color.RgbColorModelPercentage);
- }
- else if (Color.SystemColor != null)
- {
- FontColor = ReadColor(Color.SystemColor, slide);
- }
- if (Color.SchemeColor != null)
- {
- FontColor = ReadColor(Color.SchemeColor, slide);
- }
- if (Color.HslColor != null)
- {
- FontColor = ReadColor(Color.HslColor);
- }
- if (Color.PresetColor != null)
- {
- FontColor = ReadColor(Color.PresetColor);
- }
- return FontColor;
- }
-
- public static string DoSolidFill(SolidFill Color, PPTSlide slide)
- {
- string FontColor = "";
- if (Color.RgbColorModelHex != null)
- {
- FontColor = ReadColor(Color.RgbColorModelHex);
- }
- else if (Color.RgbColorModelPercentage != null)
- {
- FontColor = ReadColor(Color.RgbColorModelPercentage);
- }
- else if (Color.SystemColor != null)
- {
- FontColor = ReadColor(Color.SystemColor, slide);
- }
- if (Color.SchemeColor != null)
- {
- FontColor = ReadColor(Color.SchemeColor, slide);
- }
- if (Color.HslColor != null)
- {
- FontColor = ReadColor(Color.HslColor);
- }
- if (Color.PresetColor != null)
- {
- FontColor= ReadColor(Color.PresetColor);
- }
- return FontColor;
- }
- public static string ReadColor(DocumentFormat.OpenXml.Drawing.RgbColorModelHex RgbColorModelHex)
- {
- string FontColor = "";
- FontColor = "#" + RgbColorModelHex.Val;
- FontColor = "#" + ShapeHelper.ColorToning(RgbColorModelHex.OuterXml, FontColor.Replace("#", ""));
- return FontColor;
- }
- public static string ReadColor(DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage RgbColorModelPercentage)
- {
- string FontColor = "";
- int red =RgbColorModelPercentage.RedPortion.Value;
- int green = RgbColorModelPercentage.GreenPortion.Value;
- int blue = RgbColorModelPercentage.BluePortion.Value;
- var colorFromRGB = System.Drawing.Color.FromArgb(red, green, blue);
- string fontcolor = System.Drawing.ColorTranslator.ToHtml(colorFromRGB);
- FontColor = fontcolor;
- FontColor = "#" + ShapeHelper.ColorToning(RgbColorModelPercentage.OuterXml, FontColor.Replace("#", ""));
- return FontColor;
- }
- public static string ReadColor(DocumentFormat.OpenXml.Drawing.SystemColor SystemColor, PPTSlide slide)
- {
- string FontColor = "";
- FontColor = "#" + SystemColor.LastColor.Value;
- FontColor = "#" + ShapeHelper.ColorToning(SystemColor.OuterXml, FontColor.Replace("#", ""));
- return FontColor;
- }
- public static string ReadColor(DocumentFormat.OpenXml.Drawing.SchemeColor SchemeColor,PPTSlide slide) {
- string FontColor = "";
- FontColor = DoSchemeColor(SchemeColor, slide);
- FontColor = "#" + ShapeHelper.ColorToning(SchemeColor.OuterXml, FontColor.Replace("#", ""));
- return FontColor;
- }
- public static string ReadColor(DocumentFormat.OpenXml.Drawing.HslColor HslColor)
- {
- string FontColor = "";
- var hue =HslColor.HueValue / 100000;
- var sat = HslColor.SatValue / 100;
- var lum =HslColor.LumValue / 100;
- var hsl2rgb = ShapeHelper.HslToRgb(hue, sat, lum);
- FontColor = "#" + ShapeHelper.ToHex(hsl2rgb.r) + ShapeHelper.ToHex(hsl2rgb.g) + ShapeHelper.ToHex(hsl2rgb.b);
- FontColor = "#" + ShapeHelper.ColorToning(HslColor.OuterXml, FontColor.Replace("#", ""));
- return FontColor;
- }
-
- public static string ReadColor(PresetColor PresetColor) {
- string FontColor = "";
- //https://m.fontke.com/tool/rgb/0000ff/
- //判断是否是拿到名字 还是值
- FontColor = ShapeHelper.GetColorName2Hex(PresetColor.Val);
- FontColor = "#" + ShapeHelper.ColorToning(PresetColor.OuterXml, FontColor.Replace("#", ""));
- //TODO
- return FontColor;
- }
- public static string DoTextFontType(TextFontType latinFonts, PPTSlide slide)
- {
- string FontFamily = "";
- FontScheme allSchemeFonts =
- slide.SlideLayoutPart.SlideMasterPart.ThemePart.Theme
- .ThemeElements.FontScheme;
- var minorFont = allSchemeFonts.GetFirstChild<MinorFont>();
- var majorFont = allSchemeFonts.GetFirstChild<MajorFont>();
- if (latinFonts != null)
- {
- FontFamily = latinFonts.Typeface.Value;
- if (latinFonts.Typeface.Value.Equals("+mj-lt"))
- {
- FontFamily = majorFont.LatinFont.Typeface.Value;
- }
- else if (latinFonts.Typeface.Value.Equals("+mj-cs"))
- {
- FontFamily = majorFont.ComplexScriptFont.Typeface.Value;
- }
- else if (latinFonts.Typeface.Value.Equals("+mj-ea"))
- {
- FontFamily = majorFont.EastAsianFont.Typeface.Value;
- }
- else if (latinFonts.Typeface.Value.Equals("+mn-lt"))
- {
- FontFamily = minorFont.LatinFont.Typeface.Value;
- }
- else if (latinFonts.Typeface.Value.Equals("+mn-cs"))
- {
- FontFamily = minorFont.ComplexScriptFont.Typeface.Value;
- }
- else if (latinFonts.Typeface.Value.Equals("+mn-ea"))
- {
- FontFamily = minorFont.EastAsianFont.Typeface.Value;
- }
- }
- return FontFamily;
- }
- public static string DoSchemeColor(SchemeColor schemeColor, PPTSlide slide)
- {
- var light1Color1= slide.SlideLayoutPart.SlideMasterPart.
- ThemePart;
-
- string FontColor = "";
- if (schemeColor.Val == "bg1")
- {
- Light1Color light1Color = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Light1Color;
- if (light1Color.RgbColorModelHex != null)
- {
- FontColor = "#" + light1Color.RgbColorModelHex.Val.Value;
- }
- else if (light1Color.SystemColor != null)
- {
- FontColor = "#" + light1Color.SystemColor.LastColor.Value;
- }
- }
- else if (schemeColor.Val == "bg2")
- {
- Light2Color light2Color = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Light2Color;
- if (light2Color.RgbColorModelHex != null)
- {
- FontColor = "#" + light2Color.RgbColorModelHex.Val.Value;
- }
- else if (light2Color.SystemColor != null)
- {
- FontColor = "#" + light2Color.SystemColor.LastColor.Value;
- }
- }
- else if (schemeColor.Val == "tx1")
- {
- Dark1Color dark1Color = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Dark1Color;
- if (dark1Color.RgbColorModelHex != null)
- {
- FontColor = "#" + dark1Color.RgbColorModelHex.Val.Value;
- }
- else if (dark1Color.SystemColor != null)
- {
- FontColor = "#" + dark1Color.SystemColor.LastColor.Value;
- }
- }
- else if (schemeColor.Val == "tx2")
- {
- Dark2Color dark2Color = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Dark2Color;
- if (dark2Color.RgbColorModelHex != null)
- {
- FontColor = "#" + dark2Color.RgbColorModelHex.Val.Value;
- }
- else if (dark2Color.SystemColor != null)
- {
- FontColor = "#" + dark2Color.SystemColor.LastColor.Value;
- }
- }
- else if (schemeColor.Val == "hlink")
- {
- Hyperlink HyperLink = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Hyperlink;
- if (HyperLink.RgbColorModelHex != null)
- {
- FontColor = "#" + HyperLink.RgbColorModelHex.Val.Value;
- }
- }
- else if (schemeColor.Val == "folHlink")
- {
- FollowedHyperlinkColor folHyperLink = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.FollowedHyperlinkColor;
- if (folHyperLink.RgbColorModelHex != null)
- {
- FontColor = "#" + folHyperLink.RgbColorModelHex.Val.Value;
- }
- }
- if (string.IsNullOrEmpty(FontColor)) {
- FontColor = ReadAccentSchemeColors(schemeColor, slide);
- }
- return FontColor;
- }
- public static string ReadAccentSchemeColors(SchemeColor schemeColor, PPTSlide slide)
- {
- string FontColor = "";
- for (int i = 1; i <= 6; i++)
- {
- if (schemeColor.Val == "accent" + i)
- {
- switch (i)
- {
- case 1:
- {
- Accent1Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent1Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- case 2:
- {
- Accent2Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent2Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- case 3:
- {
- Accent3Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent3Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- case 4:
- {
- Accent4Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent4Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- case 5:
- {
- Accent5Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent5Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- case 6:
- {
- Accent6Color c = slide.SlideLayoutPart.SlideMasterPart.
- ThemePart.Theme.ThemeElements.ColorScheme.Accent6Color;
- if (c.RgbColorModelHex != null)
- FontColor = "#" + c.RgbColorModelHex.Val.Value;
- }
- break;
- default: { } break;
- }
- }
- }
- return FontColor;
- }
-
- }
- }
|