Explorar el Código

【+】
1.删减部分重复代码

lxd hace 2 meses
padre
commit
24c43b4953

+ 1 - 1
Framework/SimulationToolDev/AnimationDriver/AnimationManager.cs

@@ -170,7 +170,7 @@ namespace ChivaXR
                     if ((aniDriver as AniDriver_MoveByPath) != null)
                     {
                         (aniDriver as AniDriver_MoveByPath).duration =2f;
-                        Debug.Log(item.AniDataName + "设置成功");
+                         Debug.Log(item.AniDataName + "设置成功");
                     }else
                     {
                         Debug.Log(item.AniDataName +"转换为空");

+ 11 - 17
Framework/Toolkits/PDFkit/HeaderFooter1.cs

@@ -9,25 +9,21 @@ using Image = iTextSharp.text.Image;
 
 public class HeaderFooter1 : PdfPageEventHelper
 {
-    private PdfTemplate total;
+    private PdfTemplate totalPdfTemplate;
     private BaseFont baseFont;
-    private PdfFont headFont;
     private Image headLogo;
     public override void OnOpenDocument(PdfWriter writer, Document document)
     {
         baseFont = BaseFont.CreateFont(Application.streamingAssetsPath + "/Fonts/成绩字体.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
         headLogo = Image.GetInstance(Application.streamingAssetsPath + "/Logos/成绩logo.png");
 
-        headFont = new PdfFont(baseFont, 10, PdfFont.NORMAL, new BaseColor(128, 128, 128));
-
-        total = writer.DirectContent.CreateTemplate(100, 100);
+        totalPdfTemplate = writer.DirectContent.CreateTemplate(100, 100);
     }
 
     public override void OnEndPage(PdfWriter writer, Document document)
     {
         //添加页眉
         AddHeader(writer,document);
-
         //添加页脚
         AddFooter(writer, document);
     }
@@ -35,11 +31,11 @@ public class HeaderFooter1 : PdfPageEventHelper
     public override void OnCloseDocument(PdfWriter writer, Document document)
     {
         // 在文档关闭时设置总页数
-        total.BeginText();
-        total.SetFontAndSize(baseFont, 10);
-        total.SetTextMatrix(0, 0);
-        total.ShowText((writer.PageNumber).ToString() + " 页");
-        total.EndText();
+        totalPdfTemplate.BeginText();
+        totalPdfTemplate.SetFontAndSize(baseFont, 10);
+        totalPdfTemplate.SetTextMatrix(0, 0);
+        totalPdfTemplate.ShowText((writer.PageNumber).ToString() + " 页");
+        totalPdfTemplate.EndText();
     }
 
     private void AddHeader(PdfWriter writer, Document document)
@@ -89,15 +85,13 @@ public class HeaderFooter1 : PdfPageEventHelper
         PdfContentByte cb = writer.DirectContent;
         cb.SaveState();
         cb.SetColorFill(new BaseColor(128, 128, 128));
+        
         //页脚分隔线
-        float footY = document.Bottom;
-        cb.MoveTo(document.BottomMargin, footY);
-        cb.LineTo(document.PageSize.Width - document.RightMargin, footY);
+        cb.MoveTo(document.BottomMargin, document.Bottom);
+        cb.LineTo(document.PageSize.Width - document.RightMargin, document.Bottom);
         cb.Stroke();
 
-
         string text1 = $"虚拟仿真实验考核系统 @2025";
-        float textSize1 = baseFont.GetWidthPoint(text1, 10);
         float x1 = document.LeftMargin;
         float y1 = document.BottomMargin - 15;
 
@@ -121,7 +115,7 @@ public class HeaderFooter1 : PdfPageEventHelper
         cb.EndText();
 
         // 添加总页数占位符
-        cb.AddTemplate(total, x2 + textSize2 / 2 - baseFont.GetWidthPoint(" ", 10), y2);
+        cb.AddTemplate(totalPdfTemplate, x2 + textSize2 / 2 - baseFont.GetWidthPoint(" ", 10), y2);
 
         cb.RestoreState();
     }

+ 3 - 272
OperationUIFrame/OperationUIFrameV2/Scripts/UI/PC_OperatePanel/ScoreInfo.cs

@@ -96,7 +96,6 @@ namespace QFramework
             }
 
             BaseFont bfChinese = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
-            PdfFont smallFont = new PdfFont(bfChinese, 10) { Color = new BaseColor(100, 100, 100) }; // 灰色
             PdfFont normalFont = new PdfFont(bfChinese, 12);
             PdfFont boldFont = new PdfFont(bfChinese, 12, PdfFont.BOLD);
             PdfFont titleFont = new PdfFont(bfChinese, 25, PdfFont.BOLD);
@@ -146,7 +145,7 @@ namespace QFramework
                 // ===== 操作步骤表格 =====
                 PdfPTable stepTable = new PdfPTable(3);
                 stepTable.WidthPercentage = 100;
-                stepTable.SetWidths(new float[] { 1f, 3f, 1f });
+                stepTable.SetWidths(new float[] { 1f, 5f, 1f });
 
                 AddHeaderCell(stepTable, "序号", boldFont);
                 AddHeaderCell(stepTable, "操作步骤", boldFont);
@@ -202,6 +201,7 @@ namespace QFramework
             PdfPCell cell = new PdfPCell(new Phrase(text, font));
             cell.BackgroundColor = new BaseColor(220, 220, 220);
             cell.HorizontalAlignment = Element.ALIGN_CENTER;
+            cell.VerticalAlignment = Element.ALIGN_MIDDLE;
             cell.MinimumHeight = 25;
             table.AddCell(cell);
         }
