เมธอด THotPDF.RepairPDFUA2Structure

ซ่อม defect ด้าน namespace attribute โครงสร้าง และการเข้าถึงของ PDF/UA-2 ที่ยังกู้คืนได้ ภายใน graph transaction แบบ copy-on-write และ validate candidate graph ก่อน commit

การประกาศ

function RepairPDFUA2Structure(
  const Options: THPDFUA2RepairOptions;
  out Report: THPDFUA2RepairReport;
  out Issues: THPDFUA2ValidationIssues): boolean; overload;

function RepairPDFUA2Structure(
  const Options: THPDFUA2RepairOptions;
  out Report: THPDFUA2RepairReport;
  out Issues: THPDFUA2ValidationIssues;
  out Findings: THPDFComplianceFindings): boolean; overload;

ยูนิต

HPDFDoc

ตัวเลือกการ repair

เริ่มจาก THPDFUA2RepairOptions.Default แล้ว override เฉพาะการตัดสินใจเชิงนโยบายที่ workflow ของ input ต้องการ

ฟิลด์หน้าที่
NormalizeDuplicateNamespacesสร้าง StructTreeRoot/Namespaces ใหม่ให้มี indirect dictionary แบบ canonical หนึ่งตัวต่อ URI และปฏิเสธ role map ที่ขัดแย้งกัน
RegisterReferencedNamespacesลงทะเบียน namespace dictionary ที่ถูกต้องซึ่ง structure element attribute หรือ role map ที่รู้เรื่อง namespace อ้างถึง
RepairStandardStructureNamespacesกำหนด namespace ของ PDF 2.0 ให้ role มาตรฐานเมื่อ namespace หายไปหรือใช้ไม่ได้ และ normalize Document ระดับบนสุดเสมอ
RepairAttributeNamespacesทำให้การอ้างอิง namespace ของ attribute เป็น canonical และลบรายการ namespace ที่ใช้ไม่ได้ออกจาก owner มาตรฐาน
RepairAttributeRevisionsnormalize เลข revision ที่ติดลบหรือเป็นเศษส่วน และลบรายการ revision ที่กำพร้าออกจาก attribute array
RepairListSemanticsnormalize การนับเลข flag การต่อเนื่อง ชนิด continuation ที่ใช้ไม่ได้ และ caption ที่หลุดตำแหน่งหนึ่งตัว โดยไม่สร้างเนื้อหา list ขึ้นเอง
RepairTableSemanticsnormalize span และ scope ที่ใช้ไม่ได้ ลบการอ้างอิง header ระดับตารางที่ใช้ไม่ได้ และย้าย caption ที่หลุดตำแหน่งหนึ่งตัว
RepairRubyWarichuSequencesจัดลำดับ children ใหม่เฉพาะเมื่อ role multiset ที่ต้องการเป๊ะ ๆ มีอยู่แล้ว
RepairPronunciationHintsลบ hint ที่ type ผิด ตัดการอ้างอิง lexicon ที่ใช้ไม่ได้ และ normalize MIME subtype ของ PLS ที่ฝังอยู่
RepairMissingAlternateTextคืน Alt ที่หายไปของ Figure, Formula และ Form จาก title ที่มีอยู่ expansion text ข้อความที่ extract จาก MCID เดียวกัน หรือ fallback ที่ระบุชัด ตามลำดับนี้
RepairLanguageInheritanceยกระดับภาษา default ที่ถูกต้องจาก structure root หรือที่ระบุชัด ขึ้นไปไว้ที่ Catalog และลบรายการภาษาระดับ structure ที่ใช้ไม่ได้หรือซ้ำซ้อน เมื่อการ inherit ไม่กำกวม
RepairHeadingOrderรันเลขใหม่เฉพาะ defect แบบ first-heading และข้ามระดับ พร้อมคงลำดับเอกสารไว้
RepairArtifactTaggingเขียน tag marked-content ที่ผูกกับ structure element ประเภท Artifact ให้ครอบคลุมทั้งเนื้อหาฝั่ง producer และหน้าที่โหลดแล้ว
AllowDocumentFragmentHeadingStartsรีเซ็ตบริบท heading ภายใน DocumentFragment แต่ละชิ้น สำหรับทั้งการ repair และ validation หลังซ่อม
RollbackOnValidationFailureคืน graph เดิมเมื่อยังมี error ของ PDF/UA-2 เหลืออยู่หลังซ่อม
CustomAttributeNamespaceURIระบุ namespace แบบชัดเจนให้ owner ของ attribute เฉพาะทางที่อนุมาน semantics ได้ไม่ปลอดภัย โดยค่า default ว่างจะ fail closed
DefaultLanguageระบุ language tag แบบ BCP-47 เฉพาะเมื่อทั้ง Catalog และ structure root ไม่มีภาษาที่ถูกต้อง
FallbackAlternateTextรับ alternate text ที่ผู้เรียกตรวจแล้ว หลังแหล่งที่มาจากเอกสารทั้งหมดล้มเหลว โดยค่า default ว่างจะไม่แต่งคำอธิบายขึ้นเองเด็ดขาด
MaxGeneratedAlternateTextCharactersจำกัดการ extract ข้อความจาก MCID เดียวกัน โดย default ที่ 4,096 UTF-16 code unit
MaxObjectsจำกัดการสแกน object graph โดย default ที่ 1,000,000 object
MaxRepairsจำกัด mutation ที่เก็บไว้ โดย default ที่ 100,000 operation

รายงานการ repair

THPDFUA2RepairReport รายงานว่า graph เปลี่ยนหรือถูก rollback หรือไม่ มีค่าใดเกินขอบเขตหรือไม่ สถานะ validation หลังซ่อม จำนวน object ที่ตรวจ error ที่เหลืออยู่ และตัวนับของทุกตระกูลการซ่อม รวมถึง alternate text รายการภาษา ระดับ heading และ tag Artifact

UnresolvedAlternateTextCount, UnresolvedLanguageCount และ UnresolvedArtifactCount แยก semantics ที่ยังต้องให้ผู้เขียนตรวจ ออกจากการแก้ไขอัตโนมัติ

array THPDFUA2ValidationIssues ที่คืนกลับจะมี diagnostics หลังการซ่อมเมื่อ validation ไม่ผ่าน และมี diagnostics เฉพาะของ repair ที่นิ่ง เมื่อ transaction ถูกยุติเพราะ resource bound หรือ role map ซ้ำที่ขัดแย้งกัน

overload แบบละเอียดยังคืน findings ก่อนซ่อมที่ระบุ annotation เป็น crsApplied, crsUnresolved, crsRolledBack หรือ crsFailed พร้อมสรุปพร้อมตัวนับของแต่ละตระกูลการซ่อม

overload provenance นี้รัน validation pass ก่อนซ่อมเพิ่มอีกรอบแบบมีขอบเขต ถ้าต้องการแค่รายงานสุดท้ายกับ issues ให้ใช้ overload สาม output เดิม

ความเป็น atomic และความปลอดภัย

ตัวอย่าง

var
  Options: THPDFUA2RepairOptions;
  Report: THPDFUA2RepairReport;
  Issues: THPDFUA2ValidationIssues;
begin
  Options := THPDFUA2RepairOptions.Default;
  Options.DefaultLanguage := 'en-US';
  Options.CustomAttributeNamespaceURI :=
    'https://example.com/ns/accessibility-attributes';
  if not PDF.RepairPDFUA2Structure(Options, Report, Issues) then
    raise Exception.CreateFmt('%s at %s',
      [String(Issues[0].Code), String(Issues[0].Path)]);
end;

API ที่เกี่ยวข้อง