Пример #1
0
void
x_gui_rep::prepare_color (int sf, color fg, color bg) {
  int nr_cols= sf*sf;
  if (nr_cols >= 64) nr_cols= 64;
  x_character col_entry (0, font_glyphs (), sf, fg, bg);
  color* cols= (color*) color_scale [col_entry];
  if (cols == NULL) {
    int fR, fG, fB, fA, bR, bG, bB, bA, j;
    get_rgb_color (fg, fR, fG, fB, fA);
    get_rgb_color (bg, bR, bG, bB, bA);
    if (fA != 255) {
      fR= (bR * (255 - fA) + fR * fA) / 255;
      fG= (bG * (255 - fA) + fG * fA) / 255;
      fB= (bB * (255 - fA) + fB * fA) / 255;
    }
    cols= tm_new_array<color> (nr_cols+1);
    for (j=0; j<=nr_cols; j++)
      cols [nr_cols-j]= rgb_color ((bR*j + fR*(nr_cols-j)) / nr_cols,
				   (bG*j + fG*(nr_cols-j)) / nr_cols,
				   (bB*j + fB*(nr_cols-j)) / nr_cols);
    color_scale (col_entry)= (void*) cols;
  }
}
Пример #2
0
void
concater_rep::flag_ok (string s, path ip, color col) {
  path dip = decorate_right (ip);
  SI h= 4*env->fn->wfn/5;
  int r, g, b, a;
  get_rgb_color (col, r, g, b, a);
  //r= 255- (255 - r)/6;
  //g= 255- (255 - g)/6;
  //b= 255- (255 - b)/6;
  a= a/6;
  color light= rgb_color (r, g, b, a);
  int info= env->info_level;
  if (info == INFO_MINIMAL || info == INFO_SHORT || info == INFO_SHORT_PAPER) {
    box infob= info_box (dip, h, pencil (col, env->fn->wline), light);
    if (info == INFO_SHORT_PAPER) {
      box b= resize_box (ip, infob, 0, 0, 0, env->fn->yx);
      print (b);
    }
    else {
      box specb= specific_box (ip, infob, "screen", env->fn);
      print (specb);
    }
  }
  else if (info == INFO_DETAILED || info == INFO_PAPER) {
    int sz= script (env->fn_size, env->index_level+2);
    font gfn (tex_font ("ecrm", sz, (int) (env->magn*env->dpi)));
    box textb= text_box (decorate (ip), 0, s, gfn, col);
    box flagb= flag_box (dip, textb, h, pencil (col, env->fn->wline), light);
    if (info == INFO_DETAILED) {
      box specb= specific_box (ip, flagb, "screen", env->fn);
      print (specb);
    }
    else {
      box b= resize_box (ip, flagb, 0, 0, 0, env->fn->yx);
      print (b);
    }
  }
}
Пример #3
0
string
picture_as_eps (picture pic, int dpi) {
    (void) dpi;
    if (DEBUG_CONVERT) debug_convert<< "in picture_as_eps " <<LF;
    static const char* d= "0123456789ABCDEF";
    int w_pt= pic->get_width (), h_pt= pic->get_height ();
    int ox= pic->get_origin_x (), oy= pic->get_origin_y ();
    string r;

    string sw= as_string (w_pt);
    string sh= as_string (h_pt);
    r << "%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: TeXmacs\n%%BoundingBox: 0 0 "
      << sw << " " << sh
      << "\n\n% Created by picture_as_eps ()\n\n%%BeginProlog\nsave\n"
      << "countdictstack\nmark\nnewpath\n/showpage {} def\n/setpagedevice "
      << "{pop} def\n%%EndProlog\n%%Page 1 1\n"
      << "/max { 2 copy lt { exch } if pop } bind def\n"
      << "/ImageWidth " << sw
      << " def\n/ImageHeight " << sh << " def\nImageWidth ImageHeight max "
      << "ImageWidth ImageHeight max scale\n\n/ImageDatas\n\tcurrentfile\n\t"
      << "<< /Filter /ASCIIHexDecode >>\n\t/ReusableStreamDecode\n\tfilter\n";

    int v, i= 0, j= 0, k= 0, l= 0;
    bool alpha= false;
    for (j=0; j < h_pt; j++)
        for (i=0; i < w_pt; i++) {
            color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
            int rr, gg, bb, aa;
            get_rgb_color (col, rr, gg, bb, aa);
            if (aa != 255) alpha= true;
        }

    string mask;
    for (j= 0; j < h_pt; j++) {
        for (i=0; i < w_pt; i++) {
            l++;
            color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
            int rr, gg, bb, aa;
            get_rgb_color (col, rr, gg, bb, aa);
            rr= (rr * aa + 255 * (255 - aa)) / 255;
            gg= (gg * aa + 255 * (255 - aa)) / 255;
            bb= (bb * aa + 255 * (255 - aa)) / 255;
            r << as_hexadecimal (rr, 2);
            r << as_hexadecimal (gg, 2);
            r << as_hexadecimal (bb, 2);
            if (l > 12) {
                r << "\n";
                l= 0;
            }
        }
        if (alpha) {
            v = 0;
            for (i=0; i < w_pt; i++) {
                color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
                int rr, gg, bb, aa;
                get_rgb_color (col, rr, gg, bb, aa);
                v += (aa <= 32) << (3 - i % 4);
                if (i % 4 == 3 || i + 1 == w_pt) {
                    mask << d[v];
                    v= 0;
                    k++;
                    // Padding of the image data mask
                    if (i + 1 == w_pt && k % 2 == 1) {
                        mask << d[0];
                        k++;
                    }
                    // Code layout
                    if (k >= 78) {
                        mask << "\n";
                        k= 0;
                    }
                }
            }
        }
    }
    r << ">\ndef\n\n";

    if (alpha) {
        r << "/MaskDatas\n\tcurrentfile\n\t<< /Filter /ASCIIHexDecode >>\n"
          << "\t/ReusableStreamDecode\n\tfilter\n"
          << mask
          << ">\ndef\n\n"
          << "/TheMask\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t"
          << "\tImageHeight\n\t/BitsPerComponent 1\n\t/Decode [ 0 1 ]\n\t"
          << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t"
          << "/DataSource MaskDatas\n>> def\n\n";
    }
    r << "/TheImage\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t"
      << "\tImageHeight\n\t/BitsPerComponent 8\n\t/Decode [ 0 1 0 1 0 1 ]\n\t"
      << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t"
      << "/DataSource ImageDatas\n>> def\n\n"
      << "/DeviceRGB setcolorspace\n";
    if (alpha) {
        r << "<<\n\t/ImageType 3\n\t/InterleaveType 3\n\t/DataDict TheImage\n"
          << "\t/MaskDict TheMask\n>>";
    }
    else {
        r << "\tTheImage";
    }
    r << "\nimage\nshowpage\n%%Trailer\ncleartomark\ncountdictstack\n"
      << "exch sub { end } repeat\nrestore\n%%EOF\n";

    return r;
}