public FixedPayload(XpsDocument document) { resMngr = new ResourceManager(this); this.document = document; // HACK: find fdseq string fdseqString = null; foreach (ZipPackagePart part in XpsDocument.Parts) { //string uriString = part.Uri.OriginalString; //if (uriString.EndsWith("fdseq", true, CultureInfo.InvariantCulture)) //File extension for fdseq file can be different. //[Content_Types].xml contains the informations needed and already pared by ZipPackage. if (part.ContentType.Contains("application/vnd.ms-package.xps-fixeddocumentsequence+xml")) { fdseqString = part.Uri.OriginalString; break; } } Debug.Assert(fdseqString != null); fdseq = XpsParser.Parse(GetPartAsXmlReader(fdseqString)) as FixedDocumentSequence; fdocs = new FixedDocument[fdseq.DocumentReferences.Count]; }
private static string GetContent(string fileName) { using (InputStream stream = new FileInputStream(new File(fileName))) { AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); var xpsParser = new XpsParser(); parser.setParsers(new java.util.HashMap { { MediaType.application("vnd.ms-xpsdocument"), xpsParser } }); parser.setParsers(new java.util.HashMap { { MediaType.application("x-tika-ooxml"), xpsParser } }); parser.parse(stream, handler, metadata); return handler.toString(); } }
/// <summary> /// Gets the document with the specified index. /// </summary> public FixedDocument GetDocument(int index) { if (index < 0 || index > fdocs.Length - 1) { throw new ArgumentOutOfRangeException("index"); } FixedDocument fdoc = fdocs[index]; if (fdoc == null) { string source = fdseq.DocumentReferences[index].Source; fdoc = XpsParser.Parse(GetPartAsXmlReader(source)) as FixedDocument; fdoc.Payload = this; source = IOPath.GetDirectoryName(source); source = source.Replace('\\', '/'); if (!source.StartsWith("/")) { source = "/" + source; } fdoc.UriString = source; fdocs[index] = fdoc; } return(fdoc); }
GlyphIndices.GlyphMapping ParsePart(string parts) { GlyphIndices.GlyphMapping mapping = new GlyphIndices.GlyphMapping(42); //mapping.ClusterCodeUnitCount = 1; //mapping.ClusterGlyphCount = 1; //mapping.GlyphIndex = -1; //mapping.AdvanceWidth = Double.NaN; //mapping.UOffset = Double.NaN; //mapping.VOffset = Double.NaN; #if true string[] commaSeparated = parts.Split(','); if (commaSeparated.Length > 0) { if (!String.IsNullOrEmpty(commaSeparated[0])) { // Just split the numbers // (a:b)c // (a)c // c // (a:b) - not possible // (a) - not possible string[] tempStr = commaSeparated[0].Split(new char[] { '(', ')', ':' }, StringSplitOptions.RemoveEmptyEntries); // Last number is always the index mapping.GlyphIndex = int.Parse(tempStr[tempStr.Length - 1]); // First and second (if available) are the code unit count and glyph count if (tempStr.Length > 1) { mapping.ClusterCodeUnitCount = int.Parse(tempStr[0]); } if (tempStr.Length > 2) { mapping.ClusterGlyphCount = int.Parse(tempStr[1]); } } if (commaSeparated.Length > 1 && !String.IsNullOrEmpty(commaSeparated[1])) { mapping.AdvanceWidth = XpsParser.ParseDouble(commaSeparated[1]); } if (commaSeparated.Length > 2 && !String.IsNullOrEmpty(commaSeparated[2])) { mapping.UOffset = XpsParser.ParseDouble(commaSeparated[2]); } if (commaSeparated.Length > 3 && !String.IsNullOrEmpty(commaSeparated[3])) { mapping.VOffset = XpsParser.ParseDouble(commaSeparated[3]); } } #else string[] commaSeparated = parts.Split(','); if (commaSeparated.Length > 0) { if (commaSeparated[0] != "") { // Just split the numbers string[] tempStr = commaSeparated[0].Split(new char[] { '(', ')', ':' }, StringSplitOptions.RemoveEmptyEntries); // Last number is the index mapping.GlyphIndex = int.Parse(tempStr[tempStr.Length - 1]); // First and second (if available) are the code unit count and glyph count) if (tempStr.Length > 1) { int.TryParse(tempStr[0], out mapping.ClusterCodeUnitCount); } if (tempStr.Length > 2) { int.TryParse(tempStr[1], out mapping.ClusterGlyphCount); } } if (commaSeparated.Length > 1) { double.TryParse(commaSeparated[1], out mapping.AdvanceWidth); // BUG: InvariantCulture not used! } if (commaSeparated.Length > 2) { double.TryParse(commaSeparated[2], out mapping.UOffset); // <-- must not be zero if not defined, but must keep NaN } if (commaSeparated.Length > 3) { double.TryParse(commaSeparated[3], out mapping.VOffset); } } #endif return(mapping); }