1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
|
/* November 8, 2006
PLplot driver for SVG 1.1 (http://www.w3.org/Graphics/SVG/)
Copyright (C) 2006 Hazen Babcock
This file is part of PLplot.
PLplot is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PLplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with PLplot; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*---------------------------------------------
// Header files, defines and local variables
//---------------------------------------------
*/
#include <stdarg.h>
#include <math.h>
/* PLplot header files */
#include "plplotP.h"
#include "drivers.h"
/* constants */
#define SVG_Default_X 720
#define SVG_Default_Y 540
/*
// This is a bit arbitrary. I adjusted it to get the graphs to be about
// the same size as the graphs generated by some of the other devices.
*/
#define DPI 90
#define MAX_STRING_LEN 1000
/* local variables */
char* plD_DEVICE_INFO_svg = "svg:Scalable Vector Graphics (SVG 1.1):1:svg:57:svg";
static int canvasXSize = 0;
static int canvasYSize = 0;
static int svgIndent = 0;
static FILE *svgFile;
/* font stuff */
/* Debugging extras */
/*
//-----------------------------------------------
// function declarations
//-----------------------------------------------
*/
/* Functions for writing XML SVG tags to a file */
static void svg_open(char *);
static void svg_open_end(void);
static void svg_attr_value(char *, char *);
static void svg_attr_values(char *, char *, ...);
static void svg_close(char *);
static void svg_general(char *);
static void svg_indent(void);
static void svg_stroke_width(PLStream *);
static void svg_stroke_color(PLStream *);
static void svg_fill_color(PLStream *);
static void svg_fill_background_color(PLStream *);
/* General */
static void poly_line(PLStream *, short *, short *, PLINT, short);
static void write_hex(unsigned char);
static void write_unicode(PLUNICODE);
static short desired_offset(short, double);
static void specify_font(PLUNICODE);
/* String processing */
static void proc_str(PLStream *, EscText *);
/* PLplot interface functions */
void plD_dispatch_init_svg (PLDispatchTable *pdt);
void plD_init_svg (PLStream *);
void plD_line_svg (PLStream *, short, short, short, short);
void plD_polyline_svg (PLStream *, short *, short *, PLINT);
void plD_eop_svg (PLStream *);
void plD_bop_svg (PLStream *);
void plD_tidy_svg (PLStream *);
void plD_state_svg (PLStream *, PLINT);
void plD_esc_svg (PLStream *, PLINT, void *);
/*
//---------------------------------------------------------------------
// dispatch_init_init()
//
// Initialize device dispatch table
//----------------------------------------------------------------------
*/
void plD_dispatch_init_svg(PLDispatchTable *pdt)
{
#ifndef ENABLE_DYNDRIVERS
pdt->pl_MenuStr = "Scalable Vector Graphics (SVG 1.1)";
pdt->pl_DevName = "svg";
#endif
pdt->pl_type = plDevType_FileOriented;
pdt->pl_seq = 57;
pdt->pl_init = (plD_init_fp) plD_init_svg;
pdt->pl_line = (plD_line_fp) plD_line_svg;
pdt->pl_polyline = (plD_polyline_fp) plD_polyline_svg;
pdt->pl_eop = (plD_eop_fp) plD_eop_svg;
pdt->pl_bop = (plD_bop_fp) plD_bop_svg;
pdt->pl_tidy = (plD_tidy_fp) plD_tidy_svg;
pdt->pl_state = (plD_state_fp) plD_state_svg;
pdt->pl_esc = (plD_esc_fp) plD_esc_svg;
}
/*
//---------------------------------------------------------------------
// svg_init()
//
// Initialize device
//----------------------------------------------------------------------
*/
void plD_init_svg(PLStream *pls)
{
pls->termin = 0; /* not an interactive device */
pls->color = 1; /* supports color */
pls->width = 1;
pls->verbose = 1;
pls->bytecnt = 0;
pls->debug = 1;
pls->dev_text = 1; /* handles text */
pls->dev_unicode = 1; /* wants text as unicode */
pls->page = 0;
pls->dev_fill0 = 1; /* supports hardware solid fills */
pls->dev_fill1 = 1;
pls->graphx = GRAPHICS_MODE;
if (!pls->colorset)
pls->color = 1;
/* Set up device parameters */
plP_setpxl(DPI/25.4, DPI/25.4); /* Pixels/mm. */
/* Set the bounds for plotting. default is SVG_Default_X x SVG_Default_Y unless otherwise specified. */
if (pls->xlength <= 0 || pls->ylength <= 0){
canvasXSize = SVG_Default_X;
canvasYSize = SVG_Default_Y;
plP_setphy((PLINT) 0, (PLINT) SVG_Default_X, (PLINT) 0, (PLINT) SVG_Default_Y);
} else {
canvasXSize = pls->xlength;
canvasYSize = pls->ylength;
plP_setphy((PLINT) 0, (PLINT) pls->xlength, (PLINT) 0, (PLINT) pls->ylength);
}
/* Prompt for a file name if not already set */
plOpenFile(pls);
svgFile = pls->OutFile;
svgIndent = 0;
svg_open("document>");
}
/*
//----------------------------------------------------------------------
// svg_bop()
//
// Set up for the next page.
//----------------------------------------------------------------------
*/
void plD_bop_svg(PLStream *pls)
{
pls->page++;
/* write opening svg tag for the new page */
svg_open("svg");
svg_attr_value("xmlns", "http://www.w3.org/2000/svg");
svg_attr_value("version", "1.1");
svg_attr_values("width", "%dcm", (int)((double)canvasXSize/DPI * 2.54));
svg_attr_values("height", "%dcm", (int)((double)canvasYSize/DPI * 2.54));
svg_attr_values("viewBox", "%d %d %d %d", 0, 0, canvasXSize, canvasYSize);
svg_general(">\n");
/*
// set the background by drawing a rectangle that is the size of
// of the canvas and filling it with the background color.
*/
svg_open("rect");
svg_attr_values("x", "%d", 0);
svg_attr_values("y", "%d", 0);
svg_attr_values("width", "%d", canvasXSize);
svg_attr_values("height", "%d", canvasYSize);
svg_attr_value("stroke", "none");
svg_fill_background_color(pls);
svg_open_end();
/*
** invert the coordinate system so that PLplot graphs appear right side up
*/
svg_open("g");
svg_attr_values("transform", "matrix(1 0 0 -1 0 %d)", canvasYSize);
svg_general(">\n");
}
/*
//---------------------------------------------------------------------
// svg_line()
//
// Draw a line in the current color from (x1,y1) to (x2,y2).
//----------------------------------------------------------------------
*/
void plD_line_svg(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
{
svg_open("polyline");
svg_stroke_width(pls);
svg_stroke_color(pls);
svg_attr_value("fill", "none");
/* svg_attr_value("shape-rendering", "crisp-edges"); */
svg_attr_values("points", "%d,%d %d,%d", x1a, y1a, x2a, y2a);
svg_open_end();
}
/*
//---------------------------------------------------------------------
// svg_polyline()
//
// Draw a polyline in the current color.
//---------------------------------------------------------------------
*/
void plD_polyline_svg(PLStream *pls, short *xa, short *ya, PLINT npts)
{
poly_line(pls, xa, ya, npts, 0);
}
/*
//---------------------------------------------------------------------
// svg_eop()
//
// End of page
//---------------------------------------------------------------------
*/
void plD_eop_svg(PLStream *pls)
{
/* write the closing svg tag */
svg_close("g");
svg_close("svg");
}
/*
//---------------------------------------------------------------------
// svg_tidy()
//
// Close graphics file or otherwise clean up.
//---------------------------------------------------------------------
*/
void plD_tidy_svg(PLStream *pls)
{
svg_close("document");
fclose(svgFile);
}
/*
//---------------------------------------------------------------------
// plD_state_svg()
//
// Handle change in PLStream state (color, pen width, fill attribute, etc).
//
// Nothing is done here because these attributes are aquired from
// PLStream for each element that is drawn.
//---------------------------------------------------------------------
*/
void plD_state_svg(PLStream *pls, PLINT op)
{
}
/*
//---------------------------------------------------------------------
// svg_esc()
//
// Escape function.
//---------------------------------------------------------------------
*/
void plD_esc_svg(PLStream *pls, PLINT op, void *ptr)
{
switch (op)
{
case PLESC_FILL: // fill polygon
poly_line(pls, pls->dev_x, pls->dev_y, pls->dev_npts, 1);
break;
case PLESC_HAS_TEXT: // render text
proc_str(pls, (EscText *)ptr);
break;
}
}
/*
//---------------------------------------------------------------------
// poly_line()
//
// Handles drawing filled and unfilled polygons
//---------------------------------------------------------------------
*/
void poly_line(PLStream *pls, short *xa, short *ya, PLINT npts, short fill)
{
int i;
svg_open("polyline");
svg_stroke_width(pls);
svg_stroke_color(pls);
if(fill){
svg_fill_color(pls);
} else {
svg_attr_value("fill", "none");
}
/* svg_attr_value("shape-rendering", "crisp-edges"); */
svg_indent();
fprintf(svgFile, "points=\"");
for (i = 0; i < npts; i++){
fprintf(svgFile, "%d,%d ", xa[i], ya[i]);
if(((i+1)%10) == 0){
fprintf(svgFile,"\n");
svg_indent();
}
}
fprintf(svgFile, "\"/>\n");
svgIndent -= 2;
}
/*
//---------------------------------------------------------------------
// proc_str()
//
// Processes strings for display.
//
// NOTE:
//
// (1) This was tested on Firefox and Camino where it seemed to display
// text properly. However, it isn't obvious to me that these browsers
// conform to the specification. Basically the issue is that some of
// the text properties (i.e. dy) that you specify inside a tspan element
// remain in force until the end of the text element. It would seem to
// me that they should only apply inside the tspan tag. To get around
// this, and because it was easier anyway, I used what is essentially
// a list of tspan tags rather than a tree of tspan tags. Perhaps
// better described as a tree with one branch?
//
// (2) To deal with the some whitespace annoyances, the entire text
// element must be written on a single line. If there are lots of
// format characters then this line might end up being too long
// for some SVG implementations.
//
// (3) Text placement is not ideal. Vertical offset seems to be
// particularly troublesome.
//
// (4) See additional notes in specify_font re. to sans / serif
//
//---------------------------------------------------------------------
*/
void proc_str (PLStream *pls, EscText *args)
{
unsigned char plplot_esc;
short i;
short upDown = 0;
short totalTags = 1;
short ucs4Len = args->unicode_array_len;
short lastOffset = 0;
double ftHt;
PLUNICODE fci;
PLFLT *t = args->xform;
PLUNICODE *ucs4 = args->unicode_array;
/* check that we got unicode */
if(ucs4Len == 0){
printf("Non unicode string passed to SVG driver, ignoring\n");
return;
}
/* get plplot escape character and the current font */
plgesc(&plplot_esc);
plgfci(&fci);
/* determine the font height */
ftHt = 1.5 * pls->chrht * DPI/25.4;
/*
// Apply coordinate transform for text display.
// The transformation also defines the location of the text in x and y.
*/
svg_open("g");
svg_attr_values("transform", "matrix(%f %f %f %f %d %d)", t[0], t[2], -t[1], -t[3], args->x, (int)(args->y - 0.3*ftHt + 0.5));
svg_general(">\n");
/*
//--------------
// open text tag
//--------------
*/
svg_open("text");
/*
** I believe this property to be important, but I'm not sure what the
** right value is.
** In example 2 the numbers are all over the place vertically. Perhaps
** that could be controlled in some way with this parameter?
*/
svg_attr_value("dominant-baseline","no-change");
/*
** The text goes at zero in x since the coordinate transform also
** defined the location of the text
*/
svg_attr_value("x", "0");
svg_attr_value("y", "0");
/* Tentavively removed. The examples, or at least Example 1, seem to expect
the driver to ignore the text baseline, so the baseline adjustment is
now done the text transform is applied above.
// Set the baseline of the string by adjusting the y offset
// Values were arrived at by trial and error. Unfortunately they don't seem to
// right in all cases, presumably due to adjustments being performed by
// my svg renderer.
if (args->base == 2){
// Align to the top of the text, and probably wrong.
svg_attr_values("y", "%d", (int)(0.7*ftHt + 0.5));
}
else if (args->base == 1){
// Align to the bottom of the text.
//
// This was adjusted based on example1 so that the symbols would be centered
// on the line. It is strange that it should have the same value as align
// to the middle of the text.
//
svg_attr_values("y", "%d", (int)(0.3*ftHt + 0.5));
}
else{
// Align to the middle of the text
//
// This was adjusted based on example1 so that the axis label text would be centered
// on the appropriate tick mark. Strangely, some seem to end up on the high side
// and others on the low side. Perhaps this is due rounding to the nearest pixel?
//
svg_attr_values("y", "%d", (int)(0.3*ftHt + 0.5));
}
*/
/* set font color */
svg_fill_color(pls);
/* white space preserving mode */
svg_attr_value("xml:space","preserve");
/* set the font size */
svg_attr_values("font-size","%d", (int)ftHt);
/*
** set the justification, svg only supports 3 options so we round
** appropriately
*/
if (args->just < 0.33)
svg_attr_value("text-anchor", "start"); /* left justification */
else if (args->just > 0.66)
svg_attr_value("text-anchor", "end"); /* right justification */
else
svg_attr_value("text-anchor", "middle"); /* center */
fprintf(svgFile,">");
/* specify the initial font */
specify_font(fci);
/*
//----------------------------------------------------------
// Write the text with formatting
// We just keep stacking up tspan tags, then close them all
// after we have written out all of the text.
//----------------------------------------------------------
*/
i = 0;
while (i < ucs4Len){
if (ucs4[i] < PL_FCI_MARK){ /* not a font change */
if (ucs4[i] != (PLUNICODE)plplot_esc) { /* a character to display */
write_unicode(ucs4[i]);
i++;
continue;
}
i++;
if (ucs4[i] == (PLUNICODE)plplot_esc){ /* a escape character to display */
write_unicode(ucs4[i]);
i++;
continue;
}
else {
if(ucs4[i] == (PLUNICODE)'u'){ /* Superscript */
totalTags++;
upDown++;
fprintf(svgFile,"<tspan dy=\"%d\" font-size=\"%d\">", desired_offset(upDown, ftHt) - lastOffset, (int)(ftHt * pow(0.8, abs(upDown))));
lastOffset = desired_offset(upDown, ftHt);
}
if(ucs4[i] == (PLUNICODE)'d'){ /* Subscript */
totalTags++;
upDown--;
fprintf(svgFile,"<tspan dy=\"%d\" font-size=\"%d\">", desired_offset(upDown, ftHt) - lastOffset, (int)(ftHt * pow(0.8, abs(upDown))));
lastOffset = desired_offset(upDown, ftHt);
}
i++;
}
}
else { /* a font change */
specify_font(ucs4[i]);
totalTags++;
i++;
}
}
/*
//----------------------------------------------
// close out all the tspan tags and the text tag
//----------------------------------------------
*/
for(i=0;i<totalTags;i++){
fprintf(svgFile,"</tspan>");
}
fprintf(svgFile,"\n");
svg_close("text");
svg_close("g");
}
/*
//---------------------------------------------------------------------
// svg_open ()
//
// Used to open a new XML expression, sets the indent level appropriately
//---------------------------------------------------------------------
*/
void svg_open (char *tag)
{
svg_indent();
fprintf(svgFile, "<%s\n", tag);
svgIndent += 2;
}
/*
//---------------------------------------------------------------------
// svg_open_end ()
//
// Used to end the opending of a new XML expression i.e. add
// the final ">".
//---------------------------------------------------------------------
*/
void svg_open_end (void)
{
svg_indent();
fprintf(svgFile, "/>\n");
svgIndent -= 2;
}
/*
//---------------------------------------------------------------------
// svg_attr_value ()
//
// Prints two strings to svgFile as a XML attribute value pair
// i.e. foo="bar"
//---------------------------------------------------------------------
*/
void svg_attr_value (char *attribute, char *value)
{
svg_indent();
fprintf(svgFile, "%s=\"%s\"\n", attribute, value);
}
/*
//---------------------------------------------------------------------
// svg_attr_values ()
//
// Prints a string and a bunch of numbers / strings as a XML attribute
// value pair i.e. foo="0 10 1.0 5.3 bar"
//
// This function is derived from an example in
// "The C Programming Language" by Kernighan and Ritchie.
//
//---------------------------------------------------------------------
*/
void svg_attr_values (char *attribute, char *format, ...)
{
va_list ap;
char *p, *sval;
int ival;
double dval;
svg_indent();
fprintf(svgFile, "%s=\"", attribute);
va_start(ap, format);
for(p=format; *p; p++){
if(*p != '%'){
fprintf(svgFile, "%c", *p);
continue;
}
switch(*++p){
case 'd':
ival = va_arg(ap, int);
fprintf(svgFile, "%d", ival);
break;
case 'f':
dval = va_arg(ap, double);
fprintf(svgFile, "%f", dval);
break;
case 's':
sval = va_arg(ap, char *);
fprintf(svgFile, "%s", sval);
break;
default:
fprintf(svgFile, "%c", *p);
break;
}
}
fprintf(svgFile, "\"\n");
va_end(ap);
}
/*
//---------------------------------------------------------------------
// svg_close ()
//
// Used to close a XML expression, sets the indent level appropriately
//---------------------------------------------------------------------
*/
void svg_close (char *tag)
{
svgIndent -= 2;
svg_indent();
if(strlen(tag) > 0){
fprintf(svgFile, "</%s>\n", tag);
} else {
fprintf(svgFile, "/>\n");
}
}
/*
//---------------------------------------------------------------------
// svg_general ()
//
// Used to print any text into the svgFile
//---------------------------------------------------------------------
*/
void svg_general (char *text)
{
svg_indent();
fprintf(svgFile, "%s", text);
}
/*
//---------------------------------------------------------------------
// svg_indent ()
//
// Indents properly based on the current indent level
//---------------------------------------------------------------------
*/
void svg_indent(void)
{
short i;
for(i=0;i<svgIndent;i++){
fprintf(svgFile, " ");
}
}
/*
//---------------------------------------------------------------------
// svg_stroke_width ()
//
// sets the stroke color based on the current color
//---------------------------------------------------------------------
*/
void svg_stroke_width(PLStream *pls)
{
svg_indent();
fprintf(svgFile, "stroke-width=\"%d\"\n", pls->width);
}
/*
//---------------------------------------------------------------------
// svg_stroke_color ()
//
// sets the stroke color based on the current color
//---------------------------------------------------------------------
*/
void svg_stroke_color(PLStream *pls)
{
svg_indent();
fprintf(svgFile, "stroke=\"#");
write_hex(pls->curcolor.r);
write_hex(pls->curcolor.g);
write_hex(pls->curcolor.b);
fprintf(svgFile, "\"\n");
}
/*
//---------------------------------------------------------------------
// svg_fill_color ()
//
// sets the fill color based on the current color
//---------------------------------------------------------------------
*/
void svg_fill_color(PLStream *pls)
{
svg_indent();
fprintf(svgFile, "fill=\"#");
write_hex(pls->curcolor.r);
write_hex(pls->curcolor.g);
write_hex(pls->curcolor.b);
fprintf(svgFile, "\"\n");
}
/*
//---------------------------------------------------------------------
// svg_fill_background_color ()
//
// sets the background fill color based on the current background color
//---------------------------------------------------------------------
*/
void svg_fill_background_color(PLStream *pls)
{
svg_indent();
fprintf(svgFile, "fill=\"#");
write_hex(pls->cmap0[0].r);
write_hex(pls->cmap0[0].g);
write_hex(pls->cmap0[0].b);
fprintf(svgFile, "\"\n");
}
/*
//---------------------------------------------------------------------
// write_hex ()
//
// writes a unsigned char as an approriately formatted hex value
//---------------------------------------------------------------------
*/
void write_hex(unsigned char val)
{
if(val < 16){
fprintf(svgFile, "0%X", val);
} else {
fprintf(svgFile, "%X", val);
}
}
/*
//---------------------------------------------------------------------
// write_unicode ()
//
// writes a unicode character, appropriately formatted (i.e. &#xNNN)
//---------------------------------------------------------------------
*/
void write_unicode(PLUNICODE ucs4_char)
{
fprintf(svgFile, "&#x%x;", ucs4_char);
}
/*
//---------------------------------------------------------------------
// desired_offset ()
//
// calculate the desired offset given font height and super/subscript level
//---------------------------------------------------------------------
*/
short desired_offset(short level, double ftHt)
{
if(level > 0){
return -level * ftHt * pow(0.6, abs(level));
}
else if(level < 0){
return level * ftHt * pow(0.6, abs(level));
}
else{
return 0;
}
}
/*
//---------------------------------------------------------------------
// specify_font ()
//
// Note:
// We don't actually specify a font, just the fonts properties.
// The hope is that this will give the display program the freedom
// to choose the font with the glyphs that it needs to display
// the text.
//
// Known Issues:
// (1) On OS-X 10.4 with Firefox and Camino the "serif" font-family
// looks more like the "italic" font-style.
//
//---------------------------------------------------------------------
*/
void specify_font(PLUNICODE ucs4_char)
{
fprintf(svgFile,"<tspan ");
// sans, serif, mono, script, symbol
if((ucs4_char&0x00F) == 0x000){
fprintf(svgFile, "font-family=\"sans-serif\" ");
} else if ((ucs4_char&0x00F) == 0x001) {
fprintf(svgFile, "font-family=\"serif\" ");
} else if ((ucs4_char&0x00F) == 0x002) {
fprintf(svgFile, "font-family=\"mono-space\" ");
} else if ((ucs4_char&0x00F) == 0x003) {
fprintf(svgFile, "font-family=\"cursive\" ");
} else if ((ucs4_char&0x00F) == 0x004) {
// this should be symbol, but that doesn't seem to be available
fprintf(svgFile, "font-family=\"sans-serif\" ");
}
/* normal, italic, oblique */
if((ucs4_char&0x0F0) == 0x000){
fprintf(svgFile, "font-style=\"normal\" ");
} else if ((ucs4_char&0x0F0) == 0x010) {
fprintf(svgFile, "font-style=\"italic\" ");
} else if ((ucs4_char&0x0F0) == 0x020) {
fprintf(svgFile, "font-style=\"oblique\" ");
}
/* normal, bold */
if((ucs4_char&0xF00) == 0x000){
fprintf(svgFile, "font-weight=\"normal\">");
} else if ((ucs4_char&0xF00) == 0x100) {
fprintf(svgFile, "font-weight=\"bold\">");
}
}
|