Fl_GDI_Printer.cxx 18 KB
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
//
// "$Id: Fl_GDI_Printer.cxx,v 1.1 2004/11/24 20:31:46 cursorstar Exp $"
//
// WIN32 GDI printing device for the Fast Light Tool Kit (FLTK).
//
// Copyright (c) 2002  O'ksi'D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
//
// Please report all bugs and problems to "oksid@bluewin.ch".
//
#include <stdlib.h>
#include <math.h>
#include <FL/Fl.H>
#include <windows.h>
#include <wingdi.h>
#include <FL/math.h>

#include <FL/Fl_GDI_Printer.H>
//#include <commdlg.h>
#include <FL/x.H>
#include <FL/fl_draw.H>

//#include <FL/Fl_Group.H>



extern FL_EXPORT void set_xmaps(HPEN tmppen_, HBRUSH tmpbrush_, HPEN savepen_, Fl_Brush *brushes_, Fl_XMap * fl_xmap_, Fl_XMap xmap_);
extern FL_EXPORT void pop_xmaps();
extern FL_EXPORT void push_xmaps();


Fl_GDI_Printer::~Fl_GDI_Printer(){

  
  if(nPages)
      EndPage(gc_);
  EndDoc(gc_);

  // cleaning pens&brushes...
  if(xmap.pen)
    DeleteObject((HGDIOBJ)(xmap.pen));
  int i;
  for(i=0; i<256; i++)
    if(fl_xmap[i].pen)
      DeleteObject((HGDIOBJ)(fl_xmap[i].pen));

  for(i=0; i<FL_N_BRUSH; i++)
  if(brushes[i].brush)
    DeleteObject(brushes[i].brush);
  //end clean
  
  DeleteDC(gc_);
  if(!GlobalUnlock(mode_))
    GlobalFree(mode_);
}


extern HDC fl_gc_save;

Fl_Output_Device * Fl_GDI_Printer::set_current(){
  if(fl == this) return this;
  Fl_Output_Device * c = fl;
  if(fl == &fltk){
    fl_gc_save = fl_gc;
    Fl::flush();
    push_xmaps();
  }
  set_xmaps(tmppen, tmpbrush, savepen, brushes, fl_xmap, xmap);
  fl = this;
  fl_gc = gc_;
  fl_clip_region(0);
  return c;
}




void Fl_GDI_Printer::draw(Fl_Widget * w){
  Fl_Output_Device * cd =fl;
  set_current();

  w->redraw(); // making dirty

  w->draw();

  Fl_Output_Device::current(cd);
}





////////////// gets the paper size from DEVMODE /////////////////////

static int gdipaper(DEVMODE  *mod){
  if(!(mod->dmFields & DM_PAPERSIZE)) return 0;

  int paper;
  switch (mod->dmPaperSize){
    case DMPAPER_A3:
      paper = Fl_Printer::A3; break;
    case DMPAPER_A4:
      paper = Fl_Printer::A4; break;
    case DMPAPER_A5:
      paper = Fl_Printer::A5; break;
    //case DMPAPER_A6: paper = FL_A6; break;
    case DMPAPER_B4:
      paper = Fl_Printer::B4; break;
    case DMPAPER_B5: paper = Fl_Printer::B5; break;
    //case DMPAPER_B6: paper = FL_B6; break;
    case DMPAPER_EXECUTIVE:
      paper = Fl_Printer::EXECUTIVE; break;
    case DMPAPER_FOLIO:
      paper = Fl_Printer::FOLIO; break;
    case DMPAPER_LEDGER:
      paper = Fl_Printer::LEDGER; break;
    case DMPAPER_LEGAL:
      paper = Fl_Printer::LEGAL; break;
    case DMPAPER_LETTER:
      paper = Fl_Printer::LETTER; break;
    case DMPAPER_TABLOID:
      paper = Fl_Printer::TABLOID; break;
    case DMPAPER_ENV_10:
      paper = Fl_Printer::ENVELOPE; break;
    default:
      paper = -1;
  }
  return paper;
}

////////////// sets the paper size in DEVMODE /////////////////////

