//--------------------------------------------------------------------------- #include #include #include #include #include #include #pragma hdrstop #include "Common.h" #include "Define.h" #include "Exception.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- TStringTable CommonStringTable; AnsiString Language; #ifdef LOCK_HASP int Password[4]; #endif AnsiString DirectoryBin; AnsiString DirectoryItem; AnsiString DirectoryTemp; AnsiString DirectoryColor; AnsiString DirectoryTexture; #if defined(TEXTILE) AnsiString DirectoryStyle; AnsiString DirectoryTreatment; #elif defined(WEAVE) || defined(PILE) AnsiString DirectoryYarn; #elif defined (KNIT) AnsiString DirectoryStitch; #endif AnsiString DefaultFontName; TFont *SmallFont; /* TPrinterColor *PrinterColor; TStandardColor *StandardColor; TTextileColor *TextileColor; */ TTablet *Tablet; #if defined(KNIT) TDesignMode DesignMode = D_YARN; #endif #if defined(TEXTILE) || defined(KNIT) //--------------------------------------------------------------------------- // 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; } #endif //--------------------------------------------------------------------------- // TPCanvasInfor //--------------------------------------------------------------------------- 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 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 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 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 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); } //--------------------------------------------------------------------------- AnsiString __fastcall TPCanvasInfor::Name(TUnit Unit, int w, int h) { switch (SizeType) { case cstA4: return "A4"; case cstA3: return "A3"; case cstA2: return "A2"; case cstA1: return "A1"; case cstA0: return "A0"; default: if (Unit == uDot) { return Format("%d x %d", OPENARRAY(TVarRec, (w, h))); } else if (Unit == uInch) { return Format("%f x %f", OPENARRAY(TVarRec, ((double)w/DotsPerInch, (double)h/DotsPerInch))); } else if (Unit == uCm) { return Format("%f x %f", OPENARRAY(TVarRec, (2.54*w/DotsPerInch, 2.54*h/DotsPerInch))); } break; } } //--------------------------------------------------------------------------- // External Function //--------------------------------------------------------------------------- void __fastcall LoadFromMainRegIniFile() { TRegIniFile *RegIniFile; char tp[MAX_PATH+1]; AnsiString pw; GetTempPath(MAX_PATH, tp); if (tp[strlen(tp)-1]=='\\') tp[strlen(tp)-1] = 0; DirectoryTemp = tp; RegIniFile = new TRegIniFile(RegFilename); if (RegIniFile) { // Language = RegIniFile->ReadString("Common", "Language", "English"); // DefaultFontName = RegIniFile->ReadString("Common", "DefaultFontName", "MS Sans Serif"); #ifdef LOCK_HASP pw = RegIniFile->ReadString("TexWork", "Serial", ""); sscanf(pw.c_str(), "%d-%d-%d-%d", &Password[0], &Password[1], &Password[2], &Password[3]); #endif DirectoryBin = RegIniFile->ReadString("Directory", "Bin", DefaultDir + "\\Bin"); DirectoryColor = RegIniFile->ReadString("Directory", "Color", DefaultDir + "\\Color"); DirectoryTexture = RegIniFile->ReadString("Directory", "Texture", DefaultDir + "\\Texture"); #if defined(TEXTILE) DirectoryStyle = RegIniFile->ReadString("Directory", "Style", DefaultDir + "\\Style"); DirectoryTreatment = RegIniFile->ReadString("Directory", "Treatment", DefaultDir + "\\Treatment"); #elif defined(WEAVE) || defined(PILE) DirectoryYarn = RegIniFile->ReadString("Directory", "Yarn", DefaultDir + "\\Yarn"); #elif defined(KNIT) DirectoryStitch = RegIniFile->ReadString("Directory", "Stitch", DefaultDir + "\\Stitch"); #endif delete RegIniFile; } else { Language = "English"; DefaultFontName = "MS Sans Serif"; DirectoryBin = DefaultDir + "\\Bin"; DirectoryColor = DefaultDir + "\\Color"; DirectoryTexture = DefaultDir + "\\Texture"; #if defined(TEXTILE) DirectoryStyle = DefaultDir + "\\Style"; DirectoryTreatment = DefaultDir + "\\Treatment"; #elif defined(WEAVE) || defined(PILE) DirectoryYarn = DefaultDir + "\\Yarn"; #elif defined(KNIT) DirectoryStitch = DefaultDir + "\\Stitch"; #endif } #if defined(TEXTILE) DirectoryItem = DirectoryBin + "\\Textile"; #elif defined(WEAVE) DirectoryItem = DirectoryBin + "\\Weave"; #elif defined(KNIT) DirectoryItem = DirectoryBin + "\\Knit"; #elif defined(PILE) DirectoryItem = DirectoryBin + "\\Pile"; #endif } //--------------------------------------------------------------------------- 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 } } //--------------------------------------------------------------------------- Graphics::TBitmap* __fastcall GetRegion(int ws, int hs) { #ifndef UNIT #define UNIT 4 #endif int i; POINT Start, End; Graphics::TBitmap *bm; // POINT *pt; TPoint *pt; HDC dc; BYTE *p; long temp; long Garo, Sero; int VertexCount[4]; bm = new Graphics::TBitmap; bm->PixelFormat = pf16bit; bm->Width = ws -2; // ºñÆ®¸ÊÀÇ ³ÐÀÌ ¼³Á¤ bm->Height = hs -2; // ºñÆ®¸ÊÀÇ ³ôÀÌ ¼³Á¤ bm->Canvas->Brush->Color = clWhite; bm->Canvas->FillRect(Rect(0,0,bm->Width,bm->Height)); // Èò»öÀ¸·Î Bitmap À» ä¿ò bm->Canvas->Pen->Color = clBlack; bm->Canvas->Brush->Color = clBlack; End.x = bm->Width - 3; End.y = bm->Height - 3; Start.x = Start.y = 2; Garo = abs(End.x - Start.x -UNIT); // Polygon ÀÇ °¡·Î ±æÀÌ Sero = abs(End.y - Start.y -UNIT); // Polygon ÀÇ ¼¼·Î ±æÀÌ // ¼¼·Î º¯ÀÇ VerTex ¼ö ±¸Çϱâ VertexCount[0] = VertexCount[2] = Sero / UNIT ; // °¡·Î º¯ÀÇ VerTex ¼ö ±¸Çϱâ VertexCount[1] = VertexCount[3] = Garo / UNIT; int Total = VertexCount[0] + VertexCount[1] + VertexCount[2] + VertexCount[3]; pt = new TPoint[Total]; bm->Canvas->MoveTo(Start.x + UNIT,Start.y + UNIT); // Polygon ÀÇ ½ÃÀÛÁ¡ int ValueX ,ValueY; // Áº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueY = Start.y; for(i = 0; i < VertexCount[0] ; i++) { if( i %2 == 1){ pt[i].x = Start.x ; } if (i %2 == 0){ pt[i].x = Start.x +UNIT; } pt[i].y = ValueY = ValueY + UNIT; if(pt[i].y > End.y - UNIT){ if(abs(pt[i].y - pt[i-1].y) < 4) pt[i].x = Start.x +UNIT; pt[i].y = End.y - UNIT; } } // ¹Øº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueX = Start.x; int RoopStart; RoopStart = VertexCount[0]; for (i = RoopStart ; i < RoopStart + VertexCount[1];i++) { if(i % 2 == 1) pt[i].y = End.y; if(i % 2 == 0) pt[i].y = End.y - UNIT; pt[i].x = ValueX = ValueX + UNIT; if(pt[i].x > End.x - UNIT){ if(abs(pt[i].x - pt[i-1].x) < 4) pt[i].y = Start.y +UNIT; pt[i].x = End.x - UNIT; } } // ¿ìº¯ÀÇ ÁÂÇ¥ ±¸Çϱâ RoopStart = RoopStart + VertexCount[1]; ValueY = End.y; for(i = RoopStart; i < RoopStart + VertexCount[2]; i++) { if( i %2 == 1){ pt[i].x = End.x ; } if (i %2 == 0){ pt[i].x = End.x -UNIT; } pt[i].y = ValueY = ValueY - UNIT; if(pt[i].y < Start.y + UNIT){ if(abs(pt[i].y - pt[i-1].y) < 4) pt[i].x = End.x -UNIT; pt[i].y = Start.y + UNIT; } } // À­º¯ÀÇ ÁÂÇ¥ ±¸Çϱâ ValueX = End.x; RoopStart = RoopStart + VertexCount[2]; for(i = RoopStart ; i < RoopStart + VertexCount[3];i++) { if(i % 2 == 1) pt[i].y = Start.y; if(i % 2 == 0) pt[i].y = Start.y + UNIT; pt[i].x = ValueX = ValueX - UNIT; if(pt[i].x < Start.x + UNIT){ if(abs(pt[i].x - pt[i-1].x) < 4) pt[i].y = Start.y +UNIT; pt[i].x = Start.x + UNIT; } } bm->Canvas->Polygon(pt, Total -1); // ±¸ÇÑ ÁÂÇ¥·Î Polygon ±×¸®±â delete[] pt; return bm; } /*--------------------------------------------------------------------------- void __fastcall PrintColorChip8(Graphics::TBitmap *Pattern, TRect rect, BYTE pi, Graphics::TBitmap * BitMask) { WORD *p; BYTE *q; int by,py,x; if (BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ for (by = 0, py=rect.Top; by < BitMask->Height; py++,by++) { p = (WORD * ) BitMask->ScanLine[by]; // BitMask ÀÇ À̹ÌÁö Á¤º¸ q = (BYTE *) Pattern->ScanLine[py] + rect.Left; // Pattern ÀÇ À̹ÌÁö Á¤º¸ for (x = 0 ; x < BitMask->Width ; x++,p++,q++){ if(*p == 0 ){ // polygon ÀÇ ³»ºÎÀÎÁö¸¦ üũ *q = pi; // »ö°ªÀ» ¼³Á¤ } } } } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. for( py = rect.Top ; py < rect.Bottom ; py++) { memset((BYTE *)Pattern->ScanLine[py] + rect.Left, pi, rect.Right - rect.Left); } } } */ //--------------------------------------------------------------------------- void __fastcall PrintColorChip8(TTexpiaBitmap *Pattern, TRect rect, BYTE pi, Graphics::TBitmap * BitMask) { WORD *p; BYTE *q; int by,py,x; if (BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ Pattern->StartScanLine(); for (by=0, py=rect.Top; byHeight; py++,by++) { p = (WORD * ) BitMask->ScanLine[by]; // BitMask ÀÇ À̹ÌÁö Á¤º¸ q = Pattern->GetScanLine(py) + rect.Left; // Pattern ÀÇ À̹ÌÁö Á¤º¸ for (x=0; xWidth; x++,p++,q++) { if(*p == 0) { // polygon ÀÇ ³»ºÎÀÎÁö¸¦ üũ *q = pi; // »ö°ªÀ» ¼³Á¤ } } Pattern->PutScanLine(py); } Pattern->StopScanLine(); } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. Pattern->StartScanLine(); for(py=rect.Top; pyGetScanLine(py) + rect.Left; memset(q, pi, rect.Right - rect.Left); Pattern->PutScanLine(py); } Pattern->StopScanLine(); } } /*--------------------------------------------------------------------------- void __fastcall PrintColorChip15(Graphics::TBitmap *Pattern, TRect rect, BYTE red, BYTE green, BYTE blue, Graphics::TBitmap *BitMask) { WORD *p; WORD *q; int by,py,x; WORD color = ((red & 0xF8) << 7) | ((green & 0xF8) << 2) | (blue >> 3); if(BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ for (by = 0, py=rect.Top; by < BitMask->Height; py++,by++) { p = (WORD *)BitMask->ScanLine[by]; // BitMask ÀÇ À̹ÌÁö Á¤º¸ q = (WORD *) Pattern->ScanLine[py] + rect.Left; // Pattern ÀÇ À̹ÌÁö Á¤º¸ for (x = 0 ; x < BitMask->Width ; x++,p++,q++){ if((*p == 0)) { // polygon ÀÇ ³»ºÎÀÎÁö¸¦ üũ *q = color; // »ö°ªÀ» ¼³Á¤ } } } } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. for (int py=rect.Top; pyScanLine[py] + rect.Left; for (int x=rect.Left; x> 3); if(BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ Pattern->StartScanLine(); for (by=0, py=rect.Top; byHeight; py++, by++) { p = (WORD *)BitMask->ScanLine[by]; // BitMask ÀÇ À̹ÌÁö Á¤º¸ q = (WORD *)Pattern->GetScanLine(py) + rect.Left; // Pattern ÀÇ À̹ÌÁö Á¤º¸ for (x = 0 ; x < BitMask->Width ; x++, p++, q++) { if((*p == 0)) { // polygon ÀÇ ³»ºÎÀÎÁö¸¦ üũ *q = color; // »ö°ªÀ» ¼³Á¤ } } Pattern->PutScanLine(py); } Pattern->StopScanLine(); } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. Pattern->StartScanLine(); for (py=rect.Top; pyGetScanLine(py) + rect.Left; for (x=rect.Left; xPutScanLine(py); } Pattern->StopScanLine(); } } /*--------------------------------------------------------------------------- void __fastcall PrintColorChip24(Graphics::TBitmap *Pattern, TRect rect, BYTE red, BYTE green, BYTE blue, Graphics::TBitmap *BitMask ) { WORD *p; BYTE *q; int by,py,x; int i,j; int color = 0x00000000; if( BitMask) { // °¡À§ È¿°ú¸¦ ÁÙ°ÍÀÎÁö¸¦ üũ for (by = 0, py=rect.Top; by < BitMask->Height; py++,by++) { p = (WORD *) BitMask->ScanLine[by]; // Mask À̹ÌÁö Á¤º¸ q = (BYTE *) Pattern->ScanLine[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; } } } } else { // °¡À§ È¿°ú¸¦ ÁÖÁö¾Ê°í Rectangle ¿µ¿ªÀ» »ö±ò·Î ä¿ò. color = (blue << 16) + (green << 8) + red; for (int py=rect.Top; pyScanLine[py] + 3 * rect.Left, color, rect.Right - rect.Left); } } } */ //--------------------------------------------------------------------------- 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(); } } //--------------------------------------------------------------------------- /* bool __fastcall SendToPrinter(Graphics::TBitmap *Pattern, int dpi, AnsiString title, int page, int method) { HDC hPrintDC = NULL, hDC = NULL; // Test Version by kjs TRect Src, Dst; int WidthRes, HeightRes, x, y, cnt; TSize Area, n, s; RGBQUAD rgb[256]; AnsiString str; TTexpiaBitmap Bitmap; hPrintDC = Printer()->Handle; WidthRes = GetDeviceCaps(hPrintDC, LOGPIXELSX); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * dpi / WidthRes; 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 (Pattern->PixelFormat == pf8bit) { GetDIBColorTable(Pattern->Canvas->Handle, 0, 256, rgb); } cnt=0; str = "/"+IntToStr(n.cy*n.cx); if (method == 2) { Dst.Left = 0; Dst.Top = 0; 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++) { cnt++; Printer()->Title = title+IntToStr(cnt)+str; Printer()->Copies = page; Printer()->BeginDoc(); Src.Left = x * Area.cx; s.cx = Pattern->Width - Src.Left; if (s.cx > Area.cx) s.cx = Area.cx; if (Pattern->PixelFormat == pf8bit) { 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); Printer()->EndDoc(); } } } else { switch (Pattern->PixelFormat) { case pf8bit: if (!Bitmap.Create(Area.cx, Area.cy, 8, rgb)) return false; break; case pf15bit: if (!Bitmap.Create(Area.cx, Area.cy, 16)) return false; break; case pf24bit: if (!Bitmap.Create(Area.cx, Area.cy, 24)) return false; break; } 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++) { cnt++; Printer()->Title = title+IntToStr(cnt)+str; Printer()->Copies = page; Printer()->BeginDoc(); 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) { Bitmap.Resize(s.cx, s.cy, clWhite); } hDC = Bitmap.CreateDC(); BitBlt(hDC, 0, 0, s.cx, s.cy, Pattern->Canvas->Handle, Src.Left, Src.Top, SRCCOPY); Bitmap.DeleteDC(hDC); if (method) { L_PrintBitmapExt(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false); } else { L_PrintBitmapFast(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false); } Printer()->EndDoc(); } } } return true; } */ /* bool __fastcall SendToPrinter(Graphics::TBitmap *Pattern, int dpi, AnsiString title, int page, int method) { HDC hPrintDC = NULL, hDC = 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); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * dpi / WidthRes; 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 (Pattern->PixelFormat == pf8bit) { GetDIBColorTable(Pattern->Canvas->Handle, 0, 256, rgb); } if (method == 2) { Dst.Left = 0; Dst.Top = 0; 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->PixelFormat == pf8bit) { 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); } } } else { switch (Pattern->PixelFormat) { case pf8bit: if (!Bitmap.Create(Area.cx, Area.cy, 8, rgb)) return false; break; case pf15bit: if (!Bitmap.Create(Area.cx, Area.cy, 16)) return false; break; case pf24bit: if (!Bitmap.Create(Area.cx, Area.cy, 24)) return false; break; } 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) { Bitmap.Resize(s.cx, s.cy, clWhite); } hDC = Bitmap.CreateDC(); BitBlt(hDC, 0, 0, s.cx, s.cy, Pattern->Canvas->Handle, Src.Left, Src.Top, SRCCOPY); Bitmap.DeleteDC(hDC); if (method) { L_PrintBitmapExt(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false); } else { L_PrintBitmapFast(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false); } } } } Printer()->EndDoc(); return true; } */ 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); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * dpi / WidthRes; 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; } /* bool __fastcall SendToPrinter(Graphics::TBitmap *Pattern, int dpi, AnsiString title, int page) { HDC hPrintDC = NULL, hDC = NULL; TRect Src, Dst; int WidthRes, HeightRes, x, y; TSize Area, n, s; RGBQUAD rgb[256]; BITMAPHANDLE Bitmap; Printer()->Title = title; Printer()->Copies = page; Printer()->BeginDoc(); hPrintDC = Printer()->Handle; WidthRes = GetDeviceCaps(hPrintDC, LOGPIXELSX); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * dpi / WidthRes; 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 (Pattern->PixelFormat == pf8bit) { GetDIBColorTable(Pattern->Canvas->Handle, 0, 256, rgb); } switch (Pattern->PixelFormat) { case pf8bit: if (!Bitmap.Create(Area.cx, Area.cy, 8, rgb)) return false; break; case pf15bit: if (!Bitmap.Create(Area.cx, Area.cy, 16)) return false; break; case pf24bit: if (!Bitmap.Create(Area.cx, Area.cy, 24)) return false; break; } 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) { Bitmap.Resize(s.cx, s.cy, clWhite); } hDC = Bitmap.CreateDC(); BitBlt(hDC, 0, 0, s.cx, s.cy, Pattern->Canvas->Handle, Src.Left, Src.Top, SRCCOPY); Bitmap.DeleteDC(hDC); L_PrintBitmapFast(hPrintDC, Bitmap.Handle, 1, 1, s.cx * WidthRes / dpi, s.cy * HeightRes / dpi, false); } } Printer()->EndDoc(); return true; } */ //--------------------------------------------------------------------------- void __fastcall LoadFont(TIniFile *IniFile, TFont *Font, AnsiString Section) { Font->Name = IniFile->ReadString(Section, "Name", DefaultFontName); /* Font->Size = IniFile->ReadInteger(Section, "Size", 8); int Style = IniFile->ReadInteger(Section, "Style", 0); if (Style&1) Font->Style << fsBold; else if (Style&2) Font->Style << fsItalic; else if (Style&4) Font->Style << fsUnderline; */ } //--------------------------------------------------------------------- void __fastcall SaveFont(TIniFile *IniFile, TFont *Font, AnsiString Section) { IniFile->WriteString(Section, "Name", Font->Name); /* IniFile->WriteInteger(Section, "Size", Font->Size); int Style = 0; if (Font->Style.Contains(fsBold)) Style |= 1; else if (Font->Style.Contains(fsItalic)) Style |= 2; else if (Font->Style.Contains(fsUnderline)) Style |= 4; IniFile->WriteInteger(Section, "Style", Style); */ } //--------------------------------------------------------------------- void __fastcall SetSmallFont(TFont *Font) { if (SmallFont) Font->Name = SmallFont->Name; Font->Size = 10; } //--------------------------------------------------------------------------- /* 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 3: return StandardColor->PN2Code(cd->Page, cd->Number); case 4: return TextileColor->PN2Code(cd->Page, cd->Number); default: return cd->ColorName; } } */ //--------------------------------------------------------------------------- AnsiString __fastcall GetTexpiaVersion() { AnsiString Version = "None"; TRegIniFile *RegIniFile = new TRegIniFile(RegFilename); if (RegIniFile) { Version = RegIniFile->ReadString("Common", "Version", "None"); delete RegIniFile; } return Version; } //--------------------------------------------------------------------------- TGrid __fastcall StrToGrid(AnsiString str) { char *tok = ")x ", *s, *p; TGrid g; s = strdup(str.c_str()); p = strtok(s, tok); if (strcmp(p, "Cm")==0) g.Unit = uCm; else if (strcmp(p, "Inch")==0) g.Unit = uInch; else g.Unit = uDot; p = strtok(NULL, tok); g.X = atof(p); p = strtok(NULL, tok); g.Y = atof(p); free(s); return g; } //--------------------------------------------------------------------------- AnsiString __fastcall GridToStr(TUnit u, double x, double y) { char *unit[3] = { "Dot", "Inch", "Cm" }; return Format("%s) %f x %f", OPENARRAY(TVarRec, (unit[(int)u], x, y))); } //---------------------------------------------------------------------------