Exemple #1
0
		private void SetPageAnnot(int page_num, Annotate_t render_result)
		{
			if (m_docPages[page_num].Annotate == Annotate_t.UNKNOWN ||
				m_docPages[page_num].Annotate == Annotate_t.COMPUTING)
			{
				if (render_result == Annotate_t.NO_ANNOTATE)
					m_docPages[page_num].Annotate = Annotate_t.NO_ANNOTATE;
				else
				{
					if (m_showannot)
						m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_VISIBLE;
					else
						m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_HIDDEN;
				}
			}
			else
			{
				if (m_docPages[page_num].Annotate != Annotate_t.NO_ANNOTATE)
				{
					if (m_showannot)
						m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_VISIBLE;
					else
						m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_HIDDEN;
				}
			}
		}
Exemple #2
0
        public int RenderPage(int page_num, Byte[] bmp_data, int bmp_width,
			int bmp_height, double scale, bool flipy, bool use_dlist, bool
			get_text, out BlocksText blocks, bool annotation, 
			out Annotate_t annot_type)
        {
            int code;
            blocks = null;
            String blockcolor = "#00FFFFFF";
            String linecolor = "#402572AC";
            /* Debug */
            //blockcolor = "#20FFFF00";

            annot_type = Annotate_t.UNKNOWN;
            if (use_dlist)
            {
                IntPtr dlist = IntPtr.Zero;
                IntPtr annot_dlist = IntPtr.Zero;
                IntPtr text = IntPtr.Zero;
                int num_blocks = 0;

                int page_height = 0;
                int page_width = 0;

                if (get_text)
                {
                    lock (m_lock)
                    {
                        dlist = tc_mCreateDisplayListText(mu_object, page_num,
                            ref page_width, ref page_height, ref text, ref num_blocks);
                    }
                    /* If we have some text go ahead and get the bounding boxes
                     * now. There is likely a better way to do this with passing
                     * a structure across the boundary in a single call.  ToDO */
                    /* Length here is the number of blocks.  mupdf splits block
                     * into lines (spans) and then these into text characters
                     * Our goal here is to get them into a structure that we
                     * can rapidly use in our ui display.  Maintaining the block
                     * and span stucture so that we can minimize the number of
                     * rects that are introduced */
                    if (num_blocks > 0)
                    {
                        blocks = new BlocksText();
                        for (int kk = 0; kk < num_blocks; kk++)
                        {
                            double top_x = 0, top_y = 0, height = 0, width = 0;
                            var block = new TextBlock();

                            int num_lines = tc_mGetTextBlock(text, kk, ref top_x,
                                ref top_y, ref height, ref width);

                            block.X = top_x;
                            block.Y = top_y;
                            block.Width = width;
                            block.Height = height;
                            block.Color = blockcolor;
                            block.Scale = 1.0;
                            block.PageNumber = page_num;
                            blocks.Add(block);

                            blocks[kk].TextLines = new List<TextLine>();
                            for (int jj = 0; jj < num_lines; jj++)
                            {
                                var line = new TextLine();
                                int num_chars = tc_mGetTextLine(text, kk, jj, ref top_x,
                                    ref top_y, ref height, ref width);
                                line.X = top_x;
                                line.Y = top_y;
                                line.Width = width;
                                line.Height = height;
                                line.Scale = 1.0;
                                line.Color = linecolor;
                                blocks[kk].TextLines.Add(line);

                                blocks[kk].TextLines[jj].TextCharacters = new List<TextCharacter>();
                                for (int mm = 0; mm < num_chars; mm++)
                                {
                                    var textchars = new TextCharacter();
                                    int character = tc_mGetTextCharacter(text, kk, jj, mm, ref top_x,
                                        ref top_y, ref height, ref width);
                                    textchars.X = top_x;
                                    textchars.Y = top_y;
                                    textchars.Width = width;
                                    textchars.Height = height;
                                    textchars.Scale = 1.0;
                                    textchars.Color = linecolor;
                                    textchars.character = System.Convert.ToChar(character).ToString();
                                    blocks[kk].TextLines[jj].TextCharacters.Add(textchars);
                                }
                            }
                        }
                        /* We are done with the text object */
                        tc_mReleaseText(mu_object, text);
                    }
                }
                else
                    lock (m_lock)
                    {
                        dlist = tc_mCreateDisplayList(mu_object, page_num,
                            ref page_width, ref page_height);
                    }
                if (annotation)
                {
                    lock (m_lock)
                    {
                        annot_dlist = tc_mCreateDisplayListAnnot(mu_object, page_num);
                        if (annot_dlist == IntPtr.Zero)
                            annot_type = Annotate_t.NO_ANNOTATE;
                        else
                            annot_type = Annotate_t.HAS_ANNOTATE;
                    }
                }

                /* Rendering of display list can occur with other threads so unlock */
                if (dlist == null)
                {
                    return (int) status_t.E_FAILURE;
                }
                code = tc_mRenderPageMT(mu_object, dlist, annot_dlist, page_width,
                    page_height, bmp_data, bmp_width, bmp_height, scale, flipy);
            }
            else
             			{
                lock(m_lock)
                {
                    code = tc_mRenderPage(mu_object, page_num, bmp_data, bmp_width,
                        bmp_height, scale, flipy);
                }
            }
            return code;
        }