123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613 |
- 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;
- using System.Drawing;
- using HTEXLib.Helpers.ColorHelpers;
- using System.IO;
- 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 SlideColor DoShapeStyle(DocumentFormat.OpenXml.Office.Drawing.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.PPTX.Models.HyperLink DoHyperlinkType(HyperlinkType hyperlink,PPTSlide slide ,string partForm) {
- if (hyperlink == null) {
- return null;
- }
- string linkType = hyperlink.LocalName;
- HyperlinkRelationship hyperlinksp = null;
- if (partForm == "slide")
- {
- hyperlinksp = slide.SlidePart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
- }
- if (partForm == "layout")
- {
- hyperlinksp = slide.SlideLayoutPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
- }
- if (partForm == "master")
- {
- hyperlinksp = slide.slideMasterPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
- }
- if (partForm == "drawing")
- {
- hyperlinksp = slide.diagramDataPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
- }
- if (partForm == "chart")
- {
- hyperlinksp = slide.chartPart.HyperlinkRelationships.Where(x => x.Id == hyperlink.Id).FirstOrDefault();
- }
- HTEXLib.PPTX.Models.HyperLink hyper = new HTEXLib.PPTX.Models.HyperLink
- {
- linkType = linkType,
- // history = hyperlink.History != null ? hyperlink.History.Value.ToString() : null,
- // invalidUrl = hyperlink.InvalidUrl != null ? hyperlink.InvalidUrl.Value.ToString() : null,
- //tgtFrame = hyperlink.TargetFrame != null ? hyperlink.TargetFrame.Value.ToString() : null,
- // tooltip = hyperlink.Tooltip!=null ? hyperlink.Tooltip.Value.ToString():null,
- // id = hyperlink.Id!=null ? hyperlink.Id.Value.ToString():null,
- action = hyperlink.Action!=null?hyperlink.Action.Value.ToString():null,
- highlightClick = hyperlink.HighlightClick!=null ? hyperlink.HighlightClick.Value:false,
- // endSnd = hyperlink.EndSound!=null? hyperlink.EndSound.Value:false
- };
- if (hyperlink.HyperlinkSound != null)
- {
- hyper.sndName = hyperlink.HyperlinkSound.Name;
- DataPartReferenceRelationship snd = null;
- if (partForm == "slide")
- {
- snd = slide.SlidePart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
- }
- if (partForm == "layout")
- {
- snd = slide.SlideLayoutPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
- }
- if (partForm == "master")
- {
- snd = slide.slideMasterPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
- }
- if (partForm == "drawing")
- {
- snd = slide.diagramDataPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
- }
- if (partForm == "chart")
- {
- snd = slide.chartPart.DataPartReferenceRelationships.Where(x => x.Id == hyperlink.HyperlinkSound.Embed).FirstOrDefault();
- }
- if (snd != null) {
- var url = snd.Uri.ToString().Replace("../", "/ppt/");
- var name = url.Replace("/", "");
- var thumbnail = slide.Media.Where(x => x.Attributes().Select(y => y.Value == url).FirstOrDefault()).FirstOrDefault();
- hyper.sndUrl = name;
- }
- }
- if (hyperlinksp != null) {
- var url= hyperlinksp.Uri.IsAbsoluteUri? hyperlinksp.Uri.AbsoluteUri : hyperlinksp.Uri.OriginalString;
- hyper.url = url;
- var strs= hyperlinksp.RelationshipType.Split('/');
- //hyper.type = strs[strs.Length-1];
- //var type = hyperlinksp.RelationshipType;
- //string[] s = type.Split('/');
- //linkType = s[s.Length - 1];
- //link = hyperlinksp.Uri.ToString();
- //if (hyperlink.Action != null && (hyperlink.Action.Value.StartsWith("ppaction://hlinkpres") || hyperlink.Action.Value.StartsWith("ppaction://hlinkfile")
- // || hyperlink.Action.Value.StartsWith("ppaction://hlinksldjump")
- // || hyperlink.Action.Value.StartsWith("ppaction://hlinkshowjump")))
- //{
- // linkType = "file";
- // slide.lazyFiles.Add(link);
- //}
- }
- return hyper;
- }
-
- public static Shape DoCustomGeometry(CustomGeometry shapeTypeCustom, Shape shape) {
- if (shapeTypeCustom != null)
- {
- var pathlist = shapeTypeCustom.GetFirstChild<PathList>();
- var path = pathlist.GetFirstChild<DocumentFormat.OpenXml.Drawing.Path>();
- var Width = 1.0;
- if (path.Width != null) {
- Width= shape.style.position.cx / path.Width.Value / 96.0 * 914400;
- }
- var Height = 1.0;
- if (path.Height != null) {
- Height = shape.style.position.cy / path.Height.Value / 96.0 * 914400;
- }
-
- var pathChildren = path.ChildElements;
- if (pathChildren != null)
- {
- var start = pathChildren.Where(x => x is MoveTo).FirstOrDefault();
- var close = pathChildren.Where(x => x is CloseShapePath).FirstOrDefault();
- var spX = 96.0;
- var spY = 96.0;
- if (start != null)
- {
- var point = start.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
- spX = double.Parse(point.X.Value) * Globals.px96 / Globals.px914400 * Width;
- spY = double.Parse(point.Y.Value) * Globals.px96 / Globals.px914400* Height;
- }
- var d = "M" + spX + "," + spY;
- foreach (var child in pathChildren)
- {
- if (child is LineTo lineTo)
- {
- var elm = lineTo.GetFirstChild<DocumentFormat.OpenXml.Drawing.Point>();
- if (elm != null)
- {
- var Lx = double.Parse(elm.X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Ly = double.Parse(elm.Y.Value) * Globals.px96 / Globals.px914400 * Height;
- d += " L" + Lx + "," + Ly;
- }
- }
- if (child is ArcTo arcTo)
- {
- var WidthRadius = arcTo.WidthRadius ;
- var HeightRadius = arcTo.HeightRadius ;
- var StartAngle = arcTo.StartAngle;
- var SwingAngle = arcTo.SwingAngle;
- var wR = double.Parse(WidthRadius.Value) * Globals.px96 / Globals.px914400 * Width;
- var hR = double.Parse(HeightRadius.Value) * Globals.px96 / Globals.px914400 * Height;
- var stAng = double.Parse(StartAngle.Value) * Globals.px96 / Globals.px914400;
- var swAng = double.Parse(SwingAngle.Value) * Globals.px96 / Globals.px914400;
- var endAng = stAng + swAng;
- d += SvgHelper.ShapeArc(wR, hR, wR, hR, stAng, endAng, false);
- }
- if (child is QuadraticBezierCurveTo quadraticBezierCurveTo)
- {
- var elms = quadraticBezierCurveTo.Elements<DocumentFormat.OpenXml.Drawing.Point>();
- if (elms != null)
- {
- var list = elms.ToList();
- var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
- }
- }
- if (child is CubicBezierCurveTo cubicBezierCurveTo)
- {
- var elms = cubicBezierCurveTo.Elements<DocumentFormat.OpenXml.Drawing.Point>();
- if (elms != null)
- {
- var list = elms.ToList();
- var Cx1 = double.Parse(list[0].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy1 = double.Parse(list[0].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- var Cx2 = double.Parse(list[1].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy2 = double.Parse(list[1].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- var Cx3 = double.Parse(list[2].X.Value) * Globals.px96 / Globals.px914400 * Width;
- var Cy3 = double.Parse(list[2].Y.Value) * Globals.px96 / Globals.px914400 * Height;
- d += " C" + Cx1 + "," + Cy1 + " " + Cx2 + "," + Cy2 + " " + Cx3 + "," + Cy3;
- }
- }
- }
- //是否关闭svg
- if (close != null)
- {
- d += " z";
- }
- d = d.Replace(",", " ");
- Svg shapes =
- new Svg {
- type = "path",
- // Fill = (!imgFillFlg ? (grndFillFlg ? "url(#linGrd_" + order + ")" : Fill.Color) : "url(#imgPtrn_" + order + ")"),
- //Stroke = "#" + shapeBorder.Color,
- //StrokeWidth = shapeBorder.Width + "",
- //StrokeDasharray = shapeBorder.Stroke,
- d=d,
- close = close!=null? true:false,
- start =shape.style.border.headEnd!=null?shape.style.border.headEnd:null,
- end=shape.style.border.tailEnd!=null?shape.style.border.tailEnd:null,
- };
- shape.svg = shapes;
- shape.shapeType = "custom";
- }
- }
- return shape;
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoBackground(DocumentFormat.OpenXml.Drawing.Diagrams.Background shapeProperties, PPTSlide slide, string partForm)
- {
- if (shapeProperties == null)
- {
- return null;
- }
-
- 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 effect = doEffect(EffectList, slide, partForm);
- 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, effect = effect };
- }
- public static Border DoWhole(DocumentFormat.OpenXml.Drawing.Diagrams.Whole shapeProperties, PPTSlide slide, string type, string partForm)
- {
- if (shapeProperties == null)
- {
- return null;
- }
- //Outline
- var lnNode = shapeProperties.GetFirstChild<Outline>();
- Border border = null;
- if (lnNode != null)
- {
- border = DoOutline(lnNode, slide, type);
- }
- //var EffectList = shapeProperties.GetFirstChild<EffectList>();
- //var effect = doEffect(EffectList, slide, partForm);
- //var EffectDag = shapeProperties.GetFirstChild<EffectDag>();
- //var Scene3DType = shapeProperties.GetFirstChild<Scene3DType>();
- //var Shape3DType = shapeProperties.GetFirstChild<Shape3DType>();
- //var ShapePropertiesExtensionList = shapeProperties.GetFirstChild<ShapePropertiesExtensionList>();
- return border;
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Office.Drawing.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
- {
- if (shapeProperties == null)
- {
- return null;
- }
- //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 effect = doEffect(EffectList, slide, partForm);
- 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, effect = effect };
- }
- public static HTEXLib.Models.HTEX.RunStyle DoRunProperties(TextCharacterPropertiesType shapeProperties, PPTSlide slide, string type, string partForm) {
- if (shapeProperties == null)
- {
- return null;
- }
- //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 effect = doEffect(EffectList, slide, partForm);
- 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.RunStyle { fill = fill, border = border,effect=effect };
- }
- public static HTEXLib.Models.HTEX.Effect doEffect(EffectList effectList, PPTSlide slide, string partForm) {
- if (effectList == null) {
- return null;
- }
- HTEXLib.Models.HTEX.Effect effect = new Models.HTEX.Effect();
- if (effectList.Blur != null) {
- effect.blur = new Models.HTEX.Blur
- {
- radius = effectList.Blur.Radius!=null? effectList.Blur.Radius.Value * 1.0 / Globals.px12700 : 0,
- grow = effectList.Blur.Grow!=null?effectList.Blur.Grow.Value:false
- };
- }
- if (effectList.FillOverlay != null)
- {
- Fill fill = DoFillOverlay(effectList.FillOverlay, slide, partForm);
- if (fill == null || fill.type == -1 || fill.type == 0) {
- fill = null;
- }
- effect.fillOverlay = new Models.HTEX.FillOverlay
- {
- fill = fill,
- blend = effectList.FillOverlay.Blend != null ? effectList.FillOverlay.Blend.Value.ToString() : null
- };
- }
- if (effectList.Glow != null)
- {
- string color = DoEffectColor(slide, effectList.Glow);
- effect.glow = new Models.HTEX.Glow
- {
- color = color,
- rad= effectList.Glow.Radius!=null?effectList.Glow.Radius.Value * 1.0 / Globals.px12700 : 0
- };
- }
- if (effectList.InnerShadow != null)
- {
- string color = DoEffectColor(slide, effectList.InnerShadow);
- effect.innerShadow = new Models.HTEX.InnerShadow
- {
- color = color,
- blurRad = effectList.InnerShadow.BlurRadius!=null?effectList.InnerShadow.BlurRadius.Value * 1.0 / Globals.px12700 : 0,
- dir= effectList.InnerShadow.Direction!=null?effectList.InnerShadow.Direction.Value* 1.0 / 60000 : 0,
- dist= effectList.InnerShadow.Distance!=null?effectList.InnerShadow.Distance.Value*1.0/Globals.px12700:0
- };
- }
- if (effectList.OuterShadow != null)
- {
- string color = DoEffectColor(slide, effectList.OuterShadow);
- effect.outerShadow = new Models.HTEX.OuterShadow
- {
- color = color,
- blurRad = effectList.OuterShadow.BlurRadius!=null? effectList.OuterShadow.BlurRadius.Value*1.0/ Globals.px12700 : 0,
- dir = effectList.OuterShadow.Direction!=null?effectList.OuterShadow.Direction.Value * 1.0 / 60000 : 0,
- dist = effectList.OuterShadow.Distance!=null?effectList.OuterShadow.Distance.Value * 1.0 / Globals.px12700 : 0,
- rotWithShape= effectList.OuterShadow.RotateWithShape!=null?effectList.OuterShadow.RotateWithShape.Value:true,
- algn= effectList.OuterShadow.Alignment!=null? effectList.OuterShadow.Alignment.Value.ToString():null,
- ky= effectList.OuterShadow.VerticalSkew!=null? effectList.OuterShadow.VerticalSkew.Value:0,
- sy = effectList.OuterShadow.VerticalRatio!=null? effectList.OuterShadow.VerticalRatio.Value:0,
- sx= effectList.OuterShadow.HorizontalRatio!=null? effectList.OuterShadow.HorizontalRatio.Value:0,
- kx= effectList.OuterShadow.HorizontalSkew!=null? effectList.OuterShadow.HorizontalSkew.Value:0,
- };
- }
- if (effectList.PresetShadow != null)
- {
- string color = DoEffectColor(slide, effectList.PresetShadow);
- effect.presetShadow = new Models.HTEX.PresetShadow
- {
- color = color,
- dir = effectList.PresetShadow.Direction!=null? effectList.PresetShadow.Direction.Value * 1.0 / 60000 : 0,
- dist = effectList.PresetShadow.Distance!=null?effectList.PresetShadow.Distance.Value * 1.0 / Globals.px12700 : 0,
- prst = effectList.PresetShadow.Preset!=null? effectList.PresetShadow.Preset.Value.ToString():null
- };
- }
- if (effectList.Reflection != null)
- {
- effect.reflection = new Models.HTEX.Reflection
- {
- dir = effectList.Reflection.Direction!=null ? effectList.Reflection.Direction.Value*1.0/ 60000 : 0,
- dist = effectList.Reflection.Distance!=null?effectList.Reflection.Distance.Value*1.0/Globals.px12700:0,
- blurRad = effectList.Reflection.BlurRadius!=null? effectList.Reflection.BlurRadius.Value * 1.0 / Globals.px12700 : 0,
- rotWithShape = effectList.Reflection.RotateWithShape!=null? effectList.Reflection.RotateWithShape.Value:true,
- algn = effectList.Reflection.Alignment!=null? effectList.Reflection.Alignment.Value.ToString():null,
- ky = effectList.Reflection.VerticalSkew!=null?effectList.Reflection.VerticalSkew.Value:0,
- sy = effectList.Reflection.VerticalRatio!=null? effectList.Reflection.VerticalRatio.Value:0,
- sx = effectList.Reflection.HorizontalRatio!=null? effectList.Reflection.HorizontalRatio.Value:0,
- kx = effectList.Reflection.HorizontalSkew!=null? effectList.Reflection.HorizontalSkew.Value:0,
- stA= effectList.Reflection.StartOpacity!=null?effectList.Reflection.StartOpacity.Value * 1.0 / 100000 : 1,
- stPos = effectList.Reflection.StartPosition!=null?effectList.Reflection.StartPosition.Value : 0,
- endA = effectList.Reflection.EndAlpha!=null?effectList.Reflection.EndAlpha.Value:0,
- endPos = effectList.Reflection.EndPosition!=null?effectList.Reflection.EndPosition.Value*1.0/100000:1,
- fadeDir = effectList.Reflection.FadeDirection!=null?effectList.Reflection.FadeDirection.Value:0,
- };
- }
- if (effectList.SoftEdge != null)
- {
- effect.softEdge = new Models.HTEX.SoftEdge
- {
- //12700
- rad = effectList.SoftEdge.Radius!=null? effectList.SoftEdge.Radius.Value*1.0/Globals.px12700:0,
- };
- }
- return effect;
- }
- private static string DoEffectColor(PPTSlide slide, PresetShadow FillReference)
- {
- string color = null;
- if (FillReference != 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);
- }
- }
- return color;
- }
- private static string DoEffectColor(PPTSlide slide, OuterShadow FillReference)
- {
- string color = null;
- if (FillReference != 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);
- }
- }
- return color;
- }
- private static string DoEffectColor(PPTSlide slide, InnerShadow FillReference)
- {
- string color = null;
- if (FillReference != 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);
- }
- }
- return color;
- }
- private static string DoEffectColor(PPTSlide slide, Glow FillReference)
- {
- string color = null;
- if (FillReference != 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);
- }
- }
- return color;
- }
- public static Fill DoFillOverlay(FillOverlay fillOverlay, PPTSlide slide, string partForm) {
- Fill fill = new Fill() { type = -1 };
- var gradFill = fillOverlay.GradientFill;
- if (gradFill != null)
- {
- fill.type = 2;
- fill.gradientFill = DoGradientFill(gradFill, slide);
- }
- var noFill = fillOverlay.NoFill;
- if (noFill != null)
- {
- fill.type = 0;
- }
- var pattFill = fillOverlay.PatternFill;
- if (pattFill != null)
- {
- HtexPattFill htexPattFill = DoPattFill(pattFill, slide);
- fill.type = 4;
- fill.pattFill = htexPattFill;
- }
- var solidFill = fillOverlay.SolidFill;
- if (solidFill != null)
- {
- fill.type = 1;
- fill.solidFill = DoSolidFill(solidFill, slide);
- }
- var groupFill = fillOverlay.GroupFill;
- if (groupFill != null)
- {
- fill.type = 5;
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var blipFill = fillOverlay.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 HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(DocumentFormat.OpenXml.Drawing.Charts.ShapeProperties shapeProperties, PPTSlide slide, string type, string partForm)
- {
- if (shapeProperties == null) {
- return null;
- }
- //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 effect = doEffect(EffectList, slide,partForm);
- 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, effect=effect };
- }
- public static HTEXLib.Models.HTEX.ShapeStyle DoShapeProperties(ChartShapeProperties shapeProperties, PPTSlide slide, string type, string partForm,ChartPart chartPart)
- {
- if (chartPart != null) {
- slide.chartPart = chartPart;
- }
- //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;
- partForm = "chartPart";
- fill.blipFill = DoBlipFill(blipFill, slide, partForm);
- // fill.solidFill = ReadSolidFillColors(new SolidFill(solidFill.ToString()), slide);
- }
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- Models.HTEX. Effect effect= doEffect(EffectList, slide, partForm);
- 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 ,effect= effect };
- }
- 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>();
- Models.HTEX.Effect effect = doEffect(EffectList, slide, partForm);
- 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 ,effect=effect};
- }
- public static (HTEXLib.Models.HTEX.ShapeStyle,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);
- }
-
- TableStyleType TableStyle = shapeProperties.GetFirstChild<TableStyle>();
- if (TableStyle == null)
- {
- var TableStyleId = shapeProperties.GetFirstChild<TableStyleId>();
- if (TableStyleId != null) {
- var TableStyleEntrys = slide.tableStylesPart.TableStyleList.Elements<TableStyleEntry>();
- foreach (var TableStyleEntry in TableStyleEntrys)
- {
- if (TableStyleEntry.StyleId == TableStyleId.InnerText)
- {
- TableStyle = TableStyleEntry;
- }
- }
- }
-
- }
- (TbStyle tbStyle,Fill fillbg) = DoTableStyle(TableStyle,slide,type,partForm);
- var shapeStyle = new HTEXLib.Models.HTEX.ShapeStyle() ;
- if (fill != null)
- {
- shapeStyle.fill = fill;
- }
- else {
- shapeStyle.fill = fillbg;
- }
- if (shapeStyle.fill.type == -1)
- {
- shapeStyle.fill = null;
- }
- //TODO
- var EffectList = shapeProperties.GetFirstChild<EffectList>();
- var effect= doEffect(EffectList, slide, partForm);
- 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;
- shapeStyle.effect = effect;
- return (shapeStyle,tbStyle);
- }
- public static (TbStyle, Fill) DoTableStyle(TableStyleType tableStyle, PPTSlide slide, string type, string partForm) {
- TbStyle tbStyle = new TbStyle();
- if (tableStyle == null) {
- return (tbStyle,null);
- }
- var TableBackground = tableStyle.TableBackground;
- Fill fill = null;
- if (TableBackground != null)
- {
- var shapeProperties = TableBackground.GetFirstChild<FillProperties>();
- fill = DoFillProperties(shapeProperties , partForm,slide );
- var FillReference = TableBackground.GetFirstChild<FillReference>();
- fill= DoFillReference(slide, fill, FillReference);
- if (fill.type == -1)
- {
- fill = null;
- }
- //TODO
- TableBackground.GetFirstChild<EffectPropertiesType>();
- string EffectColor = DoMatrixReferenceColors(TableBackground.GetFirstChild<EffectReference>(), slide);
- }
- //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,fill);
- }
- 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.LocalName};
- 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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 == 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;
- if (cellStyle.fill.type == -1)
- {
- cellStyle.fill = null;
- }
- //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;
- if (cellStyle.fill.type == -1)
- {
- cellStyle.fill = null;
- }
- 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 effect= doEffect(EffectList, slide, partForm);
- 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 ,effect= effect };
- }
- 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.GetPPTXNodeByPath("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.GetPPTXNodeByPath("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 (partForm == "chartPart") {
- part = slide.chartPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (partForm == "drawing")
- {
- part = slide.diagramDataPart.Parts.Where(x => x.RelationshipId == Embed).FirstOrDefault();
- }
- if (part != null) {
- var url= part.OpenXmlPart.Uri .ToString().Replace("../","/ppt/");
- var name = url.Replace("/", "");
- 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 = name;
- // 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.GetPPTXNodeByPath("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.GetPPTXNodeByPath("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 name = url.Replace("/", "");
- 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 = name;
- // 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},type="none" };
- //20.1.10.35 EMUs. 1 pt = 12700 EMUs.
- double? Width = null;
- if (outline == null && Shapetype== "CxnSp") {
- return new Border { outline =new HtexOutline { width=0.5} ,type= "solid",stroke="0" };
- }
- 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;
- }
- if (border.color != null && (border.color.type !=null || border.color.type !=1) && border.outline.width==null) {
- border.outline.width = 1;
- if (border.type == "none"|| border.type==null) {
- border.type = "solid";
- border.stroke = "0";
- }
- }
- return border;
- }
- /// <summary>
- ///自定义连线符
- /// </summary>
- /// <param name="custDash"></param>
- /// <returns></returns>
- public static (string type, string stroke) DoCustDash(CustomDash custDash) {
- string type = "cust";
- string stroke = "0";
- IEnumerable<XElement> elements= custDash.GetPPTXNodeListByPath("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() { type= "solid",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 (border.type, border.stroke);
- }
- public static HtexPattFill DoPattFill(DocumentFormat.OpenXml.Drawing.PatternFill patternFill , PPTSlide slide) {
- HtexPattFill htexPattFill = new HtexPattFill();
- Color FgClr = Color.Empty;
- Color BgClr = Color.Empty;
- if (patternFill.ForegroundColor != null)
- {
- var fgClr = ColorTypeColors(patternFill.ForegroundColor, slide);
- htexPattFill.fgClr = fgClr;
- FgClr= ColorTranslator.FromHtml(fgClr);
- }
- if (patternFill.BackgroundColor != null)
- {
- var bgClr = ColorTypeColors(patternFill.BackgroundColor, slide);
- htexPattFill.bgClr = bgClr;
- BgClr= ColorTranslator.FromHtml(bgClr);
- }
- htexPattFill.prst = patternFill.Preset.ToString();
- MemoryStream ms = new MemoryStream();
- System.Drawing.Bitmap bm = PatternFillHelper.GetVmlPatternFill(patternFill.Preset, FgClr, BgClr);
- Graphics graphics = Graphics.FromImage(bm);
- graphics.Save();
- graphics.Dispose();
- bm.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- byte[] arr = new byte[ms.Length];
- ms.Position = 0;
- ms.Read(arr, 0, (int)ms.Length);
- ms.Close();
- bm.Dispose();
- string sImageData = "data:image/png;base64,"+ Convert.ToBase64String(arr);
- htexPattFill.base64 = sImageData;
- 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.GetPPTXNodeByPath("//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);
- }
- if (scaledNode != null) {
- scaled = scaledNode.Value;
- }
- gradientFill.line = new LineFill { rot = rot, scaled = scaled };
- }
- var path = GradientFill.GetPPTXNodeByPath("//a:path");
- if (path != null) {
- type = "path";
- ///circle
- ///rect
- ///shape
- var pathType= path.Attribute("path").Value;
- var fillToRect=path.GetPPTXNodeByPath("//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.path =new PathFill {fillToRect= vector,pathType= pathType } ;
- }
- }
- var tileRect = GradientFill.GetPPTXNodeByPath("//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("#", "")).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("#", "")).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("#", "")).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("#", "")).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("#", "")).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("#", "")).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")
- {
- if (cl.GetFirstChild<SystemColor>() != null)
- {
- FontColor = "#" + cl.GetFirstChild<SystemColor>().LastColor;
- }
- else {
- FontColor = "#" + cl.GetFirstChild<RgbColorModelHex>().Val.Value; ;
- }
-
- }
- 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;
- }
-
- }
- }
|