/// <summary> /// Adds a Chunk. /// </summary> /// <remarks> /// This method is a hack to solve a problem I had with phrases that were split between chunks /// in the wrong place. /// </remarks> /// <param name="chunk">a Chunk</param> /// <returns>a bool</returns> virtual protected bool AddChunk(Chunk chunk) { Font f = chunk.Font; String c = chunk.Content; if (font != null && !font.IsStandardFont()) { f = font.Difference(chunk.Font); } if (Count > 0 && !chunk.HasAttributes()) { try { Chunk previous = (Chunk)this[Count - 1]; PdfName previousRole = previous.Role; PdfName chunkRole = chunk.Role; Boolean sameRole; if (previousRole == null || chunkRole == null) { //Set the value to true if either are null since the overwriting of the role will not matter sameRole = true; } else { sameRole = previousRole.Equals(chunkRole); } if (sameRole && !previous.HasAttributes() && !chunk.HasAccessibleAttributes() && !previous.HasAccessibleAttributes() && (f == null || f.CompareTo(previous.Font) == 0) && previous.Font.CompareTo(f) == 0 && !"".Equals(previous.Content.Trim()) && !"".Equals(c.Trim())) { previous.Append(c); return(true); } } catch { } } Chunk newChunk = new Chunk(c, f); newChunk.Attributes = chunk.Attributes; newChunk.role = chunk.Role; newChunk.accessibleAttributes = chunk.GetAccessibleAttributes(); if (hyphenation != null && newChunk.GetHyphenation() == null && !newChunk.IsEmpty()) { newChunk.SetHyphenation(hyphenation); } base.Add(newChunk); return(true); }
/** * Applies the properties of the Anchor to a Chunk. * @param chunk the Chunk (part of the Anchor) * @param notGotoOK if true, this chunk will determine the local destination * @param localDestination true if the chunk is a local goto and the reference a local destination * @return the value of notGotoOK or false, if a previous Chunk was used to determine the local destination */ virtual protected bool ApplyAnchor(Chunk chunk, bool notGotoOK, bool localDestination) { if (name != null && notGotoOK && !chunk.IsEmpty()) { chunk.SetLocalDestination(name); notGotoOK = false; } if (localDestination) { chunk.SetLocalGoto(reference.Substring(1)); } else if (reference != null) { chunk.SetAnchor(reference); } return(notGotoOK); }
/// <summary> /// Adds a Chunk, an Anchor or another Phrase /// to this Phrase. /// </summary> /// <param name="index">index at which the specified element is to be inserted</param> /// <param name="o">an object of type Chunk, Anchor, or Phrase</param> public virtual void Add(int index, object o) { if (o == null) { return; } try { IElement element = (IElement)o; if (element.Type == Element.CHUNK) { Chunk chunk = (Chunk)element; if (!font.IsStandardFont()) { chunk.Font = font.Difference(chunk.Font); } if (hyphenation != null && chunk.GetHyphenation() == null && !chunk.IsEmpty()) { chunk.SetHyphenation(hyphenation); } Insert(index, chunk); } else if (element.Type == Element.PHRASE || element.Type == Element.ANCHOR || element.Type == Element.ANNOTATION || element.Type == Element.TABLE || // line added by David Freels element.Type == Element.YMARK || element.Type == Element.MARKED) { Insert(index, element); } else { throw new Exception(element.Type.ToString()); } } catch (Exception cce) { throw new Exception("Insertion of illegal Element: " + cce.Message); } }
/// <summary> /// Adds a Chunk. /// </summary> /// <remarks> /// This method is a hack to solve a problem I had with phrases that were split between chunks /// in the wrong place. /// </remarks> /// <param name="chunk">a Chunk</param> /// <returns>a bool</returns> virtual protected bool AddChunk(Chunk chunk) { Font f = chunk.Font; String c = chunk.Content; if (font != null && !font.IsStandardFont()) { f = font.Difference(chunk.Font); } if (Count > 0 && !chunk.HasAttributes()) { try { Chunk previous = (Chunk)this[Count - 1]; if (!previous.HasAttributes() && !chunk.HasAccessibleAttributes() && (f == null || f.CompareTo(previous.Font) == 0) && previous.Font.CompareTo(f) == 0 && !"".Equals(previous.Content.Trim()) && !"".Equals(c.Trim())) { previous.Append(c); return(true); } } catch { } } Chunk newChunk = new Chunk(c, f); newChunk.Attributes = chunk.Attributes; newChunk.role = chunk.Role; newChunk.accessibleAttributes = chunk.GetAccessibleAttributes(); if (hyphenation != null && newChunk.GetHyphenation() == null && !newChunk.IsEmpty()) { newChunk.SetHyphenation(hyphenation); } base.Add(newChunk); return(true); }
// overriding some of the ArrayList-methods /// <summary> /// Adds a Chunk, an Anchor or another Phrase /// to this Phrase. /// </summary> /// <param name="index">index at which the specified element is to be inserted</param> /// <param name="o">an object of type Chunk, Anchor, or Phrase</param> public virtual void Add(int index, IElement element) { if (element == null) { return; } switch (element.Type) { case Element.CHUNK: Chunk chunk = (Chunk)element; if (!font.IsStandardFont()) { chunk.Font = font.Difference(chunk.Font); } if (hyphenation != null && chunk.GetHyphenation() == null && !chunk.IsEmpty()) { chunk.SetHyphenation(hyphenation); } base.Insert(index, chunk); return; case Element.PHRASE: case Element.PARAGRAPH: case Element.MARKED: case Element.DIV: case Element.ANCHOR: case Element.ANNOTATION: case Element.PTABLE: case Element.LIST: case Element.YMARK: case Element.WRITABLE_DIRECT: base.Insert(index, element); return; default: throw new Exception(MessageLocalization.GetComposedMessage("insertion.of.illegal.element.1", element.Type.ToString())); } }
// overriding some of the ArrayList-methods /// <summary> /// Adds a Chunk, an Anchor or another Phrase /// to this Phrase. /// </summary> /// <param name="index">index at which the specified element is to be inserted</param> /// <param name="o">an object of type Chunk, Anchor, or Phrase</param> public virtual void Add(int index, Object o) { if (o == null) { return; } try { IElement element = (IElement)o; if (element.Type == Element.CHUNK) { Chunk chunk = (Chunk)element; if (!font.IsStandardFont()) { chunk.Font = font.Difference(chunk.Font); } if (hyphenation != null && chunk.GetHyphenation() == null && !chunk.IsEmpty()) { chunk.SetHyphenation(hyphenation); } base.Insert(index, chunk); } else if (element.Type == Element.PHRASE || element.Type == Element.ANCHOR || element.Type == Element.ANNOTATION || element.Type == Element.YMARK || element.Type == Element.MARKED) { base.Insert(index, element); } else { throw new Exception(element.Type.ToString()); } } catch (Exception cce) { throw new Exception(MessageLocalization.GetComposedMessage("insertion.of.illegal.element.1", cce.Message)); } }
/// <summary> /// Adds a Chunk. /// </summary> /// <remarks> /// This method is a hack to solve a problem I had with phrases that were split between chunks /// in the wrong place. /// </remarks> /// <param name="chunk">a Chunk</param> /// <returns>a bool</returns> protected bool AddChunk(Chunk chunk) { Font f = chunk.Font; String c = chunk.Content; if (font != null && !font.IsStandardFont()) { f = font.Difference(chunk.Font); } if (Count > 0 && !chunk.HasAttributes()) { try { Chunk previous = (Chunk) this[Count - 1]; if (!previous.HasAttributes() && (f == null || f.CompareTo(previous.Font) == 0) && previous.Font.CompareTo(f) == 0 && !"".Equals(previous.Content.Trim()) && !"".Equals(c.Trim())) { previous.Append(c); return true; } } catch { } } Chunk newChunk = new Chunk(c, f); newChunk.Attributes = chunk.Attributes; if (hyphenation != null && newChunk.GetHyphenation() == null && !newChunk.IsEmpty()) { newChunk.SetHyphenation(hyphenation); } base.Add(newChunk); return true; }
/** * Applies the properties of the Anchor to a Chunk. * @param chunk the Chunk (part of the Anchor) * @param notGotoOK if true, this chunk will determine the local destination * @param localDestination true if the chunk is a local goto and the reference a local destination * @return the value of notGotoOK or false, if a previous Chunk was used to determine the local destination */ protected bool ApplyAnchor(Chunk chunk, bool notGotoOK, bool localDestination) { if (name != null && notGotoOK && !chunk.IsEmpty()) { chunk.SetLocalDestination(name); notGotoOK = false; } if (localDestination) { chunk.SetLocalGoto(reference.Substring(1)); } else if (reference != null) chunk.SetAnchor(reference); return notGotoOK; }