From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Printing Date: Fri, 04 May 2012 23:06:43 -0400 Message-ID: References: <5f0660120903280331y780c80b7i57a8115dc4b029eb@mail.gmail.com> <49CE3A84.9070705@swipnet.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336187219 7576 80.91.229.3 (5 May 2012 03:06:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 5 May 2012 03:06:59 +0000 (UTC) Cc: emacs-devel@gnu.org To: YAMAMOTO Mitsuharu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 05 05:06:59 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SQVKi-0003Hs-Vg for ged-emacs-devel@m.gmane.org; Sat, 05 May 2012 05:06:57 +0200 Original-Received: from localhost ([::1]:38300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQVKi-0000EU-7f for ged-emacs-devel@m.gmane.org; Fri, 04 May 2012 23:06:56 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQVKd-00005P-Rq for emacs-devel@gnu.org; Fri, 04 May 2012 23:06:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SQVKa-0004G6-6J for emacs-devel@gnu.org; Fri, 04 May 2012 23:06:51 -0400 Original-Received: from ironport-out.teksavvy.com ([206.248.143.162]:47420) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQVKa-0004Fj-0r for emacs-devel@gnu.org; Fri, 04 May 2012 23:06:48 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApYIACxOgk9MCqD5/2dsb2JhbABDDrgVA4EMgQiCCQEBBAFWIwULCzQSFBgNJBOICQW2MothhHkEpEWBXYIwUw X-IronPort-AV: E=Sophos;i="4.75,391,1330923600"; d="scan'208";a="178435180" Original-Received: from 76-10-160-249.dsl.teksavvy.com (HELO ceviche.home) ([76.10.160.249]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 04 May 2012 23:06:44 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 15F9866109; Fri, 4 May 2012 23:06:43 -0400 (EDT) In-Reply-To: (YAMAMOTO Mitsuharu's message of "Sun, 19 Apr 2009 19:21:16 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.143.162 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150264 Archived-At: Hi, I'd be interested to see this pushed further. Maybe you could make a branch in the bzr repository for it? Stefan >>>>> "YAMAMOTO" == YAMAMOTO Mitsuharu writes: >>>>> On Tue, 07 Apr 2009 18:46:01 +0900, YAMAMOTO Mitsuharu said: >>>> I tried making a really preliminary proof-of-concept cairo port. :-) >>>> It's still rough and has several glitches/limitations, but at least >>>> it can generate a "resolution-independent screenshot" PDF as >>>> attached. Maybe I'll clean up the code this weekend and hopefully >>>> post a patch. >>> Here's the patch for the Emacs 23.0.92 pretest (not the trunk HEAD). >>> * No configure support. The easiest way would be to compile it with >>> the GTK+ support that is already linked with cairo libs. Add >>> -DUSE_CAIRO to CFLAGS to activate the cairo code. >>> * Currently, texts, rectangles (filling and stroking), and trapezoids >>> for reliefs are drawn using cairo by hooking the corresponding >>> drawing routine calls in xterm.c. > This time, I combined the cairo drawing code with GTK+ print dialogs > code, which is actually almost the same as examples in the GTK+ > reference. The added primitives are: > (x-page-setup-dialog): Pop up a page setup dialog. > (x-get-page-setup): Return the value of the current page setup. > It returns an alist like > ((orientation . portrait) > (width . 559.2755905511812) (height . 783.5697637795276) > (left-margin . 18.0) (right-margin . 18.0) > (top-margin . 18.0) (bottom-margin . 40.32000000000001)) > (x-print-frames-dialog FRAMES): Pop up a print dialog to print the > current contents of FRAMES. > The last one is intended to be called after some pagination (in Lisp) > that creates a frame per page. Below is a simple example. > (defun test-print-buffer (buffer-or-name) > "Paginate and print buffer contents." > (interactive "bBuffer to export:") > (with-current-buffer buffer-or-name > (let* ((buffer (current-buffer)) > (start-pos (point-min)) > (end-pos (point-max)) > (page-setup (if (fboundp 'x-get-page-setup) > (x-get-page-setup) > '((width . 559.0) (height . 783.0)))) > (width-in-points (cdr (assq 'width page-setup))) > (height-in-points (cdr (assq 'height page-setup))) > buffers frames) > (unwind-protect > (progn > (with-selected-frame (selected-frame) > ;; Paginate and create a frame for each page. > (while (< start-pos end-pos) > (let ((inhibit-quit t)) > (set-buffer > (make-indirect-buffer > buffer (generate-new-buffer-name (buffer-name buffer)) t)) > (push (current-buffer) buffers) > (setq kill-buffer-hook nil) ;; XXX > (select-frame (make-frame > '((internal-border-width . 0) > (vertical-scroll-bars . nil) > (left-fringe . 0) (right-fringe . 0) > (menu-bar-lines . 0) (tool-bar-lines . 0) > (line-spacing . 0) > (minibuffer . nil) (visibility . nil) > (cursor-type . nil))) > 'norecord) > (push (selected-frame) frames)) > (set-frame-size (selected-frame) > (floor (/ width-in-points (frame-char-width))) > (floor (/ height-in-points (frame-char-height)))) > (setq header-line-format nil) > (setq mode-line-format nil) > (set-window-start nil start-pos) > (goto-char (window-end nil t)) > (while (and (< start-pos (point)) > (not (pos-visible-in-window-p (1- (point))))) > (backward-char)) > (narrow-to-region start-pos (point)) > (setq start-pos (point)))) > ;; Print the frames. > (if (null frames) > (error "Buffer %s is empty" buffer-or-name) > (mapc 'make-frame-visible frames) > (if (fboundp 'x-print-frames-dialog) > (x-print-frames-dialog (reverse frames)) > ;; Dummy stub just to reproduce an intermittent error > ;; in x-print-frames-dialog even without it. > (dolist (frame frames) > (unless (eq (frame-visible-p frame) t) > (error "Frames to be printed must be visible."))) > (redisplay t)))) > ;; Clean up > (mapc 'delete-frame frames) > (mapc 'kill-buffer buffers))))) > You can try printing with M-x test-print-buffer RET. Because the > current cairo drawing routines are hooked onto those in xterm.c in > order to minimize the change, you'll see the actual frames on screen. > Moreover, you might get an incorrect printed result because your > window manager may clip the frames to fit in the screen size. > Nevertheless, I think you can get the basic idea with this sample > code. > YAMAMOTO Mitsuharu > mituharu@math.s.chiba-u.ac.jp