mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
make everything internal which does not need to be public
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
using ContentStream;
|
||||
using Cos;
|
||||
|
||||
public class Catalog
|
||||
internal class Catalog
|
||||
{
|
||||
private readonly PdfDictionary catalogDictionary;
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
using Logging;
|
||||
using Parser;
|
||||
|
||||
public class Pages
|
||||
internal class Pages
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly Catalog catalog;
|
||||
|
@@ -7,7 +7,7 @@
|
||||
using Cos;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
public class PdfDictionary : CosBase, IReadOnlyDictionary<CosName, CosBase>
|
||||
internal class PdfDictionary : CosBase, IReadOnlyDictionary<CosName, CosBase>
|
||||
{
|
||||
private readonly Dictionary<CosName, CosBase> inner = new Dictionary<CosName, CosBase>();
|
||||
|
||||
|
@@ -2,10 +2,9 @@
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using Cos;
|
||||
using Util;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
public static class DictionaryValueAccessorExtensions
|
||||
internal static class DictionaryValueAccessorExtensions
|
||||
{
|
||||
public static long GetLongOrDefault(this PdfDictionary dictionary, CosName key)
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using Cos;
|
||||
|
||||
public static class DictionaryValueSetterExtensions
|
||||
internal static class DictionaryValueSetterExtensions
|
||||
{
|
||||
public static void SetLong(this PdfDictionary dictionary, CosName key, long value)
|
||||
{
|
||||
|
@@ -1,440 +0,0 @@
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using IO;
|
||||
using Parser;
|
||||
using Parser.Parts;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the in-memory representation of the PDF document. You need to call
|
||||
* close() on this object when you are done using it!!
|
||||
*
|
||||
* @author Ben Litchfield
|
||||
*
|
||||
*/
|
||||
public class COSDocument : CosBase, IDisposable
|
||||
{
|
||||
private float version = 1.4f;
|
||||
|
||||
/**
|
||||
* Maps ObjectKeys to a COSObject. Note that references to these objects
|
||||
* are also stored in COSDictionary objects that map a name to a specific object.
|
||||
*/
|
||||
private readonly Dictionary<CosObjectKey, CosObject> objectPool = new Dictionary<CosObjectKey, CosObject>();
|
||||
|
||||
/**
|
||||
* Maps object and generation id to object byte offsets.
|
||||
*/
|
||||
private readonly Dictionary<CosObjectKey, long> xrefTable = new Dictionary<CosObjectKey, long>();
|
||||
|
||||
/**
|
||||
* Document trailer dictionary.
|
||||
*/
|
||||
public CosDictionary trailer;
|
||||
|
||||
private bool warnMissingClose = true;
|
||||
|
||||
/**
|
||||
* Signal that document is already decrypted.
|
||||
*/
|
||||
|
||||
private bool closed = false;
|
||||
|
||||
/**
|
||||
* This will get the first dictionary object by type.
|
||||
*
|
||||
* @param type The type of the object.
|
||||
*
|
||||
* @return This will return an object with the specified type.
|
||||
* @throws IOException If there is an error getting the object
|
||||
*/
|
||||
public CosObject getObjectByType(CosName type)
|
||||
{
|
||||
foreach (CosObject obj in objectPool.Values)
|
||||
{
|
||||
var realObject = obj.GetObject();
|
||||
if (realObject is CosDictionary dic)
|
||||
{
|
||||
try
|
||||
{
|
||||
var typeItem = dic.getItem(CosName.TYPE);
|
||||
if (typeItem is CosName objectType)
|
||||
{
|
||||
if (objectType.Equals(type))
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
else if (typeItem != null)
|
||||
{
|
||||
//LOG.debug("Expected a /Name object after /Type, got '" + typeItem + "' instead");
|
||||
}
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
//LOG.warn(e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get all dictionary objects by type.
|
||||
*
|
||||
* @param type The type of the object.
|
||||
*
|
||||
* @return This will return an object with the specified type.
|
||||
* @throws IOException If there is an error getting the object
|
||||
*/
|
||||
public List<CosObject> getObjectsByType(String type)
|
||||
{
|
||||
return getObjectsByType(CosName.Create(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get a dictionary object by type.
|
||||
*
|
||||
* @param type The type of the object.
|
||||
*
|
||||
* @return This will return an object with the specified type.
|
||||
* @throws IOException If there is an error getting the object
|
||||
*/
|
||||
public List<CosObject> getObjectsByType(CosName type)
|
||||
{
|
||||
var retval = new List<CosObject>();
|
||||
foreach (var obj in objectPool.Values)
|
||||
{
|
||||
var realObject = obj.GetObject();
|
||||
if (realObject is CosDictionary dic)
|
||||
{
|
||||
try
|
||||
{
|
||||
var typeItem = dic.getItem(CosName.TYPE);
|
||||
if (typeItem is CosName objectType)
|
||||
{
|
||||
if (objectType.Equals(type))
|
||||
{
|
||||
retval.Add(obj);
|
||||
}
|
||||
}
|
||||
else if (typeItem != null)
|
||||
{
|
||||
//LOG.debug("Expected a /Name object after /Type, got '" + typeItem + "' instead");
|
||||
}
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
//LOG.warn(e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CosObjectKey for a given COS object, or null if there is none.
|
||||
* This lookup iterates over all objects in a PDF, which may be slow for large files.
|
||||
*
|
||||
* @param object COS object
|
||||
* @return key
|
||||
*/
|
||||
public CosObjectKey getKey(CosBase obj)
|
||||
{
|
||||
foreach (var entry in objectPool)
|
||||
{
|
||||
if (entry.Value.GetObject() == obj)
|
||||
{
|
||||
return entry.Key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will print contents to stdout.
|
||||
*/
|
||||
public void print()
|
||||
{
|
||||
foreach (CosObject obj in objectPool.Values)
|
||||
{
|
||||
Console.WriteLine(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public decimal Version { get; set; }
|
||||
|
||||
|
||||
public bool IsDecrypted { get; set; }
|
||||
/**
|
||||
* This will tell if this is an encrypted document.
|
||||
*
|
||||
* @return true If this document is encrypted.
|
||||
*/
|
||||
public bool isEncrypted()
|
||||
{
|
||||
var encrypted = false;
|
||||
if (trailer != null)
|
||||
{
|
||||
encrypted = trailer.getDictionaryObject(CosName.ENCRYPT) != null;
|
||||
}
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get the encryption dictionary if the document is encrypted or null
|
||||
* if the document is not encrypted.
|
||||
*
|
||||
* @return The encryption dictionary.
|
||||
*/
|
||||
public CosDictionary getEncryptionDictionary()
|
||||
{
|
||||
return (CosDictionary)trailer.getDictionaryObject(CosName.ENCRYPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the encryption dictionary, this should only be called when
|
||||
* encrypting the document.
|
||||
*
|
||||
* @param encDictionary The encryption dictionary.
|
||||
*/
|
||||
public void setEncryptionDictionary(CosDictionary encDictionary)
|
||||
{
|
||||
trailer.setItem(CosName.ENCRYPT, encDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get the document ID.
|
||||
*
|
||||
* @return The document id.
|
||||
*/
|
||||
public COSArray getDocumentID()
|
||||
{
|
||||
return (COSArray)getTrailer().getDictionaryObject(CosName.ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will set the document ID.
|
||||
*
|
||||
* @param id The document id.
|
||||
*/
|
||||
public void setDocumentID(COSArray id)
|
||||
{
|
||||
getTrailer().setItem(CosName.ID, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get the document catalog.
|
||||
*
|
||||
* @return @return The catalog is the root of the document; never null.
|
||||
*
|
||||
* @throws IOException If no catalog can be found.
|
||||
*/
|
||||
public CosObject getCatalog()
|
||||
{
|
||||
CosObject catalog = getObjectByType(CosName.CATALOG);
|
||||
if (catalog == null)
|
||||
{
|
||||
throw new InvalidOperationException("Catalog cannot be found");
|
||||
}
|
||||
return catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get a list of all available objects.
|
||||
*
|
||||
* @return A list of all objects, never null.
|
||||
*/
|
||||
public List<CosObject> getObjects()
|
||||
{
|
||||
return objectPool.Values.ToList();
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get the document trailer.
|
||||
*
|
||||
* @return the document trailer dict
|
||||
*/
|
||||
public CosDictionary getTrailer()
|
||||
{
|
||||
return trailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* // MIT added, maybe this should not be supported as trailer is a persistence construct.
|
||||
* This will set the document trailer.
|
||||
*
|
||||
* @param newTrailer the document trailer dictionary
|
||||
*/
|
||||
public void setTrailer(CosDictionary newTrailer)
|
||||
{
|
||||
trailer = newTrailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* visitor pattern double dispatch method.
|
||||
*
|
||||
* @param visitor The object to notify when visiting this object.
|
||||
* @return any object, depending on the visitor implementation, or null
|
||||
* @throws IOException If an error occurs while visiting this object.
|
||||
*/
|
||||
public override object Accept(ICosVisitor visitor)
|
||||
{
|
||||
return visitor.VisitFromDocument(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will close all storage and delete the tmp files.
|
||||
*
|
||||
* @throws IOException If there is an error close resources.
|
||||
*/
|
||||
public void Dispose()
|
||||
{
|
||||
if (!closed)
|
||||
{
|
||||
// close all open I/O streams
|
||||
foreach (CosObject obj in getObjects())
|
||||
{
|
||||
CosBase cosObject = obj.GetObject();
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this document has been closed.
|
||||
*/
|
||||
public bool isClosed()
|
||||
{
|
||||
return closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn the user in the finalizer if he didn't close the PDF document. The method also
|
||||
* closes the document just in case, to avoid abandoned temporary files. It's still a good
|
||||
* idea for the user to close the PDF document at the earliest possible to conserve resources.
|
||||
* @throws IOException if an error occurs while closing the temporary files
|
||||
*/
|
||||
~COSDocument()
|
||||
{
|
||||
if (!closed)
|
||||
{
|
||||
if (warnMissingClose)
|
||||
{
|
||||
//LOG.warn("Warning: You did not close a PDF Document");
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether this instance shall issue a warning if the PDF document wasn't closed
|
||||
* properly through a call to the {@link #close()} method. If the PDF document is held in
|
||||
* a cache governed by soft references it is impossible to reliably close the document
|
||||
* before the warning is raised. By default, the warning is enabled.
|
||||
* @param warn true enables the warning, false disables it.
|
||||
*/
|
||||
public void setWarnMissingClose(bool warn)
|
||||
{
|
||||
this.warnMissingClose = warn;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get an object from the pool.
|
||||
*
|
||||
* @param key The object key.
|
||||
*
|
||||
* @return The object in the pool or a new one if it has not been parsed yet.
|
||||
*
|
||||
* @throws IOException If there is an error getting the proxy object.
|
||||
*/
|
||||
public CosObject getObjectFromPool(CosObjectKey key)
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
if (objectPool.TryGetValue(key, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// this was a forward reference, make "proxy" object
|
||||
var obj = new CosObject(null);
|
||||
if (key != null)
|
||||
{
|
||||
obj.SetObjectNumber(key.Number);
|
||||
obj.SetGenerationNumber((int)key.Generation);
|
||||
objectPool[key] = obj;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an object from the object pool.
|
||||
* @param key the object key
|
||||
* @return the object that was removed or null if the object was not found
|
||||
*/
|
||||
public CosObject removeObject(CosObjectKey key)
|
||||
{
|
||||
if (!objectPool.TryGetValue(key, out CosObject result))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
objectPool.Remove(key);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate XRef HashMap with given values.
|
||||
* Each entry maps ObjectKeys to byte offsets in the file.
|
||||
* @param xrefTableValues xref table entries to be added
|
||||
*/
|
||||
public void addXRefTable(Dictionary<CosObjectKey, long> xrefTableValues)
|
||||
{
|
||||
foreach (var value in xrefTableValues)
|
||||
{
|
||||
xrefTable[value.Key] = value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the xrefTable which is a mapping of ObjectKeys
|
||||
* to byte offsets in the file.
|
||||
* @return mapping of ObjectsKeys to byte offsets
|
||||
*/
|
||||
public Dictionary<CosObjectKey, long> getXrefTable()
|
||||
{
|
||||
return xrefTable;
|
||||
}
|
||||
|
||||
|
||||
public long StartXRef { get; set; }
|
||||
|
||||
public bool IsXRefStream { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -25,7 +25,8 @@ namespace UglyToad.Pdf.Cos
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
public class COSArray : CosBase, IEnumerable<CosBase>, ICosUpdateInfo
|
||||
|
||||
internal class COSArray : CosBase, IEnumerable<CosBase>, ICosUpdateInfo
|
||||
{
|
||||
private readonly List<CosBase> objects = new List<CosBase>();
|
||||
public bool NeedsToBeUpdated { get; set; }
|
||||
|
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
public abstract class CosBase : ICosObject
|
||||
internal abstract class CosBase : ICosObject
|
||||
{
|
||||
public bool Direct { get; set; }
|
||||
|
||||
@@ -16,7 +12,7 @@ namespace UglyToad.Pdf.Cos
|
||||
public abstract object Accept(ICosVisitor visitor);
|
||||
}
|
||||
|
||||
public interface ICosObject
|
||||
internal interface ICosObject
|
||||
{
|
||||
CosBase GetCosObject();
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
using System.IO;
|
||||
using Core;
|
||||
|
||||
public class CosBoolean : CosBase, ICosStreamWriter
|
||||
internal class CosBoolean : CosBase, ICosStreamWriter
|
||||
{
|
||||
/**
|
||||
* The true boolean token.
|
||||
|
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Util;
|
||||
|
||||
public class CosDictionary : CosBase, ICosUpdateInfo
|
||||
internal class CosDictionary : CosBase, ICosUpdateInfo
|
||||
{
|
||||
private static readonly string PATH_SEPARATOR = "/";
|
||||
private bool needToBeUpdated;
|
||||
@@ -63,7 +62,7 @@ namespace UglyToad.Pdf.Cos
|
||||
var contains = items.Values.Any(x => ReferenceEquals(x, value));
|
||||
if (!contains && value is CosObject)
|
||||
{
|
||||
contains = items.ContainsValue(((CosObject) value).GetObject());
|
||||
contains = items.ContainsValue(((CosObject)value).GetObject());
|
||||
}
|
||||
return contains;
|
||||
}
|
||||
@@ -80,7 +79,7 @@ namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
Object nextValue = item.Value;
|
||||
if (nextValue.Equals(value)
|
||||
|| nextValue is CosObject && ((CosObject) nextValue).GetObject()
|
||||
|| nextValue is CosObject && ((CosObject)nextValue).GetObject()
|
||||
.Equals(value))
|
||||
{
|
||||
return item.Key;
|
||||
@@ -176,7 +175,7 @@ namespace UglyToad.Pdf.Cos
|
||||
|
||||
if (result is CosObject)
|
||||
{
|
||||
result = ((CosObject) result).GetObject();
|
||||
result = ((CosObject)result).GetObject();
|
||||
}
|
||||
if (result is CosNull)
|
||||
{
|
||||
@@ -239,7 +238,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public void setbool(String key, bool value)
|
||||
{
|
||||
setItem(CosName.Create(key), (CosBoolean) value);
|
||||
setItem(CosName.Create(key), (CosBoolean)value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,7 +249,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public void setbool(CosName key, bool value)
|
||||
{
|
||||
setItem(key, (CosBoolean) value);
|
||||
setItem(key, (CosBoolean)value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +335,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public void setEmbeddedDate(String embedded, CosName key, DateTime date)
|
||||
{
|
||||
CosDictionary dic = (CosDictionary) getDictionaryObject(embedded);
|
||||
CosDictionary dic = (CosDictionary)getDictionaryObject(embedded);
|
||||
if (dic == null)
|
||||
{
|
||||
dic = new CosDictionary();
|
||||
@@ -397,7 +396,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public void setEmbeddedString(String embedded, CosName key, String value)
|
||||
{
|
||||
CosDictionary dic = (CosDictionary) getDictionaryObject(embedded);
|
||||
CosDictionary dic = (CosDictionary)getDictionaryObject(embedded);
|
||||
if (dic == null && value != null)
|
||||
{
|
||||
dic = new CosDictionary();
|
||||
@@ -475,7 +474,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public void setEmbeddedInt(String embeddedDictionary, CosName key, int value)
|
||||
{
|
||||
CosDictionary embedded = (CosDictionary) getDictionaryObject(embeddedDictionary);
|
||||
CosDictionary embedded = (CosDictionary)getDictionaryObject(embeddedDictionary);
|
||||
if (embedded == null)
|
||||
{
|
||||
embedded = new CosDictionary();
|
||||
@@ -540,7 +539,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase name = getDictionaryObject(key);
|
||||
if (name is CosName)
|
||||
{
|
||||
return (CosName) name;
|
||||
return (CosName)name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -558,7 +557,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase name = getDictionaryObject(key);
|
||||
if (name is CosName)
|
||||
{
|
||||
return (CosName) name;
|
||||
return (CosName)name;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -588,11 +587,11 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase name = getDictionaryObject(key);
|
||||
if (name is CosName)
|
||||
{
|
||||
retval = ((CosName) name).Name;
|
||||
retval = ((CosName)name).Name;
|
||||
}
|
||||
else if (name is CosString)
|
||||
{
|
||||
retval = ((CosString) name).GetString();
|
||||
retval = ((CosString)name).GetString();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -653,7 +652,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase value = getDictionaryObject(key);
|
||||
if (value is CosString)
|
||||
{
|
||||
retval = ((CosString) value).GetString();
|
||||
retval = ((CosString)value).GetString();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -741,7 +740,7 @@ namespace UglyToad.Pdf.Cos
|
||||
public String getEmbeddedString(String embedded, CosName key, String defaultValue)
|
||||
{
|
||||
String retval = defaultValue;
|
||||
CosDictionary dic = (CosDictionary) getDictionaryObject(embedded);
|
||||
CosDictionary dic = (CosDictionary)getDictionaryObject(embedded);
|
||||
if (dic != null)
|
||||
{
|
||||
retval = dic.getString(key, defaultValue);
|
||||
@@ -773,7 +772,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase baseObj = getDictionaryObject(key);
|
||||
if (baseObj is CosString)
|
||||
{
|
||||
return DateConverter.toCalendar((CosString) baseObj);
|
||||
return DateConverter.toCalendar((CosString)baseObj);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -870,7 +869,7 @@ namespace UglyToad.Pdf.Cos
|
||||
|
||||
{
|
||||
var retval = defaultValue;
|
||||
CosDictionary eDic = (CosDictionary) getDictionaryObject(embedded);
|
||||
CosDictionary eDic = (CosDictionary)getDictionaryObject(embedded);
|
||||
if (eDic != null)
|
||||
{
|
||||
retval = eDic.getDate(key, defaultValue);
|
||||
@@ -922,7 +921,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase boolValue = getDictionaryObject(firstKey, secondKey);
|
||||
if (boolValue is CosBoolean)
|
||||
{
|
||||
retval = ((CosBoolean) boolValue).Value;
|
||||
retval = ((CosBoolean)boolValue).Value;
|
||||
}
|
||||
|
||||
return retval;
|
||||
@@ -980,7 +979,7 @@ namespace UglyToad.Pdf.Cos
|
||||
public int getEmbeddedInt(String embeddedDictionary, CosName key, int defaultValue)
|
||||
{
|
||||
int retval = defaultValue;
|
||||
CosDictionary embedded = (CosDictionary) getDictionaryObject(embeddedDictionary);
|
||||
CosDictionary embedded = (CosDictionary)getDictionaryObject(embeddedDictionary);
|
||||
if (embedded != null)
|
||||
{
|
||||
retval = embedded.getInt(key, defaultValue);
|
||||
@@ -1026,7 +1025,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase obj = getDictionaryObject(keyList);
|
||||
if (obj is ICosNumber)
|
||||
{
|
||||
retval = ((ICosNumber) obj).AsInt();
|
||||
retval = ((ICosNumber)obj).AsInt();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -1161,7 +1160,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase obj = getDictionaryObject(key);
|
||||
if (obj is ICosNumber)
|
||||
{
|
||||
retval = ((ICosNumber) obj).AsLong();
|
||||
retval = ((ICosNumber)obj).AsLong();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -1217,7 +1216,7 @@ namespace UglyToad.Pdf.Cos
|
||||
CosBase obj = getDictionaryObject(key);
|
||||
if (obj is ICosNumber)
|
||||
{
|
||||
retval = ((ICosNumber) obj).AsFloat();
|
||||
retval = ((ICosNumber)obj).AsFloat();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -1382,18 +1381,18 @@ namespace UglyToad.Pdf.Cos
|
||||
*/
|
||||
public CosBase getObjectFromPath(String objPath)
|
||||
{
|
||||
String[] path = objPath.Split(new string[] {PATH_SEPARATOR}, StringSplitOptions.RemoveEmptyEntries);
|
||||
String[] path = objPath.Split(new string[] { PATH_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
|
||||
CosBase retval = this;
|
||||
foreach (var pathString in path)
|
||||
{
|
||||
if (retval is COSArray)
|
||||
{
|
||||
int idx = int.Parse(pathString.Replace("\\[", "").Replace("\\]", ""));
|
||||
retval = ((COSArray) retval).getObject(idx);
|
||||
retval = ((COSArray)retval).getObject(idx);
|
||||
}
|
||||
else if (retval is CosDictionary)
|
||||
{
|
||||
retval = ((CosDictionary) retval).getDictionaryObject(pathString);
|
||||
retval = ((CosDictionary)retval).getDictionaryObject(pathString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1408,7 +1407,7 @@ namespace UglyToad.Pdf.Cos
|
||||
public CosDictionary asUnmodifiableDictionary()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// return new UnmodifiableCosDictionary(this);
|
||||
// return new UnmodifiableCosDictionary(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1418,7 +1417,7 @@ namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
try
|
||||
{
|
||||
return getDictionaryString(this, new List<CosBase>());
|
||||
return getDictionaryString(this, new List<CosBase>());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@ using UglyToad.Pdf.Core;
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
public class CosFloat : CosBase, ICosNumber, ICosStreamWriter
|
||||
internal class CosFloat : CosBase, ICosNumber, ICosStreamWriter
|
||||
{
|
||||
private readonly decimal value;
|
||||
private readonly string valueAsString;
|
||||
|
@@ -4,7 +4,7 @@ using UglyToad.Pdf.Core;
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
public class CosInt : CosBase, ICosNumber, ICosStreamWriter
|
||||
internal class CosInt : CosBase, ICosNumber, ICosStreamWriter
|
||||
{
|
||||
/**
|
||||
* The lowest integer to be kept in the {@link #STATIC} array.
|
||||
|
@@ -16,7 +16,7 @@ namespace UglyToad.Pdf.Cos
|
||||
*
|
||||
* @author Ben Litchfield
|
||||
*/
|
||||
public class CosName : CosBase, IComparable<CosName>, ICosStreamWriter
|
||||
internal class CosName : CosBase, IComparable<CosName>, ICosStreamWriter
|
||||
{
|
||||
// using ConcurrentHashMap because this can be accessed by multiple threads
|
||||
private static readonly ConcurrentDictionary<string, CosName> NameMap = new ConcurrentDictionary<string, CosName>();
|
||||
|
@@ -5,7 +5,7 @@ namespace UglyToad.Pdf.Cos
|
||||
using System.IO;
|
||||
using Core;
|
||||
|
||||
public class CosNull : CosBase, ICosStreamWriter
|
||||
internal class CosNull : CosBase, ICosStreamWriter
|
||||
{
|
||||
/// <summary>
|
||||
/// The Null Token
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using ContentStream;
|
||||
|
||||
public class CosObject : CosBase, ICosUpdateInfo
|
||||
internal class CosObject : CosBase, ICosUpdateInfo
|
||||
{
|
||||
private CosBase baseObject;
|
||||
private long objectNumber;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
public class CosObjectKey : IComparable<CosObjectKey>
|
||||
internal class CosObjectKey : IComparable<CosObjectKey>
|
||||
{
|
||||
public long Number { get; }
|
||||
public long Generation { get; }
|
||||
|
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace UglyToad.Pdf.Cos
|
||||
namespace UglyToad.Pdf.Cos
|
||||
{
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Util;
|
||||
|
||||
public class CosString : CosBase
|
||||
internal class CosString : CosBase
|
||||
{
|
||||
public byte[] Bytes { get; }
|
||||
|
||||
@@ -70,7 +69,7 @@ namespace UglyToad.Pdf.Cos
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static byte[] CloneBytes(IReadOnlyList<byte> bytes)
|
||||
{
|
||||
var result = new byte[bytes.Count];
|
||||
@@ -181,7 +180,7 @@ namespace UglyToad.Pdf.Cos
|
||||
return ((Bytes != null ? Bytes.GetHashCode() : 0) * 397);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override object Accept(ICosVisitor visitor)
|
||||
{
|
||||
return visitor.VisitFromString(this);
|
||||
|
@@ -5,7 +5,7 @@
|
||||
using ContentStream;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
public class CrossReferenceTable
|
||||
internal class CrossReferenceTable
|
||||
{
|
||||
public CrossReferenceType Type { get; }
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
/// giving the number of bytes from the beginning of the file to the beginning of the
|
||||
/// object.
|
||||
/// </remarks>
|
||||
public class CrossReferenceTablePart
|
||||
internal class CrossReferenceTablePart
|
||||
{
|
||||
public IReadOnlyDictionary<CosObjectKey, long> ObjectOffsets { get; }
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* @author Michael Traut
|
||||
*/
|
||||
public interface ICosVisitor
|
||||
internal interface ICosVisitor
|
||||
{
|
||||
/**
|
||||
* Notification of visit to Array object.
|
||||
@@ -33,16 +33,7 @@
|
||||
* @throws IOException If there is an error while visiting this object.
|
||||
*/
|
||||
object VisitFromDictionary(CosDictionary obj);
|
||||
|
||||
/**
|
||||
* Notification of visit to document object.
|
||||
*
|
||||
* @param obj The Object that is being visited.
|
||||
* @return any Object depending on the visitor implementation, or null
|
||||
* @throws IOException If there is an error while visiting this object.
|
||||
*/
|
||||
object VisitFromDocument(COSDocument obj);
|
||||
|
||||
|
||||
/**
|
||||
* Notification of visit to float object.
|
||||
*
|
||||
|
@@ -7,7 +7,7 @@
|
||||
/// <summary>
|
||||
/// ASCII 85 (Base85) is a binary to text encoding using 5 ASCII characters per 4 bytes of data.
|
||||
/// </summary>
|
||||
public class Ascii85Filter : IFilter
|
||||
internal class Ascii85Filter : IFilter
|
||||
{
|
||||
private const byte EmptyBlock = (byte)'z';
|
||||
private const byte Offset = (byte)'!';
|
||||
|
@@ -16,7 +16,7 @@
|
||||
/// See section 3.3.3 of the spec (version 1.7) for details on the FlateDecode filter.
|
||||
/// The flate decode filter may have a predictor function to further compress the stream.
|
||||
/// </remarks>
|
||||
public class FlateFilter : IFilter
|
||||
internal class FlateFilter : IFilter
|
||||
{
|
||||
// Defaults are from table 3.7 in the spec (version 1.7)
|
||||
private const int DefaultColors = 1;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using ContentStream;
|
||||
|
||||
public interface IDecodeParameterResolver
|
||||
internal interface IDecodeParameterResolver
|
||||
{
|
||||
PdfDictionary GetFilterParameters(PdfDictionary streamDictionary, int index);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using ContentStream;
|
||||
|
||||
public interface IFilter
|
||||
internal interface IFilter
|
||||
{
|
||||
byte[] Decode(byte[] input, PdfDictionary streamDictionary, int filterIndex);
|
||||
}
|
||||
|
@@ -0,0 +1,6 @@
|
||||
namespace UglyToad.Pdf.Fonts.Parser.Handlers
|
||||
{
|
||||
internal class TrueTypeFontHandler
|
||||
{
|
||||
}
|
||||
}
|
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Store the results of a brute force search for all Cos Objects in the document so we only do it once.
|
||||
/// </summary>
|
||||
public class BruteForceSearcher
|
||||
internal class BruteForceSearcher
|
||||
{
|
||||
private const int MinimumSearchOffset = 6;
|
||||
|
||||
|
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UglyToad.Pdf.Parser
|
||||
namespace UglyToad.Pdf.Parser
|
||||
{
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cos;
|
||||
|
||||
public class XrefTrailerResolver
|
||||
internal class XrefTrailerResolver
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -6,7 +6,7 @@
|
||||
using Cos;
|
||||
using Util.JetBrains.Annotations;
|
||||
|
||||
public class DictionaryToken : IDataToken<IReadOnlyDictionary<IToken, IToken>>
|
||||
internal class DictionaryToken : IDataToken<IReadOnlyDictionary<IToken, IToken>>
|
||||
{
|
||||
[NotNull]
|
||||
public IReadOnlyDictionary<IToken, IToken> Data { get; }
|
||||
|
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using Cos;
|
||||
|
||||
public class NameToken : IDataToken<CosName>
|
||||
internal class NameToken : IDataToken<CosName>
|
||||
{
|
||||
public CosName Data { get; }
|
||||
|
||||
|
@@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UglyToad.Pdf.Util
|
||||
namespace UglyToad.Pdf.Util
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Cos;
|
||||
|
||||
public class DateConverter
|
||||
internal class DateConverter
|
||||
{
|
||||
private DateConverter()
|
||||
{
|
||||
@@ -231,12 +228,12 @@ namespace UglyToad.Pdf.Util
|
||||
* package-private for testing
|
||||
*/
|
||||
private static string formatTZoffset(long millis, string sep)
|
||||
{
|
||||
//{
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("Z"); // #hhmm
|
||||
// sdf.setTimeZone(new SimpleTimeZone(restrainTZoffset(millis), "unknown"));
|
||||
// String tz = sdf.format(new Date());
|
||||
// return tz.substring(0, 3) + sep + tz.substring(3);
|
||||
{
|
||||
//{
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("Z"); // #hhmm
|
||||
// sdf.setTimeZone(new SimpleTimeZone(restrainTZoffset(millis), "unknown"));
|
||||
// String tz = sdf.format(new Date());
|
||||
// return tz.substring(0, 3) + sep + tz.substring(3);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -627,7 +624,7 @@ namespace UglyToad.Pdf.Util
|
||||
if (whereLen == text.Length)
|
||||
{
|
||||
initialWhere.Index = whereLen;
|
||||
// return retCal;
|
||||
// return retCal;
|
||||
}
|
||||
if (whereLen > longestLen)
|
||||
{
|
||||
|
Reference in New Issue
Block a user