@@ -209,126 +209,13 @@ namespace QFramework
         private  void AddCell(PdfPTable table, string text, PdfFont font, BaseColor bg = null)
         {
             PdfPCell cell = new PdfPCell(new Phrase(text, font));
+            cell.MinimumHeight = 22;
             cell.HorizontalAlignment = Element.ALIGN_CENTER;
             cell.VerticalAlignment = Element.ALIGN_MIDDLE;
-            cell.MinimumHeight = 22;
             if (bg != null) cell.BackgroundColor = bg;
             table.AddCell(cell);
         }
 
-        // ===== 页脚页码事件类 =====
-        private class PdfPageEvents : PdfPageEventHelper
-        {
-            private PdfTemplate totalPages;
-            private BaseFont baseFont;
-            private PdfFont pdfFont;
-            public override void OnOpenDocument(PdfWriter writer, Document document)
-            {
-                string fontPath = Path.Combine(Application.streamingAssetsPath, "Fonts/成绩字体.ttf");
-
-                baseFont = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
-                pdfFont = new PdfFont(baseFont,10);
-
-                totalPages = writer.DirectContent.CreateTemplate(100, 100);
-            }
-
-            public override void OnEndPage(PdfWriter writer, Document document)
-            {
-                base.OnEndPage(writer, document);
-
-                // 添加页眉
-                //AddHeader(writer, document);
-
-                // 添加页脚
-                AddFooter(writer, document);
-            }
-
-            private void AddHeader(PdfWriter writer, Document document)
-            {
-                PdfPTable headerTable = new PdfPTable(2);
-                headerTable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
-                headerTable.SetWidths(new float[] { 1, 4 });
-             
-                // 图片单元格
-                string logoPath = Path.Combine(Application.streamingAssetsPath, "Logos", "成绩logo.png");
-                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(logoPath);
-                
-
-                float targetHeight = 2f;
-                //设定统一显示宽度                                          
-                float scaleFactor = targetHeight / logo.Height; // 缩放比例                                           
-                //logo.ScalePercent(scaleFactor); // iTextSharp 用百分比
-                logo.ScaleToFit(2, 1);
-
-                PdfPCell imageCell = new PdfPCell(logo, true);
-                imageCell.Border = Rectangle.NO_BORDER;
-                imageCell.HorizontalAlignment = Element.ALIGN_LEFT;
-
-                // 文本单元格
-                PdfPCell cell = new PdfPCell(new Phrase("虚拟仿真实验中心", pdfFont));
-                cell.Border = Rectangle.BOTTOM_BORDER;
-                cell.BorderColor = BaseColor.GRAY;
-                cell.BorderWidth = 1f;
-                cell.PaddingBottom = 5f;
-                cell.HorizontalAlignment = Element.ALIGN_CENTER;
-
-                PdfPCell cell1 = new PdfPCell(new Phrase("", pdfFont));
-                cell1.Border = Rectangle.BOTTOM_BORDER;
-                cell1.BorderColor = BaseColor.GRAY;
-                cell1.BorderWidth = 1f;
-                cell1.PaddingBottom = 5f;
-                cell1.HorizontalAlignment = Element.ALIGN_RIGHT;
-
-                headerTable.AddCell(imageCell);
-                headerTable.AddCell(cell);
-                headerTable.AddCell(cell1);
-                headerTable.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - document.TopMargin + 2,
-                                             writer.DirectContent);
-            }
-
-            private void AddFooter(PdfWriter writer, Document document)
-            {
-                PdfPTable footerTable = new PdfPTable(2);
-                footerTable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
-
-                // 左侧文本
-                PdfPCell leftCell = new PdfPCell(new Phrase("虚拟仿真实验考核系统 © 2025", pdfFont));
-                leftCell.Border = Rectangle.TOP_BORDER;
-                leftCell.BorderColor = BaseColor.GRAY;
-                leftCell.HorizontalAlignment = Element.ALIGN_LEFT;
-
-                // 居中页码
-                string pageText = $"第 {writer.PageNumber} 页";
-                PdfPCell centerCell = new PdfPCell(new Phrase(pageText, pdfFont));
-                centerCell.Border = Rectangle.TOP_BORDER;
-                centerCell.BorderColor = BaseColor.GRAY;
-                centerCell.HorizontalAlignment = Element.ALIGN_RIGHT;
-
-                // 右侧总页数
-                //PdfPCell rightCell = new PdfPCell(new Phrase("总页数:", pdfFont));
-                //rightCell.Border = Rectangle.TOP_BORDER;
-                //rightCell.BorderColor = BaseColor.GRAY;
-                //rightCell.HorizontalAlignment = Element.ALIGN_RIGHT;
-
-                footerTable.AddCell(leftCell);
-                footerTable.AddCell(centerCell);
-                //footerTable.AddCell(rightCell);
-
-                footerTable.WriteSelectedRows(0, -1, document.LeftMargin, document.BottomMargin - 10,
-                                             writer.DirectContent);
-            }
-
-            public override void OnCloseDocument(PdfWriter writer, Document document)
-            {
-                base.OnCloseDocument(writer, document);
-
-                // 在文档关闭时写入总页数
-                //ColumnText.ShowTextAligned(totalPages, Element.ALIGN_LEFT,
-                //    new Phrase((writer.PageNumber - 1).ToString(), pdfFont),
-                //    2, 2, 0);
-            }
-        }
-
         /// <summary>
         /// 检查成绩数量
         /// </summary>