static int gdipaper(DEVMODE  *mode, int format){
  switch(format){
    case Fl_Printer::A3: mode->dmPaperSize = DMPAPER_A3; break;
    case Fl_Printer::A4: mode->dmPaperSize = DMPAPER_A4; break;
    case Fl_Printer::A5: mode->dmPaperSize = DMPAPER_A5; break;

    case Fl_Printer::B4: mode->dmPaperSize = DMPAPER_B4; break;
    case Fl_Printer::B5: mode->dmPaperSize = DMPAPER_B5; break;

    case Fl_Printer::EXECUTIVE: mode->dmPaperSize = DMPAPER_EXECUTIVE; break;
    case Fl_Printer::FOLIO: mode->dmPaperSize = DMPAPER_FOLIO; break;
    case Fl_Printer::LEDGER: mode->dmPaperSize = DMPAPER_LEDGER; break;
    case Fl_Printer::LEGAL: mode->dmPaperSize = DMPAPER_LEGAL; break;
    case Fl_Printer::LETTER: mode->dmPaperSize = DMPAPER_LETTER; break;
    case Fl_Printer::TABLOID: mode->dmPaperSize = DMPAPER_TABLOID; break;
    case Fl_Printer::ENVELOPE: mode->dmPaperSize = DMPAPER_ENV_9; break;
    default: return -1;
  }
  return 0;
}


//////////////////////////////////////////////////////////////////////////////////////////////

Fl_GDI_Printer::Fl_GDI_Printer(HDC gc, DEVMODE * mode ):Fl_Printer(),/*delete_mode_(0),*/ style_(0),width_(0),dashes_(0),mask(0){
  
  gc_=gc;

  static DOCINFO DocInfo = { sizeof(DOCINFO), "FLTK Document", NULL,0 };// declare DocInfo for use and set the name of the print job as 'Name Of Document'
  mode_  = (DEVMODE *)GlobalLock(mode);
  int orientation_ = 0;
  if(mode_->dmOrientation==DMORIENT_LANDSCAPE)
    orientation_ = 1;
  int paper;
  if(mode_->dmFields & DM_PAPERSIZE){
    paper = gdipaper(mode_);
    if(mode_->dmOrientation == DMORIENT_PORTRAIT){
      pw_ = Fl_Printer::page_formats[paper][0];
      ph_ = Fl_Printer::page_formats[paper][1];
    }else{
      pw_ = Fl_Printer::page_formats[paper][1];
      ph_ = Fl_Printer::page_formats[paper][0];
    }
  }

  ResetDC(gc_,mode_);
  //GlobalUnlock(mode_);
  SetMapMode(gc_, MM_ANISOTROPIC);
  SetTextAlign(gc_, TA_BASELINE|TA_LEFT);
  SetBkMode(gc_, TRANSPARENT);
  StartDoc(gc_, &DocInfo);
  ix = GetDeviceCaps(gc_, LOGPIXELSX);
  iy = GetDeviceCaps(gc_, LOGPIXELSY);
  ox = GetDeviceCaps(gc_, PHYSICALOFFSETX);
  oy = GetDeviceCaps(gc_, PHYSICALOFFSETY);
  if(ix<iy)
	  max_res_=ix;
  else
	  max_res_=iy;

  nPages = 0;

  int i;
  // Unlike for static vars, here I have to zero the memory
  for(i=0;i<FL_N_BRUSH;i++){
    brushes[i].brush = 0;
    brushes[i].usage = 0;
    brushes[i].backref = 0;
  }
  tmppen = 0;
  tmpbrush = 0;
  savepen = 0;
  for(i=0;i<256;i++){
    fl_xmap[i].rgb = 0;
    fl_xmap[i].pen = 0;	// pen, 0 if none created yet
    fl_xmap[i].brush = 0;
  }
  xmap.rgb=0;
  xmap.brush =0;
  xmap.pen = 0;
  type_ = 0x200;
}


/////////////////////////////////   paging   //////////////////////////////////////


void Fl_GDI_Printer::set_page(int page){
  if(page){
    ResetDC(gc_,mode_);
    SetMapMode(gc_, MM_ANISOTROPIC);
    SetTextAlign(gc_, TA_BASELINE|TA_LEFT);
    SetBkMode(gc_, TRANSPARENT);
    StartPage(gc_);
    ix = GetDeviceCaps(gc_, LOGPIXELSX);
    iy = GetDeviceCaps(gc_, LOGPIXELSY);
    ox = GetDeviceCaps(gc_, PHYSICALOFFSETX);
    oy = GetDeviceCaps(gc_, PHYSICALOFFSETY);
  }
  SetViewportOrgEx(gc_,VOx =  - ox, VOy = - oy,0); //setting origin to the upper left corner
  SetViewportExtEx(gc_, VEx = (long)(ix * iy),  VEy = (long)(iy *ix ),0);
  SetWindowExtEx(gc_, WEx = iy * 72,  WEy = ix * 72, 0); //72 pixels per inch mapping
  SetWindowOrgEx(gc_, WOx = 0, WOy = 0,0);
}



