comparison man/lispref/glyphs.texi @ 707:a307f9a2021d

[xemacs-hg @ 2001-12-20 05:49:28 by andyp] sync with 21-4-6-windows
author andyp
date Thu, 20 Dec 2001 05:49:48 +0000
parents 576fb035e263
children c6facab13185
comparison
equal deleted inserted replaced
706:c9bf82d465b5 707:a307f9a2021d
34 * Glyph Types:: Each glyph has a particular type. 34 * Glyph Types:: Each glyph has a particular type.
35 * Mouse Pointer:: Controlling the mouse pointer. 35 * Mouse Pointer:: Controlling the mouse pointer.
36 * Redisplay Glyphs:: Glyphs controlling various redisplay functions. 36 * Redisplay Glyphs:: Glyphs controlling various redisplay functions.
37 * Subwindows:: Inserting an externally-controlled subwindow 37 * Subwindows:: Inserting an externally-controlled subwindow
38 into a buffer. 38 into a buffer.
39 * Glyph Examples:: Examples of how to work with glyphs.
39 @end menu 40 @end menu
40 41
41 @node Glyph Functions 42 @node Glyph Functions
42 @section Glyph Functions 43 @section Glyph Functions
43 44
1378 Subwindows are not currently implemented. 1379 Subwindows are not currently implemented.
1379 1380
1380 @defun subwindowp object 1381 @defun subwindowp object
1381 This function returns non-@code{nil} if @var{object} is a subwindow. 1382 This function returns non-@code{nil} if @var{object} is a subwindow.
1382 @end defun 1383 @end defun
1384
1385 @node Glyph Examples
1386 @section Glyph Examples
1387
1388 For many applications, displaying graphics is a simple process: you
1389 create a glyph, and then you insert it into a buffer.
1390
1391 The easiest way to create a glyph is to use a file that contains a
1392 graphical image, such as a JPEG, TIFF, or PNG file:
1393
1394 @lisp
1395 ;; Create a glyph from a JPEG file:
1396 (setq foo (make-glyph [jpeg :file "/tmp/file1.jpg"]))
1397 @end lisp
1398
1399 @lisp
1400 ;; Create a glyph from a XPM file:
1401 (setq foo (make-glyph [xpm :file "/tmp/file2.xpm"]))
1402 @end lisp
1403
1404 @lisp
1405 ;; Create a glyph from a PNG file:
1406 (setq foo (make-glyph [png :file "/tmp/file3.png"]))
1407 @end lisp
1408
1409 @lisp
1410 ;; Create a glyph from a TIFF file:
1411 (setq foo (make-glyph [tiff :file "/tmp/file4.tiff"]))
1412 @end lisp
1413
1414 The parameters passed to @code{make-glyph} are called "Image
1415 Specifiers", and can handle more image types than those shown above.
1416 You can also put the raw image data into a string (e.g., if you put the
1417 contents of a JPEG file into a string), and use that to create a glyph.
1418 @xref{Image Specifiers}, for more information.
1419
1420 @quotation
1421 @strong{Caution}: In order for XEmacs to read a particular graphics file
1422 format, support for that format must have been compiled into XEmacs.
1423 It's possible, although somewhat unlikely, for XEmacs to have been
1424 compiled without support for any of the various graphics file formats.
1425 To see what graphics formats your particular version of XEmacs supports,
1426 use @kbd{M-x describe-installation}.
1427
1428 To programmatically query whether or not a particular file format is
1429 supported, you can use the @code{featurep} function, with one of:
1430 @code{gif}, @code{tiff}, @code{jpeg}, @code{xpm}, @code{xbm},
1431 @code{png}, or @code{xface}. For an up-to-date list, @ref{Image
1432 Specifiers}. Example:
1433
1434 @example
1435 ;; Returns `t' if TIFF is supported:
1436 (featurep 'tiff)
1437 @end example
1438
1439 Another example is:
1440
1441 @example
1442 ;; Returns a list of `t' or `nil', depending on whether or not the
1443 ;; corresponding feature is supported:
1444 (mapcar #'(lambda (format-symbol) (featurep format-symbol))
1445 '(gif tiff jpeg xpm png))
1446 @end example
1447
1448 @end quotation
1449
1450 Once you have a glyph, you can then insert it into a buffer. Example:
1451
1452 @lisp
1453 ;; Use this function to insert a glyph at the left edge of point in the
1454 ;; current buffer. Any existing glyph at this location is replaced.
1455 (defun insert-glyph (gl)
1456 "Insert a glyph at the left edge of point."
1457 (let ( (prop 'myimage) ;; myimage is an arbitrary name, chosen
1458 ;; to (hopefully) not conflict with any
1459 ;; other properties. Change it if
1460 ;; necessary.
1461 extent )
1462 ;; First, check to see if one of our extents already exists at
1463 ;; point. For ease-of-programming, we are creating and using our
1464 ;; own extents (multiple extents are allowed to exist/overlap at the
1465 ;; same point, and it's quite possible for other applications to
1466 ;; embed extents in the current buffer without your knowledge).
1467 ;; Basically, if an extent, with the property stored in "prop",
1468 ;; exists at point, we assume that it is one of ours, and we re-use
1469 ;; it (this is why it is important for the property stored in "prop"
1470 ;; to be unique, and only used by us).
1471 (if (not (setq extent (extent-at (point) (current-buffer) prop)))
1472 (progn
1473 ;; If an extent does not already exist, create a zero-length
1474 ;; extent, and give it our special property.
1475 (setq extent (make-extent (point) (point) (current-buffer)))
1476 (set-extent-property extent prop t)
1477 ))
1478 ;; Display the glyph by storing it as the extent's "begin-glyph".
1479 (set-extent-property extent 'begin-glyph gl)
1480 ))
1481
1482 ;; You can then use this function like:
1483 (insert-glyph (make-glyph [jpeg :file "/tmp/file1.jpg"]))
1484 ;; This will insert the glyph at point.
1485
1486 ;; Here's an example of how to insert two glyphs side-by-side, at point
1487 ;; (using the above code):
1488 (progn
1489 (insert-glyph (make-glyph [jpeg :file "/tmp/file1.jpg"]))
1490 ;; Create a new extent at point. We can't simply call "insert-glyph",
1491 ;; as "insert-glyph" will simply replace the first glyph with the
1492 ;; second.
1493 (setq extent (make-extent (point) (point) (current-buffer)))
1494 ;; Here, we're only setting the 'myimage property in case we need
1495 ;; to later identify/locate/reuse this particular extent.
1496 (set-extent-property extent 'myimage t)
1497 (set-extent-property extent 'begin-glyph
1498 (make-glyph [jpeg :file "/tmp/file2.jpg"]))
1499 )
1500
1501 @end lisp
1502
1503 Here are the gory details:
1504
1505 @itemize @bullet
1506
1507 @item
1508 Glyphs are displayed by attaching them to extents (see @ref{Extents}),
1509 either to the beginning or the end of extents.
1510
1511 Note that extents can be used for many things, and not just for
1512 displaying images (although, in the above example, we are creating our
1513 own extent for the sole purpose of displaying an image). Also, note
1514 that multiple extents are allowed to exist at the same position, and
1515 they can overlap.
1516
1517 @item
1518 Glyphs are often displayed inside the text area (alongside text). This
1519 is the default.
1520
1521 Although glyphs can also be displayed in the margins, how to do this
1522 will not be described here. For more information on this, see
1523 @ref{Annotation Basics} (look for information on "layout types") and
1524 @ref{Extent Properties} (look for @code{begin-glyph-layout} and
1525 @code{end-glyph-layout}).
1526
1527 @item
1528 The easiest way to insert a glyph into text is to create a zero-length
1529 extent at the point where you want the glyph to appear.
1530
1531 Note that zero-length extents are attached to the character to the
1532 right of the extent; deleting this character will also delete the extent.
1533
1534 @item
1535 It's often a good idea to assign a unique property to the newly-created
1536 extent, in case you later want to locate it, and replace any existing
1537 glyph with a different one (or just delete the existing one). In the
1538 above example, we are using "myimage" as our (hopefully) unique property
1539 name.
1540
1541 If you need to locate all of the extents, you'll have to use functions
1542 like @code{extent-list} or @code{next-extent}, or provide additional
1543 parameters to the @code{extent-at} function. Assigning a unique
1544 property to the extent makes it easy to locate your extents; for
1545 example, @code{extent-list} can return only those extents with a
1546 particular property. @xref{Finding Extents}, and @ref{Mapping Over
1547 Extents}, for more information.
1548
1549 @item
1550 Glyphs are displayed by assigning then to the @code{begin-glyph} or
1551 @code{end-glyph} property of the extent. For zero-length extents, it
1552 doesn't really matter if you assign the glyph to the @code{begin-glyph}
1553 or @code{end-glyph} property, as they are both at the same location;
1554 however, for non-zero-length extents (extents that cover one or more
1555 characters of text), it does matter which one you use.
1556
1557 Assigning @code{nil} to the @code{begin-glyph} or @code{end-glyph}
1558 property will delete any existing glyph. In this case, you may also
1559 want to delete the extent, assuming that the extent is used for no other
1560 purpose.
1561
1562 @item
1563 If you happen to insert two glyphs, side-by-side, note that the example
1564 @code{insert-glyph} function will have trouble, if it's again used at
1565 the same point (it can only locate one of the two extents).
1566 @xref{Finding Extents}, and @ref{Mapping Over Extents}, for more
1567 information on locating extents in a buffer.
1568
1569 @item
1570 Among other things, glyphs provide a way of displaying graphics
1571 alongside text. Note, however, that glyphs only provide a way of
1572 displaying graphics; glyphs are not actually part of the text, and are
1573 only displayed alongside the text. If you save the text in the buffer,
1574 the graphics are not saved. The low-level glyph code does not provide a
1575 way of saving graphics with the text. If you need to save graphics and
1576 text, you have to write your own code to do this, and this topic is
1577 outside the scope of this discussion.
1578
1579 @end itemize