//--------------------------------------------------------------------------- #include #pragma hdrstop #include "common.h" #include #include #include //--------------------------------------------------------------------------- int Password[4]; //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // TPlaneVertex //--------------------------------------------------------------------------- __fastcall TPlaneVertex::TPlaneVertex() { bit = new TPBitmap; } //--------------------------------------------------------------------------- __fastcall TPlaneVertex::~TPlaneVertex() { if (bit) delete bit; } //--------------------------------------------------------------------------- // Reivate Method //--------------------------------------------------------------------------- void __fastcall TPlaneVertex::Angle(int a, int b, int x, int y, double &sum) { double dx1, dy1, dx2, dy2; dx1 = p[a].x - x; dy1 = p[a].y - y; dx2 = p[b].x - x; dy2 = p[b].y - y; if (dx1 * dy2 - dx2 * dy1 > 0) { sum += acos((dx1 * dx2 + dy1 * dy2) / (sqrt(dx1 * dx1 + dy1 * dy1) * sqrt(dx2 * dx2 + dy2 * dy2))); } else { sum -= acos((dx1 * dx2 + dy1 * dy2) / (sqrt(dx1 * dx1 + dy1 * dy1) * sqrt(dx2 * dx2 + dy2 * dy2))); } } //--------------------------------------------------------------------------- // Rublic Method //--------------------------------------------------------------------------- void __fastcall TPlaneVertex::Create(TPoint a, TPoint b, TPoint c, TPoint d) { double s; int sx, sy, ex, ey, x, y, xx[4]; int i, j; p[0].x = a.x; p[0].y = a.y; p[1].x = b.x; p[1].y = b.y; p[2].x = c.x; p[2].y = c.y; p[3].x = d.x; p[3].y = d.y; start.x = p[0].x; start.y = p[0].y; end.x = p[0].x; end.y = p[0].y; for (i = 1; i < 4; i++) { if (start.x > p[i].x) start.x = p[i].x; if (end.x < p[i].x) end.x = p[i].x; if (start.y > p[i].y) start.y = p[i].y; if (end.y < p[i].y) end.y = p[i].y; } if (bit) { if (!bit->Create(end.x - start.x + 1, end.y - start.y + 1, 1)) goto fail; if (!bit->Lock()) goto fail; for (i = 0; i < 4; i++) { sx = p[i].x - start.x; ex = p[(i + 1) % 4].x - start.x; sy = p[i].y - start.y; ey = p[(i + 1) % 4].y - start.y; if (ex - sx && ey - sy) { s = (double)(ey - sy) / (ex - sx); if (ey > sy) { for (y = sy; y <= ey; y++) { x = (double)(y - sy) / s + sx + 0.5; #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } else { for (y = ey; y <= sy; y++) { x = (double)(y - sy) / s + sx + 0.5; #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } } else if (ex - sx) { #ifdef TPDEBUG if (sx>=0 && sxWidth && sy>=0 && syHeight) { BWSetX(bit->ScanLine(sy), sx); } else { SHOWDEBUG; } if (ex>=0 && exWidth && sy>=0 && syHeight) { BWSetX(bit->ScanLine(sy), ex); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(sy), sx); BWSetX(bit->ScanLine(sy), ex); #endif } else { if (ey > sy) { for (y = sy; y <= ey; y++) { #ifdef TPDEBUG if (sx>=0 && sxWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), sx); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), sx); #endif } } else { for (y = ey; y <= sy; y++) { #ifdef TPDEBUG if (sx>=0 && sxWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), sx); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), sx); #endif } } } } for (y = 1; y < end.y - start.y; y++) { sx = -1; for (x = i = 0; x <= end.x - start.x; x++) { if (BWGetX(bit->ScanLine(y), x)) { for (j = 0; j < 4; j++) { if (start.x + x == p[j].x && start.y + y == p[j].y) { sx = i; break; } } xx[i++] = x; } } if (i && (i % 2) == 0) { for (x = xx[0]; x <= xx[1]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } if (i == 4) { for (x = xx[2]; x <= xx[3]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } } else if (i == 3) { if (sx == 0) { for (x = xx[1]; x <= xx[2]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } else if (sx == 1) { for (x = xx[0]; x <= xx[2]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } else if (sx == 2) { for (x = xx[0]; x <= xx[1]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } else if (i) { for (x = xx[0]; x <= xx[i - 1]; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && y>=0 && yHeight) { BWSetX(bit->ScanLine(y), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(y), x); #endif } } } } for (i = 0; i < 4; i++) { sx = p[i].x - start.x; ex = p[(i + 1) % 4].x - start.x; sy = p[i].y - start.y; ey = p[(i + 1) % 4].y - start.y; if (ex - sx && ey == sy) { if (ex > sx) { for (x = sx + 1; x < ex; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && sy>=0 && syHeight) { BWSetX(bit->ScanLine(sy), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(sy), x); #endif } } else { for (x = ex + 1; x < sx; x++) { #ifdef TPDEBUG if (x>=0 && xWidth && sy>=0 && syHeight) { BWSetX(bit->ScanLine(sy), x); } else { SHOWDEBUG; } #else BWSetX(bit->ScanLine(sy), x); #endif } } } } } return; fail: ::doDestroy(bit); } //--------------------------------------------------------------------------- bool __fastcall TPlaneVertex::Check(int x, int y) { int dis_x, dis_y; double sum = 0.0; if (bit) return BWGetX(bit->ScanLine(y - start.y), x - start.x); for (int i = 0; i < 4; i++) { if (i) { dis_x = abs(p[i].x - p[i - 1].x); dis_y = abs(p[i].y - p[i - 1].y); if (abs(x - p[i].x) <= dis_x && abs(x - p[i - 1].x) <= dis_x && abs(y - p[i].y) <= dis_y && abs(y - p[i - 1].y) <= dis_y && (y - p[i].y) * (p[i - 1].x - p[i].x) == (x - p[i].x) * (p[i - 1].y - p[i].y)) return true; } else { dis_x = abs(p[0].x - p[3].x); dis_y = abs(p[0].y - p[3].y); if (abs(x - p[0].x) <= dis_x && abs(x - p[3].x) <= dis_x && abs(y - p[0].y) <= dis_y && abs(y - p[3].y) <= dis_y && (y - p[0].y) * (p[3].x - p[0].x) == (x - p[0].x) * (p[3].y - p[0].y)) return true; } } Angle(0, 3, x, y, sum); Angle(3, 2, x, y, sum); Angle(2, 1, x, y, sum); Angle(1, 0, x, y, sum); if (2.0 * M_PI - fabs(sum) < 0.0000000001) { if (fabs(sum) - 2.0 * M_PI < 0.0000000001) return true; } return false; } //--------------------------------------------------------------------------- void __fastcall TPCanvasInfor::SetSize(TPCanvasSizeType st, int w, int h) { SizeType = st; if (st==cstFree) { Width = w; Height = h; } else { Width = GetWidth(); Height = GetHeight(); } } //--------------------------------------------------------------------------- int __fastcall TPCanvasInfor::GetWidth() { if (SizeType==cstFree) return Width; if (Orientation==coPortrait) { switch (SizeType) { case cstTabloid: return 10.3 * DotsPerInch; case cstLetter: return 8.0 * DotsPerInch; //k3dogs letter case cstLegal: return 8.0 * DotsPerInch; case cstA0: return 31.2 * DotsPerInch; case cstA1: return 22.0 * DotsPerInch; case cstA2: return 15.6 * DotsPerInch; case cstA3: return 11.0 * DotsPerInch; default: return 7.8 * DotsPerInch; } } else { switch (SizeType) { case cstTabloid: return 16.0 * DotsPerInch; case cstLetter: return 10.3 * DotsPerInch; //k3dogs letter case cstLegal: return 13.2 * DotsPerInch; case cstA0: return 44.0 * DotsPerInch; case cstA1: return 31.2 * DotsPerInch; case cstA2: return 22.0 * DotsPerInch; case cstA3: return 15.6 * DotsPerInch; default: return 11.0 * DotsPerInch; } } } //--------------------------------------------------------------------------- int __fastcall TPCanvasInfor::GetHeight() { if (SizeType==cstFree) return Height; if (Orientation==coPortrait) { switch (SizeType) { case cstTabloid: return 16.0 * DotsPerInch; case cstLetter: return 10.3 * DotsPerInch; //k3dogs letter case cstLegal: return 13.2 * DotsPerInch; case cstA0: return 44.0 * DotsPerInch; case cstA1: return 31.2 * DotsPerInch; case cstA2: return 22.0 * DotsPerInch; case cstA3: return 15.6 * DotsPerInch; default: return 11.0 * DotsPerInch; } } else { switch (SizeType) { case cstTabloid: return 10.3 * DotsPerInch; case cstLetter: return 8.0 * DotsPerInch; //k3dogs letter case cstLegal: return 8.0 * DotsPerInch; case cstA0: return 31.2 * DotsPerInch; case cstA1: return 22.0 * DotsPerInch; case cstA2: return 15.6 * DotsPerInch; case cstA3: return 11.0 * DotsPerInch; default: return 7.8 * DotsPerInch; } } } //--------------------------------------------------------------------------- void __fastcall TPCanvasInfor::SetExtFileOption() { EXTFILEOPTION ExtFileOption; L_GetExtFileOption(&ExtFileOption); ExtFileOption.XResolution = DotsPerInch; ExtFileOption.YResolution = DotsPerInch; L_SetExtFileOption(&ExtFileOption); } //--------------------------------------------------------------------------- TPrinterColor *PrinterColor; TStandardColor *StandardColor; TTextileColor *TextileColor; TPantone1000 *Pantone1000; TPantoneTextile *PantoneTextile; TStringTable CommonStringTable; TStringTable MessageStringTable; AnsiString BaseDir; AnsiString Language=DEFAULT_LANGUAGE; AnsiString DefaultFontName = "MS Sans Serif"; TFont *SmallFont=NULL; //--------------------------------------------------------------------- AnsiString __fastcall MyFloatToStr(double value, int digit){ switch(digit){ case 0: { return IntToStr((int)(value+0.5)); } case 1: { return FloatToStr(0.1*(int)(value*10.0+0.5)); } case 2: default: { return FloatToStr(0.01*(int)(value*100.0+0.5)); } case 3: { return FloatToStr(0.001*(int)(value*1000.0+0.5)); } } } //--------------------------------------------------------------------- void __fastcall LoadFont(TIniFile *IniFile, TFont *Font, AnsiString Section) { Font->Name = IniFile->ReadString(Section, "Name", DefaultFontName); } //--------------------------------------------------------------------- void __fastcall SaveFont(TIniFile *IniFile, TFont *Font, AnsiString Section) { IniFile->WriteString(Section, "Name", Font->Name); } //--------------------------------------------------------------------- void __fastcall SetSmallFont(TFont *Font) { if (SmallFont) Font->Name = SmallFont->Name; // Font->Size = 10; } //--------------------------------------------------------------------- void __fastcall PrintColorChip24(TTexpiaBitmap *Pattern, TRect rect, BYTE red, BYTE green, BYTE blue, Graphics::TBitmap *BitMask ) { WORD *p; BYTE *q; int by,py,x; COLORREF color; // int color = 0x00000000; if( BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ Pattern->StartScanLine(); for (by = 0, py=rect.Top; by < BitMask->Height; py++,by++) { p = (WORD *) BitMask->ScanLine[by]; // Mask À̹ÌÁö Á¤º¸ q = Pattern->GetScanLine(py) + 3*rect.Left; // Ãâ·Â À̹ÌÁö Á¤º¸ for (x = 0 ; x < BitMask->Width ; x++, p++, q+=3) { if((*p == 0)) { // BitMask üũ *q = blue; // Ä®¶ó°ª ¼³Á¤ *(q + 1) = green; *(q + 2) = red; } } Pattern->PutScanLine(py); } Pattern->StopScanLine(); } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. color = (blue << 16) + (green << 8) + red; Pattern->StartScanLine(); for (int py=rect.Top; pyGetScanLine(py) + 3*rect.Left; memset24(q, color, rect.Right - rect.Left); Pattern->PutScanLine(py); } Pattern->StopScanLine(); } } //--------------------------------------------------------------------------- void *memset24(void *s, DWORD c, size_t n) { asm { mov edx,n cmp edx,0 jz label5 mov edi,s test edx,0xfffffffc jz label4 mov eax,c mov [edi+0x02],al mov [edi+0x05],al mov [edi+0x08],al mov [edi+0x0B],al shr eax,0x08 mov [edi+0x01],al mov [edi+0x04],al mov [edi+0x07],al mov [edi+0x0A],al shr eax,0x08 mov [edi],al mov [edi+0x03],al mov [edi+0x06],al mov [edi+0x09],al mov eax,[edi] mov ebx,[edi+0x04] mov ecx,[edi+0x08] shr edx,0x02 label1: mov [edi],eax mov [edi+0x04],ebx mov [edi+0x08],ecx add edi,0x0c dec edx jz label2 mov [edi],eax mov [edi+0x04],ebx mov [edi+0x08],ecx add edi,0x0c dec edx jz label2 mov [edi],eax mov [edi+0x04],ebx mov [edi+0x08],ecx add edi,0x0c dec edx jz label2 mov [edi],eax mov [edi+0x04],ebx mov [edi+0x08],ecx add edi,0x0c dec edx jnz label1 label2: mov edx,n and edx,0x03 jz label5 label4: mov ebx,c mov [edi+2],bl shr ebx,0x08 mov [edi+1],bl shr ebx,0x08 mov [edi],bl add edi,0x03 dec edx jnz label4 label5: mov eax,s } } //--------------------------------------------------------------------------- AnsiString __fastcall GetColorName(TColorData *cd) { switch (cd->Kind) { case 0: if (cd->Page==0) return Format("%d-%d-%d", OPENARRAY(TVarRec, (255-cd->RGB.rgbRed, 255-cd->RGB.rgbGreen, 255-cd->RGB.rgbBlue))); else return PrinterColor->PN2Code(cd->Page, cd->Number); case 1: ////////////k3dogs 20001211 return Pantone1000->PN2Code(cd->Page, cd->Number); // case 2: // return PantoneTextile->PN2Code(cd->Page, cd->Number); case 3: return StandardColor->PN2Code(cd->Page, cd->Number); case 4: return TextileColor->PN2Code(cd->Page, cd->Number); default: return cd->ColorName; } } //--------------------------------------------------------------------------- bool __fastcall SendToPrinter(TTexpiaBitmap *Pattern, double dpi, AnsiString title, int page, int method) { HDC hPrintDC, hDC = NULL, phDC = NULL; TRect Src, Dst; int WidthRes, HeightRes, x, y; TSize Area, n, s; RGBQUAD rgb[256]; TTexpiaBitmap Bitmap; Printer()->Title = title; Printer()->Copies = page; Printer()->BeginDoc(); hPrintDC = Printer()->Handle; WidthRes = GetDeviceCaps(hPrintDC, LOGPIXELSX); //ÀåÄ¡°íÀ¯Á¤º¸¸¦ ±¸ÇÔ. LOGPIXELSX=È­¸éÆø¹æÇâÀ¸·Î ·ÎÁöÄà ÀÎÄ¡´ç Çȼ¿ °³¼ö. -k3dogs HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * dpi / WidthRes; //HORXRES=½ºÅ©¸°ÀÇ Æø(Çȼ¿ ´ÜÀ§). Area.cy = GetDeviceCaps(hPrintDC, VERTRES) * dpi / HeightRes; // // Epson Color Stylus Ex, 1200 ¶Ç´Â HP Color LaserJet 4500¿¡¼­ // Area.cx, Area.cyÀÇ size¸¦ ÁÙ¿©¼­ testÇØ º¼°Í. // n.cx = ((Pattern->Width - 1) / Area.cx) + 1; n.cy = ((Pattern->Height - 1) / Area.cy) + 1; if ((phDC = Pattern->CreateDC()) == NULL) goto fail; if (Pattern->BitsPerPixel == 8) { GetDIBColorTable(phDC, 0, 256, rgb); } if (method == 2) { //Ãʱ⠹öÀü... À©µµ¿ì¿¡¼­ Áö¿øÇÏ´Â ¹æ¹ýÀÌ¿ë. Dst.Left = 0; Dst.Top = 0; if (Pattern->BitsPerPixel == 8) { SetDIBColorTable(Printer()->Canvas->Handle, 0, 256, rgb); } for (y = 0; y < n.cy; y++) { Src.Top = y * Area.cy; s.cy = Pattern->Height - Src.Top; if (s.cy > Area.cy) s.cy = Area.cy; for (x = 0; x < n.cx; x++) { if ((x > 0) || (y > 0)) Printer()->NewPage(); Src.Left = x * Area.cx; s.cx = Pattern->Width - Src.Left; if (s.cx > Area.cx) s.cx = Area.cx; // if (Pattern->BitsPerPixel == 8) { // SetDIBColorTable(Printer()->Canvas->Handle, 0, 256, rgb); // } Dst.Right = s.cx * WidthRes / dpi; Dst.Bottom = s.cy * HeightRes / dpi; Src.Right = Src.Left + s.cx; Src.Bottom = Src.Top + s.cy; // Printer()->Canvas->CopyMode = cmSrcCopy; // Printer()->Canvas->CopyRect(Dst, Pattern->Canvas, Src); //which is right? SetStretchBltMode(Printer()->Canvas->Handle, COLORONCOLOR); StretchBlt(Printer()->Canvas->Handle, Dst.Left, Dst.Top, Dst.Right, Dst.Bottom, phDC, Src.Left, Src.Top, Src.Right-Src.Left, Src.Bottom-Src.Top, SRCCOPY); } } } else { //ÇÁ¸°ÅÍ ±âÁ¾¿¡ µû¶ó¼­ À©µµ¿ì¿¡¼­ Áö¿øÇÏ´Â if (Pattern->BitsPerPixel == 8) { //ÇÔ¼ö¸¸À¸·Î ÇÁ¸°Æ®Çϱ⿡´Â ¹®Á¦°¡ ¹ß»ýÇÏ¿© Ãß°¡ if (!Bitmap.Create(Area.cx, Area.cy, 8, rgb)) goto fail; } else { if (!Bitmap.Create(Area.cx, Area.cy, Pattern->BitsPerPixel)) goto fail; } for (y = 0; y < n.cy; y++) { Src.Top = y * Area.cy; s.cy = Pattern->Height - Src.Top; if (s.cy > Area.cy) s.cy = Area.cy; for (x = 0; x < n.cx; x++) { if ((x > 0) || (y > 0)) Printer()->NewPage(); Src.Left = x * Area.cx; s.cx = Pattern->Width - Src.Left; if (s.cx > Area.cx) s.cx = Area.cx; if (s.cx != Bitmap.Width || s.cy != Bitmap.Height) { if (!Bitmap.Resize(s.cx, s.cy, clWhite)) goto fail; } if ((hDC = Bitmap.CreateDC()) == NULL) goto fail; if (!BitBlt(hDC, 0, 0, s.cx, s.cy, phDC, Src.Left, Src.Top, SRCCOPY)) goto fail; Bitmap.DeleteDC(hDC); hDC = NULL; if (method) { if (!L_PrintBitmapExt(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false)) goto fail; } else { if (!L_PrintBitmapFast(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false)) goto fail; } } } } Pattern->DeleteDC(phDC); Printer()->EndDoc(); return true; fail: if (hDC) Bitmap.DeleteDC(hDC); if (phDC) Pattern->DeleteDC(phDC); return false; } //--------------------------------------------------------------------------- void __fastcall LoadFromMainRegIniFile() { TRegIniFile *RegIniFile; AnsiString pw; RegIniFile = new TRegIniFile(RegFilename); if (RegIniFile) { pw = RegIniFile->ReadString("Common", "Serial", ""); sscanf(pw.c_str(), "%d-%d-%d-%d", &Password[0], &Password[1], &Password[2], &Password[3]); delete RegIniFile; } else { } } //---------------------------------------------------------------------------