void Fl_GDI_Printer::page(double pw, double ph, int media){
  if(nPages)
    EndPage(gc_);
  nPages++;
  pw_=pw;
  ph_=ph;
//  if(pw>ph)
//    orientation_ = 1;
  //DEVMODE * mode = (DEVMODE *)GlobalLock(mode_);
  if(ph>pw)
    mode_->dmOrientation = DMORIENT_PORTRAIT;
  else
    mode_->dmOrientation = DMORIENT_LANDSCAPE;
  if(media){
    mode_->dmPaperWidth = (int) (pw*254/72);
    mode_->dmPaperLength = (int) (ph*254/72);
    mode_->dmFields |= DM_PAPERLENGTH | DM_PAPERWIDTH;
    mode_->dmFields &= ~DM_PAPERSIZE;
  }
  //GlobalUnlock(mode_);
  set_page(1);
};


void Fl_GDI_Printer::page(int format){
 // DEVMODE * mode = (DEVMODE *)GlobalLock(mode_);
  if(nPages)
    EndPage(gc_);
  //DEVMODE * mode = (DEVMODE *)GlobalLock(mode_);
  if(format & LANDSCAPE){
    mode_->dmOrientation = DMORIENT_LANDSCAPE;
    pw_ = page_formats[format & 0xFF][1];
    ph_ = page_formats[format & 0xFF][0];
  }else{
    mode_->dmOrientation = DMORIENT_PORTRAIT;
    pw_ = page_formats[format & 0xFF][0];
    ph_ = page_formats[format & 0xFF][1];
  }
  if(format & MEDIA){
    if(!gdipaper(mode_, format& 0xFF)){
        mode_->dmFields &= ~DM_PAPERLENGTH & ~DM_PAPERWIDTH;
        mode_->dmFields |= DM_PAPERSIZE;
    }else{
       mode_->dmPaperWidth = (int) (pw_*254/72);
       mode_->dmPaperLength = (int) (ph_*254/72);
       mode_->dmFields |= DM_PAPERLENGTH | DM_PAPERWIDTH;
       mode_->dmFields &= ~DM_PAPERSIZE;
    }
  }
  if(format & LANDSCAPE){
    mode_->dmOrientation = DMORIENT_LANDSCAPE;
  }else{
    mode_->dmOrientation = DMORIENT_PORTRAIT;

  }
 
  //GlobalUnlock(mode_);
  set_page(1);
};

////////////////////////  margins and placing of drawinds on the page ///////////////////////////


void Fl_GDI_Printer::sty(int style, int width, char *dashes, int vex){
  if(!(width)){
    width=1;
    if(!style && !dashes)
      style |= FL_CAP_SQUARE | FL_JOIN_MITER; //adjustment for system drawings
  }
  if(!dashes || !(*dashes)){
    if((style & 0xff) && ((style & 0xf00)==FL_CAP_SQUARE)) // square caps do not seem to work with dasges, not sure why
      style = (style & ~0xf00)|FL_CAP_FLAT;
    Fl_Output_Device::line_style(style, width*vex);
  }else{

    // Following is shameless copy from original fl_line_style with modifications.
    // Has to be changed to avoid code redundance...

    static DWORD Cap[4]= {PS_ENDCAP_FLAT, PS_ENDCAP_FLAT, PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE};
    static DWORD Join[4]={PS_JOIN_ROUND, PS_JOIN_MITER, PS_JOIN_ROUND, PS_JOIN_BEVEL};
    int s1 = PS_GEOMETRIC | Cap[(style>>8)&3] | Join[(style>>12)&3];
    DWORD a[16]; int n = 0;
    s1 |= PS_USERSTYLE;
    for (n = 0; n < 16 && *dashes; n++) a[n] = vex * *dashes++;
    if ((style || n) && !width) width = 1; // fix cards that do nothing for 0?
    LOGBRUSH penbrush = {BS_SOLID,fl_RGB(),0}; // can this be fl_brush()?
    HPEN newpen = ExtCreatePen(s1, vex * width, &penbrush, n, n ? a : 0);
    if (!newpen) {
      Fl::error("Fl_GDI_Printer::line_style(): Could not create GDI pen object.");
      return;
    }
    HPEN oldpen = (HPEN)SelectObject(fl_gc, newpen);
    DeleteObject(oldpen);
    fl_current_xmap->pen = newpen;
  }
}