@@ -359,161 +246,5 @@ namespace QFramework
                 File.Delete(filePaths[0]);
             }
         }
-
-        private void Temp()
-        {
-            //Document doc = new Document(PageSize.A4, 60, 60, 80, 60); //上边距略大,留页眉空间
-            //PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(tmpSavePath, FileMode.CreateNew));
-
-            //// ===== 页脚和页码 =====
-            //writer.PageEvent = new PdfPageEvents();
-
-            //doc.Open();
-
-            //// ====== 字体设置 ======
-            //string fontPath = Path.Combine(Application.streamingAssetsPath, "Fonts/成绩字体.ttf");
-            //if (!File.Exists(fontPath))
-            //{
-            //    Debug.LogError("字体文件未找到:" + fontPath);
-            //    return;
-            //}
-
-            //BaseFont bfChinese = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
-            //PdfFont smallFont = new PdfFont(bfChinese, 10) { Color = new BaseColor(100, 100, 100) }; // 灰色
-            //PdfFont normalFont = new PdfFont(bfChinese, 12);
-            //PdfFont boldFont = new PdfFont(bfChinese, 12, PdfFont.BOLD);
-            //PdfFont titleFont = new PdfFont(bfChinese, 30, PdfFont.BOLD);
-
-            //PdfContentByte cb = writer.DirectContent;
-
-            ////===== 横线 =====
-            //float lineY = doc.Top - 20f;
-            //cb.MoveTo(doc.Left, lineY);
-            //cb.LineTo(doc.Right, lineY);
-            //cb.Stroke();
-
-            ////===== 页眉在横线之上 =====
-            //string headerText = "虚拟仿真实验中心";
-            //ColumnText.ShowTextAligned(
-            //    cb,
-            //    Element.ALIGN_CENTER,
-            //    new Phrase(headerText, smallFont),
-            //    (doc.Left + doc.Right) / 2,
-            //    lineY + 10,  // 横线上方 10pt
-            //    0
-            //);
-
-            //// ===== LOGO 横线上方左侧 =====
-            //string logoPath = Path.Combine(Application.streamingAssetsPath, "Logos", "成绩logo.png");
-
-            //// 统一去除 URL 前缀(特别是 file://)
-            //if (logoPath.StartsWith("file://"))
-            //    logoPath = logoPath.Replace("file://", "");
-
-            //if (!File.Exists(logoPath))
-            //{
-            //    // Unity Editor 下 StreamingAssets 在项目路径内
-            //    logoPath = Path.Combine(Application.streamingAssetsPath, "Logos", "成绩logo.png");
-            //}
-            //float logoBottomY = lineY; // 用于计算标题位置
-            //if (File.Exists(logoPath))
-            //{
-            //    try
-            //    {
-            //        byte[] logoBytes = File.ReadAllBytes(logoPath);
-            //        iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(logoBytes);
-
-            //        // 👉 只固定高度,让宽度按比例缩放
-            //        float targetHeight = 50f;  // 设定统一显示宽度
-            //        float scaleFactor = targetHeight / logo.Height; // 缩放比例
-            //        logo.ScalePercent(scaleFactor * 100); // iTextSharp 用百分比
-
-            //        // 保证顶部距离横线 5pt
-            //        float logoTopY = lineY + 5f + logo.ScaledHeight;
-            //        float logoPosY = logoTopY - logo.ScaledHeight;
-            //        logoBottomY = logoPosY;
-
-            //        // 让左下角对齐页边距
-            //        logo.SetAbsolutePosition(doc.Left, logoPosY);
-            //        doc.Add(logo);
-
-            //        Debug.Log($"✅ Logo 添加成功(原始大小: {logo.Width}x{logo.Height}, 缩放比例: {scaleFactor:F2})");
-            //    }
-            //    catch (System.Exception e)
-            //    {
-            //        Debug.LogError("❌ 读取 Logo 出错:" + e.Message);
-            //    }
-            //}
-            //else
-            //{
-            //    Debug.LogWarning("⚠️ 未找到 Logo 文件:" + logoPath);
-            //}
-
-            //// ===== 主标题(单独一行居中) =====
-            //Paragraph title = new Paragraph("成 绩 单", titleFont);
-            //title.Alignment = Element.ALIGN_CENTER;
-            //title.SpacingBefore = 30f;
-            //title.SpacingAfter = 20f;
-            //doc.Add(title);
-
-            //// ===== 基本信息表格 =====
-            //PdfPTable infoTable = new PdfPTable(4);
-            //infoTable.WidthPercentage = 100;
-            //infoTable.SpacingBefore = 10f;
-            //infoTable.SpacingAfter = 15f;
-            //infoTable.SetWidths(new float[] { 1.2f, 2f, 1.2f, 2f });
-
-            //AddCell(infoTable, "姓名", boldFont, new BaseColor(235, 235, 235));
-            //AddCell(infoTable, tmpUserProxy.userInfo.userName, normalFont);
-            //AddCell(infoTable, "实验日期", boldFont, new BaseColor(235, 235, 235));
-            //AddCell(infoTable, DateTime.Now.ToString("yyyy年MM月dd日HH时"), normalFont);
-
-            //AddCell(infoTable, "实验名称", boldFont, new BaseColor(235, 235, 235));
-            //AddCell(infoTable, OperateSetting.Instance.m_CourseName, normalFont);
-            //AddCell(infoTable, "总成绩", boldFont, new BaseColor(235, 235, 235));
-            //AddCell(infoTable, float.Parse(scorePanel.Score.text).ToString("F1") + " 分", normalFont);
-
-            //AddCell(infoTable, "用时", boldFont, new BaseColor(235, 235, 235));
-            //AddCell(infoTable, scorePanel.UseTime.text, normalFont);
-            //AddCell(infoTable, "", normalFont);
-            //AddCell(infoTable, "", normalFont);
-
-            //doc.Add(infoTable);
-
-            //// ===== 操作步骤表格 =====
-            //PdfPTable stepTable = new PdfPTable(3);
-            //stepTable.WidthPercentage = 100;
-            //stepTable.SetWidths(new float[] { 1f, 3f, 1f });
-
-            //AddHeaderCell(stepTable, "序号", boldFont);
-            //AddHeaderCell(stepTable, "操作步骤", boldFont);
-            //AddHeaderCell(stepTable, "分数", boldFont);
-
-            //foreach (var examInfo in tmpExamProxy.examScoreInfos)
-            //{
-            //    AddCell(stepTable, examInfo.id.ToString(), normalFont);
-            //    AddCell(stepTable, examInfo.stepName, normalFont);
-
-            //    string score = examInfo.score < 0 ? "0" : examInfo.score.ToString("F1");
-
-            //    AddCell(stepTable, score.ToString(), normalFont);
-            //}
-
-            //doc.Add(stepTable);
-
-            //// ===== 评语 =====
-            //doc.Add(new Paragraph("\n"));
-            //string commentText = GenerateComment(float.Parse(scorePanel.Score.text));
-            //Paragraph comment = new Paragraph($"评语:{commentText}", normalFont);
-            //comment.SpacingBefore = 10;
-            //doc.Add(comment);
-
-            //doc.Close();
-            //writer.Close();
-            //Debug.Log($"✅ 成绩单导出成功:{tmpSavePath}");
-
-            //CheckGradeCount(tmpSelectSavePath, 20, "*成绩单.pdf");
-        }
-
     }
 }