SetHyphenation() публичный Метод

sets the hyphenation engine to this Chunk.
public SetHyphenation ( IHyphenationEvent hyphenation ) : Chunk
hyphenation IHyphenationEvent the hyphenation engine
Результат Chunk
Пример #1
0
 public Chunk CreateChunk(String text, ChainedProperties props) {
     Font font = GetFont(props);
     float size = font.Size;
     size /= 2;
     Chunk ck = new Chunk(text, font);
     if (props.HasProperty("sub"))
         ck.SetTextRise(-size);
     else if (props.HasProperty("sup"))
         ck.SetTextRise(size);
     ck.SetHyphenation(GetHyphenation(props));
     return ck;
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
 /// <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);
     }
 }
Пример #4
0
        /// <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);
        }
Пример #5
0
        // 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()));
            }
        }
Пример #6
0
        // 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));
            }
        }
Пример #7
0
     /// <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;
     }
Пример #8
0
 /**
  * Creates an iText Chunk
  * @param content the content of the Chunk
  * @param chain the hierarchy chain
  * @return a Chunk
  */
 public Chunk CreateChunk(String content, ChainedProperties chain) {
     Font font = GetFont(chain);
     Chunk ck = new Chunk(content, font);
     if (chain.HasProperty(HtmlTags.SUB))
         ck.SetTextRise(-font.Size / 2);
     else if (chain.HasProperty(HtmlTags.SUP))
         ck.SetTextRise(font.Size / 2);
     ck.SetHyphenation(GetHyphenation(chain));
     return ck;
 }
Пример #9
0
        // ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document(
              new Rectangle(240, 240), 10, 10, 10, 10
            ))
            {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                // create a long Stringbuffer with movie titles
                StringBuilder sb = new StringBuilder();
                IEnumerable<Movie> movies = PojoFactory.GetMovies(1);
                foreach (Movie movie in movies)
                {
                    // replace spaces with non-breaking spaces
                    sb.Append(movie.MovieTitle.Replace(' ', '\u00a0'));
                    // use pipe as separator
                    sb.Append('|');
                }
                // Create a first chunk
                Chunk chunk1 = new Chunk(sb.ToString());
                // wrap the chunk in a paragraph and add it to the document
                Paragraph paragraph = new Paragraph("A:\u00a0");
                paragraph.Add(chunk1);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.Add(Chunk.NEWLINE);
                // define the pipe character as split character
                chunk1.SetSplitCharacter(new PipeSplitCharacter());
                // wrap the chunk in a second paragraph and add it
                paragraph = new Paragraph("B:\u00a0");
                paragraph.Add(chunk1);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.Add(Chunk.NEWLINE);

                // create a new StringBuffer with movie titles
                sb = new StringBuilder();
                foreach (Movie movie in movies)
                {
                    sb.Append(movie.MovieTitle);
                    sb.Append('|');
                }
                // Create a second chunk 
                Chunk chunk2 = new Chunk(sb.ToString());
                // wrap the chunk in a paragraph and add it to the document
                paragraph = new Paragraph("C:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.NewPage();
                // define hyphenation for the chunk
                chunk2.SetHyphenation(new HyphenationAuto("en", "US", 2, 2));
                // wrap the second chunk in a second paragraph and add it
                paragraph = new Paragraph("D:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);

                // go to a new page
                document.NewPage();
                // define a new space/char ratio
                writer.SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO;
                // wrap the second chunk in a third paragraph and add it
                paragraph = new Paragraph("E:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
            }
        }