void Fl_GDI_Printer::line_style(int style, int width, char * dashes){
   sty(style_ = style, width_ = width, dashes_ = dashes);
};

void Fl_GDI_Printer::place(double x, double y, double tx, double ty, double s){
//  SetViewportOrgEx(gc_, VOx = (long)(ix * (lm_+tx) /72 - ox + dx), VOy = (long)( iy *(tm_+th) /72 - oy + dy),0); //setting origin to the upper left corner inside margins

  SetViewportOrgEx(gc_, VOx = (long)(ix * tx /72 - ox ), VOy = (long)( iy *ty /72 - oy),0); //setting origin to the upper left corner inside margins
  SetWindowOrgEx(gc_, WOx = (long)x,  WOy = (long)y,0);
  SetViewportExtEx(gc_,  VEx =(long)(ix * iy *s),  VEy =(long)(iy * ix * s), 0);
  SetWindowExtEx(gc_, WEx = iy *72, WEy = ix * 72,0);
};

/*
void Fl_GDI_Printer::place(double x, double y, double w, double h, double tx, double ty, double tw, double th,int align){
  double dx, dy;
  double s = tw/w;

  if(s<(th/h)){
    dx = 0;
    dy = (th - s * h)*iy/144;
  }else{
    s=th/h;
    dy = 0;
    dx = (tw - s * w)*ix/144;
  }

  if(align & 3)
    if(align & FL_ALIGN_TOP)
      dy=0;
    else
      dy *= 2;
  if(align & 12)
    if(align & FL_ALIGN_LEFT)
      dx = 0;
    else
      dx *= 2;

//  SetViewportOrgEx(gc_, VOx = (long)(ix * (lm_+tx) /72 - ox + dx), VOy = (long)( iy *(tm_+th) /72 - oy + dy),0); //setting origin to the upper left corner inside margins

   SetViewportOrgEx(gc_, VOx = (long)(ix * tx /72 - ox + dx), VOy = (long)( iy * ty /72 - oy + dy),0); //setting origin to the upper left corner inside margins

  SetWindowOrgEx(gc_, WOx = (long)x,  WOy = (long)y,0);
  SetViewportExtEx(gc_,  VEx =(long)(ix * iy *s),  VEy =(long)(iy * ix * s), 0);
  SetWindowExtEx(gc_, WEx = iy *72, WEy = ix * 72,0);
};

*/
///////////////// we need to re-implement path drawings (double) for sub-pixel placement of vertices /////////////

FL_EXPORT void Fl_GDI_Printer::transformed_vertex(double x, double y){
  Fl_Output_Device::transformed_vertex((max_res_) * x, (max_res_) * y);
};

//struct matrix {double a, b, c, d, x, y;};

extern FL_EXPORT matrix * fl_get_matrix();

FL_EXPORT void Fl_GDI_Printer::vertex(double x, double y){
         transformed_vertex(fl_transform_x(x,y), fl_transform_y(x,y));
};

extern int fl_what_loop;
enum {LINE, LOOP, POLYGON, POINT_};

