git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@12 820d3149-562b-4f88-9aa4-a8e61a3485cf
master
psoares33 2008-08-18 19:13:00 +00:00
parent 4141622d84
commit 8c97e0dd51
11 changed files with 599 additions and 495 deletions

View File

@ -445,6 +445,17 @@ namespace iTextSharp.text
/** a possible list attribute */
public const String LOWERCASE = "lowercase";
/**
* a possible list attribute
* @since 2.1.3
*/
public const String FACE = "face";
/** attribute of the image or iframe tag
* @since 2.1.3
*/
public const String SRC = "src";
// methods
/// <summary>

View File

@ -122,7 +122,7 @@ namespace iTextSharp.text.factories {
}
value = attributes[Markup.CSS_KEY_LINEHEIGHT];
if (value != null) {
phrase.Leading = Markup.ParseLength(value);
phrase.Leading = Markup.ParseLength(value, Markup.DEFAULT_FONT_SIZE);
}
value = attributes[ElementTags.ITEXT];
if (value != null) {

View File

@ -213,7 +213,7 @@ namespace iTextSharp.text.html {
this[peer.Alias] = peer;
peer = new HtmlPeer(ElementTags.IMAGE, HtmlTags.IMAGE);
peer.AddAlias(ElementTags.URL, HtmlTags.URL);
peer.AddAlias(ElementTags.URL, ElementTags.SRC); // contributed by Lubos Strapko
peer.AddAlias(ElementTags.ALT, HtmlTags.ALT);
peer.AddAlias(ElementTags.PLAINWIDTH, HtmlTags.PLAINWIDTH);
peer.AddAlias(ElementTags.PLAINHEIGHT, HtmlTags.PLAINHEIGHT);

View File

@ -321,5 +321,9 @@ namespace iTextSharp.text.html {
/** This is a possible HTML attribute. */
public const string STYLESHEET = "stylesheet";
/** This is a possible HTML attribute for auto-formated
* @since 2.1.3
*/
public const String PRE = "pre";
}
}

View File

@ -268,12 +268,79 @@ namespace iTextSharp.text.html {
/** a CSS value for text decoration */
public const string CSS_VALUE_UNDERLINE = "underline";
/** a default value for font-size
* @since 2.1.3
*/
public const float DEFAULT_FONT_SIZE = 12f;
/// <summary>
/// Parses a length.
/// </summary>
/// <param name="str">a length in the form of an optional + or -, followed by a number and a unit.</param>
/// <returns>a float</returns>
public static float ParseLength(string str) {
// TODO: Evaluate the effect of this.
// It may change the default behavour of the methd if this is changed.
// return ParseLength(string, Markup.DEFAULT_FONT_SIZE);
int pos = 0;
int length = str.Length;
bool ok = true;
while (ok && pos < length) {
switch (str[pos]) {
case '+':
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
pos++;
break;
default:
ok = false;
break;
}
}
if (pos == 0)
return 0f;
if (pos == length)
return float.Parse(str, System.Globalization.NumberFormatInfo.InvariantInfo);
float f = float.Parse(str.Substring(0, pos), System.Globalization.NumberFormatInfo.InvariantInfo);
str = str.Substring(pos);
// inches
if (str.StartsWith("in")) {
return f * 72f;
}
// centimeters
if (str.StartsWith("cm")) {
return (f / 2.54f) * 72f;
}
// millimeters
if (str.StartsWith("mm")) {
return (f / 25.4f) * 72f;
}
// picas
if (str.StartsWith("pc")) {
return f * 12f;
}
// default: we assume the length was measured in points
return f;
}
/**
* New method contributed by: Lubos Strapko
*
* @since 2.1.3
*/
public static float ParseLength(String str, float actualFontSize) {
if (str == null)
return 0f;
int pos = 0;
int length = str.Length;
bool ok = true;
@ -319,6 +386,15 @@ namespace iTextSharp.text.html {
if (str.StartsWith("pc")) {
return f * 12f;
}
// 1em is equal to the current font size
if (str.StartsWith("em")) {
return f * actualFontSize;
}
// one ex is the x-height of a font (x-height is usually about half the
// font-size)
if (str.StartsWith("ex")) {
return f * actualFontSize / 2;
}
// default: we assume the length was measured in points
return f;
}

View File

@ -83,10 +83,10 @@ public class ChainedProperties {
public void AddToChain(String key, Hashtable prop) {
// adjust the font size
String value = (String)prop["size"];
String value = (String)prop[ElementTags.SIZE];
if (value != null) {
if (value.EndsWith("px")) {
prop["size"] = value.Substring(0, value.Length - 2);
prop[ElementTags.SIZE] = value.Substring(0, value.Length - 2);
}
else {
int s = 0;
@ -117,7 +117,7 @@ public class ChainedProperties {
s = 0;
else if (s >= fontSizes.Length)
s = fontSizes.Length - 1;
prop["size"] = fontSizes[s].ToString();
prop[ElementTags.SIZE] = fontSizes[s].ToString();
}
}
chain.Add(new Object[]{key, prop});

View File

@ -68,13 +68,13 @@ namespace iTextSharp.text.html.simpleparser {
foreach (DictionaryEntry dc in temp)
props[dc.Key] = dc.Value;
}
String cm = (String)props["class"];
String cm = (String)props[Markup.HTML_ATTR_CSS_CLASS];
if (cm == null)
return;
map = (Hashtable)classMap[cm.ToLower(System.Globalization.CultureInfo.InvariantCulture)];
if (map == null)
return;
props.Remove("class");
props.Remove(Markup.HTML_ATTR_CSS_CLASS);
temp = new Hashtable(map);
foreach (DictionaryEntry dc in props)
temp[dc.Key] = dc.Value;

View File

@ -105,6 +105,18 @@ public class PdfArray : PdfObject {
Add(values);
}
/**
* Constructs a PdfArray with the elements of an ArrayList.
* Throws a ClassCastException if the ArrayList contains something
* that isn't a PdfObject.
* @param l an ArrayList with PdfObjects
* @since 2.1.3
*/
public PdfArray(ArrayList l) : this() {
foreach (PdfObject o in l)
Add(o);
}
/**
* Constructs an <CODE>PdfArray</CODE>-object, containing all the <CODE>PdfObject</CODE>s in a given <CODE>PdfArray</CODE>.
*

View File

@ -478,7 +478,7 @@ namespace iTextSharp.text.pdf {
* Getter for property table.
* @return Value of property table.
*/
internal PdfPTable Table {
public PdfPTable Table {
get {
return table;
}

View File

@ -137,7 +137,7 @@ namespace iTextSharp.text.pdf {
PdfEncryption crypto = null;
if (writer != null)
crypto = writer.Encryption;
if (crypto != null) {
if (crypto != null && !crypto.IsEmbeddedFilesOnly()) {
b = crypto.EncryptByteArray(b);
}
if (hexWriting) {

View File

@ -4,6 +4,7 @@ using System.Text;
using System.Collections;
using System.util;
using iTextSharp.text.xml.simpleparser;
using iTextSharp.text.html;
/*
* Copyright 2005 by Paulo Soares.
*
@ -212,7 +213,7 @@ namespace iTextSharp.text.pdf.hyphenation {
if (token.Length > 0) {
exception.Add(token.ToString());
}
exception.Add(new Hyphen((String)h["pre"],
exception.Add(new Hyphen((String)h[HtmlTags.PRE],
(String)h["no"],
(String)h["post"]));
currElement = ELEM_HYPHEN;