1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
11
// Permission is hereby granted, free of charge, to any person obtaining a
12
// copy of this software and associated documentation files (the "Software"),
13
// to deal in the Software without restriction, including without limitation
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
// and/or sell copies of the Software, and to permit persons to whom the
16
// Software is furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
// DEALINGS IN THE SOFTWARE.
31
using System.Diagnostics;
32
using System.Resources;
33
using System.Reflection;
34
using System.Text.RegularExpressions;
35
using PdfSharp.Drawing;
38
#pragma warning disable 1591
43
/// The Pdf-Sharp-String-Resources.
45
public static class PSSR
48
// Create a function or property for each message text, depending on how much parameters are
49
// part of the message. For the time beginning, type plain english text in the function or property.
50
// The use of functions is save when a parameter must be changed. The compiler tells you all
51
// places in your code that must be modified.
52
// For localization, create a enum value for each function or property with the same name. Then
53
// create localized message files with the enum values as messages identifiers. In the properties
54
// and functions all text is replaced by Format or GetString functions with the according enum value
55
// as first parameter. The use of enums ensures that typing errors in message resource names are
56
// simply impossible. Use the TestResourceMessages function to ensure that each enum value has an
57
// appropriate message text.
59
#region Helper functions
61
/// Loads the message from the resource associated with the enum type and formats it
62
/// using 'String.Format'. Because this function is intended to be used during error
63
/// handling it never raises an exception.
65
/// <param name="id">The type of the parameter identifies the resource
66
/// and the name of the enum identifies the message in the resource.</param>
67
/// <param name="args">Parameters passed through 'String.Format'.</param>
68
/// <returns>The formatted message.</returns>
69
public static string Format(PSMsgID id, params object[] args)
74
message = PSSR.GetString(id);
76
message = Format(message, args);
78
message = "INTERNAL ERROR: Message not found in resources.";
83
message = String.Format("UNEXPECTED ERROR while formatting message with ID {0}: {1}", id.ToString(), ex.ToString());
88
public static string Format(string format, params object[] args)
91
throw new ArgumentNullException("format");
96
message = String.Format(format, args);
100
message = String.Format("UNEXPECTED ERROR while formatting message '{0}': {1}", format, ex.ToString());
106
/// Gets the localized message identified by the specified DomMsgID.
108
public static string GetString(PSMsgID id)
110
return PSSR.ResMngr.GetString(id.ToString());
115
#region General messages
117
public static string IndexOutOfRange
119
get { return "The index is out of range."; }
122
public static string ListEnumCurrentOutOfRange
124
get { return "Enumeration out of range."; }
127
public static string PageIndexOutOfRange
129
get { return "The index of a page is out of range."; }
132
public static string OutlineIndexOutOfRange
134
get { return "The index of an outline is out of range."; }
137
public static string InvalidValue(int val, string name, int min, int max)
139
return Format("{0} is not a valid value for {1}. {1} should be greater than or equal to {2} and less than or equal to {3}.",
140
val, name, min, max);
143
public static string ObsoleteFunktionCalled
145
get { return "The function is obsolete and must not be called."; }
148
public static string OwningDocumentRequired
150
get { return "The PDF object must belong to a PdfDocument, but property Document is null."; }
153
public static string FileNotFound(string path)
155
return Format("The file '{0}' does not exist.", path);
158
public static string FontDataReadOnly
160
get { return "Font data is read-only"; }
165
#region XGraphics specific messages
167
// ----- XGraphics ----------------------------------------------------------------------------
169
public static string PointArrayEmpty
171
get { return "The PointF array must not be empty."; }
174
public static string PointArrayAtLeast(int count)
176
return Format("The point array must contain {0} or more points.", count);
179
public static string NeedPenOrBrush
181
get { return "XPen or XBrush or both must not be null."; }
184
public static string CannotChangeImmutableObject(string typename)
186
return String.Format("You cannot change this immutable {0} object.", typename);
191
#region PDF specific messages
193
// ----- PDF ----------------------------------------------------------------------------------
195
public static string InvalidPdf
197
get { return "The file is not a valid PDF document."; }
200
public static string InvalidVersionNumber
202
get { return "Invalid version number. Valid values are 12, 13, and 14."; }
205
public static string CannotHandleXRefStreams
207
get { return "Cannot handle iref streams. The current implementation of PDFsharp cannot handle this PDF feature introduced with Acrobat 6."; }
210
public static string PasswordRequired
212
get { return "A password is required to open the PDF document."; }
215
public static string InvalidPassword
217
get { return "The specified password is invalid."; }
220
public static string OwnerPasswordRequired
222
get { return "To modify the document the owner password is required"; }
225
public static string UserOrOwnerPasswordRequired
227
get { return GetString(PSMsgID.UserOrOwnerPasswordRequired); }
228
//get { return "At least a user or an owner password is required to encrypt the document."; }
231
public static string CannotModify
233
get { return "The document cannot be modified."; }
236
public static string NameMustStartWithSlash
238
//get { return GetString(PSMsgID.NameMustStartWithSlash); }
239
get { return "A PDF name must start with a slash (/)."; }
242
public static string ImportPageNumberOutOfRange(int pageNumber, int maxPage, string path)
244
return String.Format("The page cannot be imported from document '{2}', because the page number is out of range. " +
245
"The specified page number is {0}, but it must be in the range from 1 to {1}.", pageNumber, maxPage, path);
248
public static string MultiplePageInsert
250
get { return "The page cannot be added to this document because the document already owned this page."; }
253
public static string UnexpectedTokenInPdfFile
255
get { return "Unexpected token in PDF file. The PDF file may be currupt. If it is not, please send us the file for serivce."; }
258
public static string InappropriateColorSpace(PdfColorMode colorMode, XColorSpace colorSpace)
263
case PdfColorMode.Rgb:
267
case PdfColorMode.Cmyk:
272
mode = "(undefined)";
279
case XColorSpace.Rgb:
283
case XColorSpace.Cmyk:
287
case XColorSpace.GrayScale:
292
space = "(undefined)";
295
return String.Format("The document requires color mode {0}, but a color is defined using {1}. " +
296
"Use only colors that match the color mode of the PDF document", mode, space);
299
public static string CannotGetGlyphTypeface(string fontName)
301
return Format("Cannot get a matching glyph typeface for font '{0}'.", fontName);
305
// ----- PdfParser ----------------------------------------------------------------------------
307
public static string UnexpectedToken(string token)
309
return Format(PSMsgID.UnexpectedToken, token);
310
//return Format("Token '{0}' was not expected.", token);
313
public static string UnknownEncryption
315
get { return GetString(PSMsgID.UnknownEncryption); }
316
//get { return "The PDF document is protected with an encryption not supported by PDFsharp."; }
321
#region Resource manager
324
/// Gets the resource manager for this module.
326
public static ResourceManager ResMngr
330
if (PSSR.resmngr == null)
333
// Force the english language, even on a German PC.
334
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
336
PSSR.resmngr = new ResourceManager("PdfSharp.Resources.Messages", Assembly.GetExecutingAssembly());
341
static ResourceManager resmngr;
344
/// Writes all messages defined by PSMsgID.
346
[Conditional("DEBUG")]
347
public static void TestResourceMessages()
349
string[] names = Enum.GetNames(typeof(PSMsgID));
350
foreach (string name in names)
352
string message = String.Format("{0}: '{1}'", name, ResMngr.GetString(name));
353
Debug.Assert(message != null);
354
Debug.WriteLine(message);
360
//TestResourceMessages();