FL_EXPORT void Fl_GDI_Printer::circle(double x, double y, double r){
  matrix * m = fl_get_matrix();
  double xt = fl_transform_x(x,y);
  double yt = fl_transform_y(x,y);
/*
// very ugly hack because m matrix is static, to be modified.
  double ma = fl_transform_dx(1,0);
  double mb = fl_transform_dy(1,0);
  double mc = fl_transform_dx(0,1);
  double md = fl_transform_dy(0,1);
*/

  double rx = r * (m->c ? sqrt(m->a*m->a+m->c*m->c) : fabs(m->a));
  double ry = r * (m->b ? sqrt(m->b*m->b+m->d*m->d) : fabs(m->d));
  double llx = xt-rx;
  double w = xt + rx - llx;
  double lly = yt - ry;
  double h = yt + ry - lly;

  SetWindowExtEx(gc_, WEx*(max_res_), WEy*(max_res_), 0);
  SetWindowOrgEx(gc_, WOx*(max_res_) ,  WOy*(max_res_) ,0);

  if (fl_what_loop==POLYGON) {
    SelectObject(fl_gc, fl_brush());
    Pie(fl_gc, (int)rint((max_res_)*llx), (int)rint((max_res_)*lly), (int)rint((max_res_)*(llx+w)), (int)rint((max_res_)*(lly+h)), 0, 0, 0, 0);
	  SetWindowExtEx(gc_, WEx, WEy, 0);
	  SetWindowOrgEx(gc_, WOx, WOy,0);
  }else{
    sty(style_, width_, dashes_, max_res_);
    Arc(fl_gc, (int)rint((max_res_)*llx), (int)rint((max_res_)*lly), (int)rint((max_res_)*(llx+w)), (int)rint((max_res_)*(lly+h)), 0, 0, 0, 0);
	  SetWindowExtEx(gc_, WEx, WEy, 0);
	  SetWindowOrgEx(gc_, WOx, WOy,0);
    sty(style_, width_, dashes_);
  }

}


void Fl_GDI_Printer::set_subpixel(){
  SetWindowExtEx(gc_, WEx*(max_res_), WEy*(max_res_), 0);
  SetWindowOrgEx(gc_, WOx*(max_res_),  WOy*(max_res_) ,0); 
  sty(style_, width_, dashes_, max_res_);
};

void Fl_GDI_Printer::set_normal(){
  SetWindowExtEx(gc_, WEx, WEy, 0);
  SetWindowOrgEx(gc_, WOx, WOy,0);
  sty(style_, width_, dashes_);
};

void Fl_GDI_Printer::rectf(int x, int y, int w, int h){
  //Fl_Output_Device::rectf(x,y,w,h);
  SetWindowExtEx(gc_, WEx * max_res_, WEy*(max_res_), 0);
  SetWindowOrgEx(gc_, WOx * max_res_,  WOy*(max_res_) ,0);
  Fl_Output_Device::rectf((int)(max_res_ * (x-0.5)),(int)(max_res_ * (y-0.5)),(int)(max_res_*(w)), (int)(max_res_*(h)));
  SetWindowExtEx(gc_, WEx, WEy, 0);
  SetWindowOrgEx(gc_, WOx, WOy,0);
};

void Fl_GDI_Printer::point(int x, int y){
  rectf(x,y,1,1);
};


void Fl_GDI_Printer::arc(int x, int y, int w, int h, double a1, double a2){
  set_subpixel();
  Fl_Output_Device::arc((int)(max_res_ * (x)),(int)(max_res_ * (y)),(int)(max_res_*(w-1)), (int)(max_res_*(h-1)), a1, a2);
  set_normal();
};
void Fl_GDI_Printer::pie(int x, int y, int w, int h, double a1, double a2){
  set_subpixel();
  Fl_Output_Device::pie((int)(max_res_ * (x)),(int)(max_res_ * (y)),(int)(max_res_*(w-1)), (int)(max_res_*(h-1)), a1, a2);
  set_normal();
};


void Fl_GDI_Printer::xyline(int x,int y, int x1){
  MoveToEx(fl_gc, x, y, 0); LineTo(fl_gc, x1, y);
}

void Fl_GDI_Printer::yxline(int x, int y, int y1){
  MoveToEx(fl_gc, x, y, 0); LineTo(fl_gc, x, y1);
}

void Fl_GDI_Printer::xyline(int x, int y, int x1, int y2) {
  MoveToEx(fl_gc, x, y, 0); 
  LineTo(fl_gc, x1, y);
  LineTo(fl_gc, x1, y2);
}

void Fl_GDI_Printer::xyline(int x, int y, int x1, int y2, int x3) {
  MoveToEx(fl_gc, x, y, 0); 
  LineTo(fl_gc, x1, y);
  LineTo(fl_gc, x1, y2);
  LineTo(fl_gc, x3, y2);
};

void Fl_GDI_Printer::yxline(int x, int y, int y1, int x2) {
  MoveToEx(fl_gc, x, y, 0); 
  LineTo(fl_gc, x, y1);
  LineTo(fl_gc, x2, y1);
}

