Browse Source

添加图片处理

黄贺彬 5 years ago
parent
commit
d871e06ed0
1 changed files with 128 additions and 2 deletions
  1. 128 2
      TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeGenerator.cs

+ 128 - 2
TEAMModelOS.Service/Services/PowerPoint/Implement/ShapeGenerator.cs

@@ -352,9 +352,133 @@ namespace HiTeachCC.Service.PowerPoint.Implement
             throw new NotImplementedException();
         }
 
-        private string ProcessPicNode(XmlNode nodeValue, WarpObj warpObj)
+        private string ProcessPicNode(XmlNode node , WarpObj warpObj)
         {
-            throw new NotImplementedException();
+
+            var rtrnData = "";
+            var mediaPicFlag = false;
+            var order = node.GetTextByPath("@order");
+
+            var rid = node.GetTextByPath("p:blipFill/a:blip/@r:embed");
+            var imgName = warpObj.slideResObj[rid.Value]["target"];
+            // var imgFileExt = extractFileExtension(imgName).toLowerCase();
+            //var zip = warpObj["zip"];
+         
+            var imgData = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + imgName+ "']");
+            var imgFileExt = imgData.GetTextByPath("@pkg:contentType").Value;
+            var imgArrayBuffer = imgData.InnerText;
+            var mimeType = "";
+            var xfrmNode = node.GetTextByPath("p:spPr/a:xfrm");
+            ///////////////////////////////////////Amir//////////////////////////////
+            double rotate = 0;
+            var rotateNode = node.GetTextByPath("p:spPr/a:xfrm/@rot");
+            if (rotateNode !=  null)
+            {
+                rotate = AngleToDegrees(rotateNode);
+            }
+            //video
+            var vdoNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:videoFile");
+            XmlNode vdoRid,    vdoMimeType, uInt8Array, blob, vdoBlob;
+            string vdoFile , vdoFileExt;
+             bool mediaSupportFlag = false;
+        //    var mediaProcess = settings.mediaProcess;
+            if (vdoNode != null)
+            {
+                vdoRid = vdoNode.GetTextByPath("@r:link");
+                vdoFile = warpObj.slideResObj[vdoRid.Value]["target"];
+                uInt8Array = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + vdoFile + "']");
+                vdoFileExt = uInt8Array.GetTextByPath("@pkg:contentType").Value; 
+                if (vdoFileExt == "mp4" || vdoFileExt == "webm" || vdoFileExt == "ogg")
+                {
+
+                    ///  处理为AzureBlob 上传
+                   // vdoMimeType = getMimeType(vdoFileExt);
+                   // blob = new Blob([uInt8Array], {
+                   // type: vdoMimeType
+                   // });
+                   // vdoBlob = URL.createObjectURL(blob);
+                    mediaSupportFlag = true;
+                    mediaPicFlag = true;
+                }
+            }
+            //Audio
+            var audioNode = node.GetTextByPath("p:nvPicPr/p:nvPr/a:audioFile");
+            XmlNode audioRid, audioMimeType, uInt8ArrayAudio, blobAudio, audioBlob;
+
+            string audioFile, audioFileExt;
+            var audioPlayerFlag = false;
+          //  var audioObjc;
+            if (audioNode !=null )
+            {
+                audioRid = audioNode.GetTextByPath("@r:link");
+                audioFile = warpObj.slideResObj[audioRid.Value]["target"];
+                uInt8ArrayAudio = warpObj.zip.GetTextByPath("//pkg:part[@pkg:name='" + audioFile + "']");
+                  audioFileExt = uInt8ArrayAudio.GetTextByPath("@pkg:contentType").Value;
+                if (audioFileExt == "mp3" || audioFileExt == "wav" || audioFileExt == "ogg")
+                {
+                    //uInt8ArrayAudio = zip.file(audioFile).asArrayBuffer();
+                    //blobAudio = new Blob([uInt8ArrayAudio]);
+                    //audioBlob = URL.createObjectURL(blobAudio);
+                    //var cx = parseInt(xfrmNode["a:ext"]["attrs"]["cx"]) * 20;
+                    //var cy = xfrmNode["a:ext"]["attrs"]["cy"];
+                    //var x = parseInt(xfrmNode["a:off"]["attrs"]["x"]) / 2.5;
+                    //var y = xfrmNode["a:off"]["attrs"]["y"];
+                    //audioObjc = {
+                    //    "a:ext" : {
+                    //        "attrs":{
+                    //            "cx":cx,
+                    //            "cy":cy
+                    //        }
+                    //    },
+                    //    "a:off":{
+                    //        "attrs":{
+                    //            "x":x,
+                    //            "y":y
+
+                    //        }
+                    //    }
+                    //}
+                    audioPlayerFlag = true;
+                    mediaSupportFlag = true;
+                    mediaPicFlag = true;
+                }
+            }
+            //console.log(node)
+            //////////////////////////////////////////////////////////////////////////
+            mimeType =  imgFileExt ;
+            //rtrnData = "<div class='block content' style='" +
+            //         (( audioPlayerFlag) ? GetPosition(audioObjc, null, null) : GetPosition(xfrmNode, null, null)) +
+            //        ((    audioPlayerFlag) ? GetSize(audioObjc, null, null) :GetSize(xfrmNode, null, null)) +
+            //        " z-index: " + order + ";" +
+            //        "transform: rotate(" + rotate + "deg);'>";
+            //if ((vdoNode ==null && audioNode ==null)  || !mediaSupportFlag)
+            //{
+            //    rtrnData += "<img src='data:" + mimeType + ";base64," + base64ArrayBuffer(imgArrayBuffer) + "' style='width: 100%; height: 100%'/>";
+            //}
+            //else if ((vdoNode !=null || audioNode !=null)  && mediaSupportFlag)
+            //{
+            //    if (vdoNode !=null)
+            //    {
+            //        rtrnData += "<video  src='" + vdoBlob + "' controls style='width: 100%; height: 100%'>Your browser does not support the video tag.</video>";
+            //    }
+            //    if (audioNode !=null)
+            //    {
+            //        rtrnData += "<audio id='audio_player' controls ><source src='" + audioBlob + "'></audio>";
+            //    }
+            //}
+            if (!mediaSupportFlag && mediaPicFlag)
+            {
+                rtrnData += "<span style='color:red;font-size:40px;position: absolute;'>This media file Not supported by HTML5</span>";
+            }
+            if ((vdoNode !=null || audioNode !=null)  && mediaSupportFlag)
+            {
+                //console.log("Founded supported media file but media process disabled (mediaProcess=false)");
+            }
+            rtrnData += "</div>";
+            //console.log(rtrnData)
+            return rtrnData;
+
+            //throw new NotImplementedException();
         }
 
         private string ProcessCxnSpNode(XmlNode nodeValue, WarpObj warpObj)
@@ -795,6 +919,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                 fill.SvgText = "node";
                 fill.Type = 0;
                 fill.HtmlText = "background-color: initial;";
+                return fill;
                 //return isSvgMode ? "none" : "background-color: initial;";
             }
             else if (fillType == "SOLID_FILL")
@@ -873,6 +998,7 @@ namespace HiTeachCC.Service.PowerPoint.Implement
                 }
                 else
                 {
+                    Console.WriteLine("#"+fill.Color);
                     //if (isSvgMode)
                     //{
                     //   var color = new colz.Color(fill);