12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844 |
- 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;
- using DocumentFormat.OpenXml.Drawing.Charts;
- 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(DocumentFormat.OpenXml.Drawing.Charts.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>();
- // CustomGeometry PresetGeometry TODO
- return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border };
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(ChartShapeProperties 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>();
- // CustomGeometry PresetGeometry TODO
- return new HTEXLib.Models.HTEX.ShapeStyle { fill = fill, border = border };
- }
- 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 TbStyle 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 TableStyleId = shapeProperties.GetFirstChild<TableStyleId>().InnerText;
- TableStyleType TableStyle = shapeProperties.GetFirstChild<TableStyle>();
- if (TableStyle == null)
- {
- var TableStyleEntrys = slide.tableStylesPart.TableStyleList.Elements<TableStyleEntry>();
- foreach (var TableStyleEntry in TableStyleEntrys) {
- if (TableStyleEntry.StyleId == TableStyleId) {
- TableStyle = TableStyleEntry;
- }
- }
- }
- TbStyle tbStyle =DoTableStyle(TableStyle,slide,type,partForm);
- if (fill != null && fill.type == -1)
- {
- tbStyle.fill = fill;
- }
- //TODO
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<DocumentFormat.OpenXml.Drawing.ExtensionList>();
- tbStyle.RightToLeft = shapeProperties.RightToLeft != null? shapeProperties.RightToLeft.Value:false;
- tbStyle.FirstRow = shapeProperties.FirstRow != null ? shapeProperties.FirstRow.Value : false;
- tbStyle.FirstColumn = shapeProperties.FirstColumn != null ? shapeProperties.FirstColumn.Value : false;
- tbStyle.LastRow = shapeProperties.LastRow != null ? shapeProperties.LastRow.Value : false;
- tbStyle.LastColumn = shapeProperties.LastColumn != null ? shapeProperties.LastColumn.Value : false;
- tbStyle.BandRow = shapeProperties.BandRow != null ? shapeProperties.BandRow.Value : false;
- tbStyle.BandColumn = shapeProperties.BandColumn != null ? shapeProperties.BandColumn.Value : false;
- return tbStyle;
- }
- public static TbStyle DoTableStyle(TableStyleType tableStyle, PPTSlide slide, string type, string partForm) {
- TbStyle tbStyle = new TbStyle();
- if (tableStyle == null) {
- return tbStyle;
- }
- var TableBackground = tableStyle.TableBackground;
- if (TableBackground != null)
- {
- var shapeProperties = TableBackground.GetFirstChild<FillProperties>();
- Fill fill = DoFillProperties(shapeProperties , partForm,slide );
- var FillReference = TableBackground.GetFirstChild<FillReference>();
- fill= DoFillReference(slide, fill, FillReference);
- tbStyle.fill = fill;
- //TODO
- TableBackground.GetFirstChild<EffectPropertiesType>();
- TableBackground.GetFirstChild<EffectReference>();
- }
- //TablePartStyleType
- List<CellStyle> cellStyles = new List<CellStyle>();
- var WholeTable = tableStyle.WholeTable;
- if (WholeTable != null) {
- var style= DoTablePartStyleType(WholeTable, slide, type, partForm);
- if (style != null) {
- cellStyles.Add(style);
- }
- }
- var Band1Horizontal = tableStyle.Band1Horizontal;
- if (Band1Horizontal != null)
- {
- var style= DoTablePartStyleType(Band1Horizontal, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var Band2Horizontal = tableStyle.Band2Horizontal;
- if (Band2Horizontal != null)
- {
- var style= DoTablePartStyleType(Band2Horizontal, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var Band1Vertical = tableStyle.Band1Vertical;
- if (Band1Vertical != null)
- {
- var style= DoTablePartStyleType(Band1Vertical, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var Band2Vertical = tableStyle.Band2Vertical;
- if (Band2Vertical != null)
- {
- var style= DoTablePartStyleType(Band2Vertical, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var LastColumn = tableStyle.LastColumn;
- if (LastColumn != null)
- {
- var style= DoTablePartStyleType(LastColumn, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var FirstColumn = tableStyle.FirstColumn;
- if (FirstColumn != null)
- {
- var style= DoTablePartStyleType(FirstColumn, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var FirstRow = tableStyle.FirstRow;
- if (FirstRow != null)
- {
- var style= DoTablePartStyleType(FirstRow, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var LastRow = tableStyle.LastRow;
- if (LastRow != null)
- {
- var style= DoTablePartStyleType(LastRow, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var SoutheastCell = tableStyle.SoutheastCell;
- if (SoutheastCell != null)
- {
- var style= DoTablePartStyleType(SoutheastCell, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var SouthwestCell = tableStyle.SouthwestCell;
- if (SouthwestCell != null)
- {
- var style= DoTablePartStyleType(SouthwestCell, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var NortheastCell = tableStyle.NortheastCell;
- if (NortheastCell != null)
- {
- var style= DoTablePartStyleType(NortheastCell, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- var NorthwestCell = tableStyle.NorthwestCell;
- if (NorthwestCell != null)
- {
- var style= DoTablePartStyleType(NorthwestCell, slide, type, partForm);
- if (style != null)
- {
- cellStyles.Add(style);
- }
- }
- tbStyle.cellStyles = cellStyles;
- var ExtensionList = tableStyle.ExtensionList;
- return tbStyle;
- }
- private static Fill 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;
- }
- }
- return fill;
- }
- 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;
- }
- /// <summary>
- /// 单元格样式表
- /// </summary>
- /// <param name="tablePartStyleType"></param>
- /// <param name="slide"></param>
- /// <param name="type"></param>
- /// <param name="partForm"></param>
- public static CellStyle DoTablePartStyleType(TablePartStyleType tablePartStyleType, PPTSlide slide, string type, string partForm) {
- //表格单元格文本样式。
- CellStyle cellStyle = new CellStyle() { type= tablePartStyleType.GetType().Name};
- 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>();
- if (font != null) {
- 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;
- }
- cellStyle.fontStyle = fontStyle;
- }
- }
- //表格单元格样式。
- var TableCellStyle = tablePartStyleType.GetFirstChild<TableCellStyle>();
- if (TableCellStyle != null)
- {
- List<CellBorder> cellBorders = new List<CellBorder>();
- var TableCellBorders= TableCellStyle.TableCellBorders;
- if (TableCellBorders != null) {
- var LeftBorder = TableCellBorders.LeftBorder;
- if (LeftBorder != null) {
- Border border= DoOutline(LeftBorder.Outline, slide, type);
- if (LeftBorder.LineReference!=null&& border.color.type == -1) {
- border.color.solidFill=DoMatrixReferenceColors(LeftBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Left" });
- }
- var RightBorder = TableCellBorders.RightBorder;
- if (RightBorder != null)
- {
- Border border = DoOutline(RightBorder.Outline, slide, type);
- if (RightBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(RightBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Right" });
- }
- var TopBorder = TableCellBorders.TopBorder;
- if (TopBorder != null)
- {
- Border border = DoOutline(TopBorder.Outline, slide, type);
- if (TopBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Top" });
- }
- var BottomBorder = TableCellBorders.BottomBorder;
- if (BottomBorder != null)
- {
- Border border = DoOutline(BottomBorder.Outline, slide, type);
- if (BottomBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(BottomBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Bottom" });
- }
- var InsideHorizontalBorder = TableCellBorders.InsideHorizontalBorder;
- if (InsideHorizontalBorder != null)
- {
- Border border = DoOutline(InsideHorizontalBorder.Outline, slide, type);
- if (InsideHorizontalBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(InsideHorizontalBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "InHor" });
- }
- var InsideVerticalBorder = TableCellBorders.InsideVerticalBorder;
- if (InsideVerticalBorder != null)
- {
- Border border = DoOutline(InsideVerticalBorder.Outline, slide, type);
- if (InsideVerticalBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(InsideVerticalBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "InVer" });
- }
- var TopLeftToBottomRightBorder = TableCellBorders.TopLeftToBottomRightBorder;
- if (TopLeftToBottomRightBorder != null)
- {
- Border border = DoOutline(TopLeftToBottomRightBorder.Outline, slide, type);
- if (TopLeftToBottomRightBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopLeftToBottomRightBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Tl2br" });
- }
- var TopRightToBottomLeftBorder = TableCellBorders.TopRightToBottomLeftBorder;
- if (TopRightToBottomLeftBorder != null)
- {
- Border border = DoOutline(TopRightToBottomLeftBorder.Outline, slide, type);
- if (TopRightToBottomLeftBorder.LineReference != null && border.color.type == -1)
- {
- border.color.solidFill = DoMatrixReferenceColors(TopRightToBottomLeftBorder.LineReference, slide);
- border.color.type = 2;
- }
- cellBorders.Add(new CellBorder() { border = border, type = "Tr2bl" });
- }
- }
- cellStyle.cellBorders = cellBorders;
- var FillProperties = TableCellStyle.GetFirstChild<FillProperties>();
- Fill fill = DoFillProperties(FillProperties, partForm, slide);
- var FillReference = TableCellStyle.GetFirstChild<FillReference>();
- fill= DoFillReference(slide, fill, FillReference);
- cellStyle.fill = fill;
- //TODO
- var Cell3DProperties = TableCellStyle.GetFirstChild<Cell3DProperties>();
- }
- return cellStyle;
- }
- public static CellStyle DoTableCellProperties(TableCellProperties shapeProperties, PPTSlide slide ,string type ,string partForm) {
- CellStyle cellStyle = new CellStyle();
- //TODO
- var Cell3DProperties = shapeProperties.GetFirstChild<Cell3DProperties>();
- 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);
- }
- cellStyle.fill = fill;
- List<CellBorder> cellBorders = new List<CellBorder>();
- var LeftBorder = shapeProperties.LeftBorderLineProperties;
- if (LeftBorder != null)
- {
- Border border = DoOutline(LeftBorder, slide, type);
-
- cellBorders.Add(new CellBorder() { border = border, type = "Left" });
- }
- var RightBorder = shapeProperties.RightBorderLineProperties;
- if (RightBorder != null)
- {
- Border border = DoOutline(RightBorder, slide, type);
- cellBorders.Add(new CellBorder() { border = border, type = "Right" });
- }
- var TopBorderLineProperties = shapeProperties.TopBorderLineProperties;
- if (TopBorderLineProperties != null)
- {
- Border border = DoOutline(TopBorderLineProperties, slide, type);
- cellBorders.Add(new CellBorder() { border = border, type = "Top" });
- }
- var BottomBorderLineProperties = shapeProperties.BottomBorderLineProperties;
- if (BottomBorderLineProperties != null)
- {
- Border border = DoOutline(BottomBorderLineProperties, slide, type);
- cellBorders.Add(new CellBorder() { border = border, type = "Bottom" });
- }
- var TopLeftToBottomRightBorderLineProperties = shapeProperties.TopLeftToBottomRightBorderLineProperties;
- if (TopLeftToBottomRightBorderLineProperties != null)
- {
- // \
- Border border = DoOutline(TopLeftToBottomRightBorderLineProperties, slide, type);
- cellBorders.Add(new CellBorder() { border = border, type = "Tl2br" });
- }
- var BottomLeftToTopRightBorderLineProperties = shapeProperties.BottomLeftToTopRightBorderLineProperties;
- if (BottomLeftToTopRightBorderLineProperties != null)
- { // /
- Border border = DoOutline(BottomLeftToTopRightBorderLineProperties, slide, type);
- cellBorders.Add(new CellBorder() { border = border, type = "Tr2bl" });
- }
- cellStyle.cellBorders = cellBorders;
- return cellStyle;
- }
- /// <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 };
- if (shapeProperties == null) {
- return fill;
- }
- 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.LinePropertiesType 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
- string algn = null;
- if (outline.Alignment != null) {
- algn = outline.Alignment;
- }
- /* 20.1.10.15 复合类型
- Single = 0, 单线 默认
- Double = 1, 双细线
- ThickThin = 2, 粗到细
- ThinThick = 3, 细到粗
- Triple = 4 三线
- */
- string cmpd = null ;
- if (outline.CompoundLineType!=null) {
- cmpd = outline.CompoundLineType;
- }
-
- /* 20.1.10.31 线端类型
- Round = 0, 方
- Square = 1,圆
- Flat = 2 平
- */
- string cap =null;
- if (outline.CapType != null) {
- cap = 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);
- }
- if (FontColor.Replace("#", "") == "") {
- var chren= slide.SlideLayoutPart.SlideMasterPart.ThemePart.Theme.ThemeElements.ColorScheme.ChildElements;
- foreach(var cl in chren) {
- if (schemeColor.Val == cl.LocalName) {
- if (schemeColor.Val == "dk1" || schemeColor.Val == "lt1")
- {
- FontColor ="#"+ cl.GetFirstChild<SystemColor>().LastColor;
- }
- else {
- FontColor ="#"+cl.GetFirstChild<RgbColorModelHex>().Val.Value; ;
- }
- }
- }
- }
- 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;
- }
-
- }
- }
|