void Fl_GDI_Printer::yxline(int x, int y, int y1, int x2, int y3) {
  MoveToEx(fl_gc, x, y, 0); 
  LineTo(fl_gc, x, y1);
  LineTo(fl_gc, x2, y1);
  LineTo(fl_gc, x2, y3);
};


void Fl_GDI_Printer::line(int x, int y, int x1, int y1) {
  MoveToEx(fl_gc, x, y, 0L); 
  LineTo(fl_gc, x1, y1);
};


void Fl_GDI_Printer::line(int x, int y, int x1, int y1, int x2, int y2) {
  MoveToEx(fl_gc, x, y, 0L); 
  LineTo(fl_gc, x1, y1);
  LineTo(fl_gc, x2, y2);
};

FL_EXPORT void Fl_GDI_Printer::end_line(){
  //LPSIZE l;
  //GetViewportExtEx( gc_, l );
  /*
  SetWindowExtEx(gc_, WEx*(max_res_), WEy*(max_res_), 0);
  SetWindowOrgEx(gc_, WOx*(max_res_),  WOy*(max_res_) ,0); 
  //GetViewportExtEx( gc_, l );
  sty(style_, width_, dashes_, max_res_);
  */
  set_subpixel();
  Fl_Output_Device::end_line();
  set_normal();
  /*
  SetWindowExtEx(gc_, WEx, WEy, 0);
  SetWindowOrgEx(gc_, WOx, WOy,0);
  sty(style_, width_, dashes_);
  */
};


FL_EXPORT void Fl_GDI_Printer::end_polygon(){
  set_subpixel();
  /*
  SetWindowExtEx(gc_, WEx*(max_res_), WEy*(max_res_), 0);
  SetWindowOrgEx(gc_, WOx * (max_res_), WOy *(max_res_),0);
  sty(style_, width_, dashes_, max_res_);
  */
  Fl_Output_Device::end_polygon();
  set_normal();
  /*
  SetWindowExtEx(gc_, WEx, WEy, 0);
  SetWindowOrgEx(gc_, WOx, WOy,0);
  sty(style_, width_, dashes_);
  */
};


FL_EXPORT void Fl_GDI_Printer::end_loop(){
  set_subpixel();
  Fl_Output_Device::end_loop();
  set_normal();
};

FL_EXPORT void Fl_GDI_Printer::end_complex_polygon(){
  set_subpixel();
  Fl_Output_Device::end_complex_polygon();
  set_normal();
};




////////  clipping, need to be re-implemented as orig. win32 functions are in device coordinates  ///////////

FL_EXPORT void Fl_GDI_Printer::push_clip(int x, int y, int w, int h){
  Fl_Output_Device::push_clip(((x - WOx) * VEx - VEx/2) / WEx + VOx,  ((y - WOy) * VEy - VEy/2 ) / WEy + VOy, w * VEx / WEx, h * VEy / WEy);
}

extern Fl_Region * fl_clip_stack;
extern int * fl_clip_stack_pointer;

FL_EXPORT int Fl_GDI_Printer::not_clipped(int x, int y, int w, int h){
  Fl_Region r = fl_clip_stack[* fl_clip_stack_pointer];
  if (!r) return 1;
  RECT rect;
  rect.left = ((x - WOx) * VEx -VEx/2)/ WEx + VOx;
  rect.top = ((y - WOy) * VEy-VEy/2) / WEy + VOy;
  rect.right  = ((x + w - WOx) * VEx  - VEx/2)/ WEx + VOx;
  rect.bottom  = ((y + h - WOy) * VEy-VEy/2) / WEy + VOy;
  return RectInRegion(r,&rect);
}

FL_EXPORT int Fl_GDI_Printer::clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H){
  int ret = Fl_Output_Device::clip_box(((x - WOx) * VEx - VEx/2)/ WEx + VOx,  ((y - WOy) * VEy -VEy/2)/ WEy + VOy, w * VEx / WEx, h * VEy / WEy, X, Y, W, H);
  X = (X - VOx ) * WEx / VEx + WOx;
  Y = (Y - VOy ) * WEy / VEy + WOy;
  W = W * WEx / VEx;
  H = H * WEy / VEy;
  return ret;
}

// -
//extern uchar **fl_mask_bitmap;