//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Text_F.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_FONT StringTable[0] #define IDS_SHAPE StringTable[1] #define IDS_HORV StringTable[2] #define IDS_CIRCLE StringTable[3] #define IDS_INTERVAL StringTable[4] //--------------------------------------------------------------------------- TTextForm *TextForm; //--------------------------------------------------------------------------- FIXED __fastcall FixedFormDouble(double d) { long l; l = (long)(d*65536L); return *(FIXED *)&l; } //--------------------------------------------------------------------------- void __fastcall TTextForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TTextForm::seTextClick(TObject *Sender) { TPSpinEdit *sp = (TPSpinEdit *)Sender; sp->SetFocus(); sp->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TTextForm::seSizeChange(TObject *Sender) { if (seSize->Text.Length()>0) { if (seSize->Value < 0) seSize->Value = 0; MainImageForm->iMainImage->Canvas->Font->Size = seSize->Value; GetTextMetrics(MainImageForm->iMainImage->Canvas->Handle, &TextMetric); UpdateMenu(); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::seIntervalChange(TObject *Sender) { if (seInterval->Text.Length()>0) { if (seInterval->Value < 0) seInterval->Value = 0; GetTextMetrics(MainImageForm->iMainImage->Canvas->Handle, &TextMetric); UpdateMenu(); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::ButtonFontClick(TObject *Sender) { FontDialog->Font->Assign(MainImageForm->iMainImage->Canvas->Font); if (FontDialog->Execute()) { MainImageForm->iMainImage->Canvas->Font->Assign(FontDialog->Font); GetTextMetrics(MainImageForm->iMainImage->Canvas->Handle, &TextMetric); IsPosition(); //Edit->SetFocus(); View(); EditChange(NULL); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::ComboBoxShapeChange(TObject *Sender) { if (IsDraw) { DrawLocate(); IsDraw = false; } Shape = ComboBoxShape->ItemIndex; UpdateMenu(); Step = 0; bPosition = false; IsPosition(); // Edit->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TTextForm::EditChange(TObject *Sender) { if (bPosition) { CursorOldPos = CursorNewPos; CursorNewPos = Edit->SelStart; if (Shape==2) ViewCircle(); else ViewOblique(); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::EditClick(TObject *Sender) { Edit->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TTextForm::ButtonOKClick(TObject *Sender) { bool undoSw = false; TUndoData *ud; int ec = EC_NONE; DeleteText(); if ((undoSw = MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height))) == false) { ec = EC_MEMORY_LACK; goto fail; } if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } Original = ud->Bitmap; Step = 0; bPosition = false; IsPosition(); ::RepaintImage(); return; fail: if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TTextForm::Timer200msTimer(TObject *Sender) { if (bPosition && CursorNewPos!=Edit->SelStart) { CursorOldPos = CursorNewPos; CursorNewPos = Edit->SelStart; if (Shape==2) ViewCircle(); else ViewOblique(); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::EditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) { ButtonOKClick(ButtonOK); } } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TTextForm::DeleteText() { TTextData *td; while (Text->Count>0) { td = (TTextData *)Text->First(); if (td->hMem) GlobalFree(td->hMem); HeapFree(GetProcessHeap(), 0, td); Text->Remove(td); } Edit->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TTextForm::UpdateMenu() { /* if (TextMetric.tmPitchAndFamily&TMPF_TRUETYPE) { seSize->Enabled = true; Edit->Enabled = true; ButtonOK->Enabled = true; } else { seSize->Enabled = false; if (Shape) { Edit->Enabled = false; ButtonOK->Enabled = false; } else { Edit->Enabled = true; ButtonOK->Enabled = true; } } */ if (TextMetric.tmPitchAndFamily&TMPF_TRUETYPE) { seSize->Enabled = true; ComboBoxShape->Enabled = true; if (bPosition) { Edit->Enabled = true; ButtonOK->Enabled = true; } } else { seSize->Enabled = false; ComboBoxShape->Enabled = false; if (Shape) { Edit->Enabled = false; ButtonOK->Enabled = false; ComboBoxShape->ItemIndex = 0; Shape = ComboBoxShape->ItemIndex; } else { if (bPosition) { Edit->Enabled = true; ButtonOK->Enabled = true; } } } } //--------------------------------------------------------------------------- void __fastcall TTextForm::View() { LabelFont->Caption = MainImageForm->iMainImage->Canvas->Font->Name; LabelFont->Font->Name = MainImageForm->iMainImage->Canvas->Font->Name; seSize->Value = MainImageForm->iMainImage->Canvas->Font->Size; UpdateMenu(); } //--------------------------------------------------------------------------- TList *__fastcall TTextForm::MakeTextList() { TList *tl = NULL; int i, j, k, l, m; TTextData *ntd = NULL, *otd; if ((tl = new TList)==NULL) return NULL; for (i=1; i<=Edit->Text.Length(); i++) { if ((ntd = (TTextData *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TTextData))) == NULL) goto fail; if (ntd) { ntd->c = (Byte)Edit->Text[i]; if (IsDBCSLeadByte(ntd->c)) { i++; ntd->c = (ntd->c<<8)|(Byte)Edit->Text[i]; } ntd->pos = i; ntd->hMem = 0; ntd->color = -1; tl->Add(ntd); } } m = CursorOldPos>CursorNewPos ? CursorNewPos : CursorOldPos; i = 0; while (iCount) { otd = (TTextData *)Text->Items[i]; j = otd->pos; if (j>m) break; ntd = (TTextData *)tl->Items[i]; if (otd->c!=ntd->c) break; ntd->gm = otd->gm; ntd->hMem = otd->hMem; otd->hMem = 0; ntd->color = otd->color; i++; } k = tl->Count-1; if (k>i) { l = Text->Count-1; while (l>=i && k>=0) { otd = (TTextData *)Text->Items[l]; ntd = (TTextData *)tl->Items[k]; if (otd->c==ntd->c) { j = otd->pos; // if (j>=((TTextData *)(Text->Last()))->pos-(((TTextData *)(tl->Last()))->pos-CursorNewPos)) { if (j > ((TTextData *)(Text->Last()))->pos-(((TTextData *)(tl->Last()))->pos-CursorNewPos)) { ntd->gm = otd->gm; ntd->hMem = otd->hMem; otd->hMem = 0; } ntd->color = otd->color; } l--; k--; } } return tl; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return NULL; } //--------------------------------------------------------------------------- void __fastcall TTextForm::ObliqueFont(TTextData *td, int sx, int sy, Byte *fbm) { TPItemImage *ti; int l, fx, fy, xx, yy; unsigned x, y; Byte *dst; COLORREF c = td->color; ti = MainImageForm->iMainImage; fx = sx+td->gm.gmptGlyphOrigin.x; fy = sy-td->gm.gmptGlyphOrigin.y; l = ((td->gm.gmBlackBoxX+31)>>5)<<2; if (ti->Bitmap->BitsPerPixel==8) { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { dst = ti->Bitmap->GetScanLine(yy); for (x=0; xgm.gmBlackBoxX; x++) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { dst[xx] = c; } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } else { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { dst = ti->Bitmap->GetScanLine(yy)+3*fx; for (x=0; xgm.gmBlackBoxX; x++, dst+=3) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { SetPixel24(dst, c); } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } } //--------------------------------------------------------------------------- void __fastcall TTextForm::ViewOblique() { TPItemImage *ti; TList *tl = NULL; double Theta, sx, sy; DWORD dwRet; void *lpBuf = NULL; int i, j, k, l, fx, fy, xx, yy, width; unsigned int x, y; Byte *fbm = NULL, *src, *dst; MAT2 m2; TTextData *td; int olddist, Width, Height; int ec = EC_NONE; double ssx, ssy; #if defined(KNIT) Width = MainImageForm->iMainImage->ArrayBitmap[0].Width; Height = MainImageForm->iMainImage->ArrayBitmap[0].Height; #else Width = MainImageForm->iMainImage->Bitmap->Width; Height = MainImageForm->iMainImage->Bitmap->Height; #endif olddist = newdist; newdist = seInterval->Value; ti = MainImageForm->iMainImage; Theta = -atan2(Pos[1].y-Pos[0].y, Pos[1].x-Pos[0].x); if (Theta<0) Theta = Theta+2*M_PI; if (Original == NULL) { return; } else { if (!(Original->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } if (!(ti->Bitmap->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} k = CursorOldPos>CursorNewPos ? CursorNewPos : CursorOldPos; sx = Pos[0].x; sy = Pos[0].y; for (i=0; iCount; i++) { td = (TTextData *)Text->Items[i]; width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (td->pos>k) { if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} fbm = (Byte *)lpBuf; fx = sx+td->gm.gmptGlyphOrigin.x; fy = sy-td->gm.gmptGlyphOrigin.y; l = ((td->gm.gmBlackBoxX+31)>>5)<<2; if (ti->Bitmap->BitsPerPixel==8) { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { src = Original->GetScanLine(yy); dst = ti->Bitmap->GetScanLine(yy); for (x=0; xgm.gmBlackBoxX; x++) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { dst[xx] = src[xx]; } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } else { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { src = Original->GetScanLine(yy)+3*fx; dst = ti->Bitmap->GetScanLine(yy)+3*fx; for (x=0; xgm.gmBlackBoxX; x++, src+=3, dst+=3) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { CopyPixel24(dst, src); } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } GlobalUnlock(td->hMem); lpBuf = NULL; fbm = NULL; } sx += (width+olddist)*cos(Theta); sy -= (width+olddist)*sin(Theta); } if ((tl = MakeTextList()) == NULL) {ec = EC_MEMORY_LACK; goto fail;} m2.eM11 = FixedFormDouble(cos(Theta)); m2.eM12 = FixedFormDouble(sin(Theta)); m2.eM21 = FixedFormDouble(-sin(Theta)); m2.eM22 = FixedFormDouble(cos(Theta)); sx = Pos[0].x; sy = Pos[0].y; Cursor[0].x = sx-TextMetric.tmDescent*cos(Theta+M_PI/2); Cursor[0].y = sy+TextMetric.tmDescent*sin(Theta+M_PI/2); Cursor[1].x = Cursor[0].x+TextMetric.tmHeight*cos(Theta+M_PI/2); Cursor[1].y = Cursor[0].y-TextMetric.tmHeight*sin(Theta+M_PI/2); for (j=0; jCount; j++) { td = (TTextData *)tl->Items[j]; if (td->hMem) { width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (td->pos>=k) { if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} ObliqueFont(td, sx, sy, (Byte *)lpBuf); GlobalUnlock(td->hMem); lpBuf = NULL; } } else { if (td->color==-1) { td->color = PaletteForm->DIB256Palette->GetFGCOLORREF(ti->Bitmap->BitsPerPixel); } if ((dwRet = GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, 0, NULL, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} if ((td->hMem = GlobalAlloc(GPTR, dwRet)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, dwRet, lpBuf, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); ObliqueFont(td, sx, sy, (Byte *)lpBuf); GlobalUnlock(td->hMem); lpBuf = NULL; } sx += (width+newdist)*cos(Theta); sy -= (width+newdist)*sin(Theta); if (td->pos<=CursorNewPos) { if ((sx>0 && sx0 && syStopScanLine(); ti->Bitmap->StopScanLine(); ti->Repaint(); while (Text->Count) { td = (TTextData *)Text->Last(); if (td->hMem) GlobalFree(td->hMem); HeapFree(GetProcessHeap(), 0, td); Text->Remove(td); } delete Text; Text = tl; return; fail: if (tl) { if (lpBuf) GlobalUnlock(td->hMem); while (tl->Count) { td = (TTextData *)tl->Last(); if (td->hMem) GlobalFree(td->hMem); HeapFree(GetProcessHeap(), 0, td); tl->Remove(td); } } ti->Bitmap->StopScanLine(); Original->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TTextForm::CircleFont(TTextData *td, double R, double Alpha, Byte *fbm) { TPItemImage *ti; int l, fx, fy, xx, yy; unsigned int x, y; Byte *dst; COLORREF c = td->color; ti = MainImageForm->iMainImage; fx = Pos[1].x+R*cos(Alpha)+td->gm.gmptGlyphOrigin.x; fy = Pos[1].y-R*sin(Alpha)-td->gm.gmptGlyphOrigin.y; l = ((td->gm.gmBlackBoxX+31)>>5)<<2; if (ti->Bitmap->BitsPerPixel==8) { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { dst = ti->Bitmap->GetScanLine(yy); for (x=0; xgm.gmBlackBoxX; x++) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { dst[xx] = c; } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } else { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { dst = ti->Bitmap->GetScanLine(yy)+3*fx; for (x=0; xgm.gmBlackBoxX; x++, dst+=3) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { SetPixel24(dst, c); } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } } //--------------------------------------------------------------------------- void __fastcall TTextForm::ViewCircle() { TList *tl = NULL; MAT2 m2; TPItemImage *ti; DWORD dwRet; void *lpBuf = NULL; int i, j, k, l, fx, fy, xx, yy, width, lx, ly; unsigned int x, y; Byte *fbm = NULL, *src, *dst; TTextData *td; double Alpha, Theta, R, a; bool cursor, out; int olddist, Width, Height, cx, cy,compx, compy; int ec = EC_NONE; #if defined(KNIT) Width = MainImageForm->iMainImage->ArrayBitmap[0].Width; Height = MainImageForm->iMainImage->ArrayBitmap[0].Height; #else Width = MainImageForm->iMainImage->Bitmap->Width; Height = MainImageForm->iMainImage->Bitmap->Height; #endif olddist = newdist; newdist = seInterval->Value; ti = MainImageForm->iMainImage; lx = Pos[0].x-Pos[1].x; ly = Pos[0].y-Pos[1].y; R = sqrt(lx*lx+ly*ly); Alpha = -atan2(ly, lx); if (Alpha<0) Alpha += 2*M_PI; k = CursorOldPos>CursorNewPos ? CursorNewPos : CursorOldPos; if (Original == NULL) { return; } else { if (!(Original->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} } if (!(ti->Bitmap->StartScanLine())) {ec = EC_MEMORY_LACK; goto fail;} for (i=0; iCount; i++) { td = (TTextData *)Text->Items[i]; width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (td->pos>k && td->hMem) { if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} fbm = (Byte *)lpBuf; fx = Pos[1].x+R*cos(Alpha)+td->gm.gmptGlyphOrigin.x; fy = Pos[1].y-R*sin(Alpha)-td->gm.gmptGlyphOrigin.y; l = ((td->gm.gmBlackBoxX+31)>>5)<<2; if (ti->Bitmap->BitsPerPixel==8) { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { src = Original->GetScanLine(yy); dst = ti->Bitmap->GetScanLine(yy); for (x=0; xgm.gmBlackBoxX; x++) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { dst[xx] = src[xx]; } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } else { for (y=0; ygm.gmBlackBoxY; y++) { yy = fy+y; if (yy>=0 && yyBitmap->Height) { src = Original->GetScanLine(yy)+3*fx; dst = ti->Bitmap->GetScanLine(yy)+3*fx; for (x=0; xgm.gmBlackBoxX; x++, src+=3, dst+=3) { xx = fx+x; if (xx>=0 && xxBitmap->Width) { if (fbm[x>>3]&(0x80>>(x&7))) { CopyPixel24(dst, src); } } } ti->Bitmap->PutScanLine(yy); } fbm += l; } } GlobalUnlock(td->hMem); lpBuf = NULL; fbm = NULL; } Alpha -= (width+olddist)/R; if (Alpha<0) Alpha += 2*M_PI; } if ((tl = MakeTextList()) == NULL) {ec = EC_MEMORY_LACK; goto fail;} Alpha = -atan2(ly, lx); if (Alpha<0) Alpha += 2*M_PI; a = 0; Cursor[0].x = Pos[1].x+(R-TextMetric.tmDescent)*cos(Alpha); Cursor[0].y = Pos[1].y-(R-TextMetric.tmDescent)*sin(Alpha); Cursor[1].x = Cursor[0].x+TextMetric.tmHeight*cos(Alpha); Cursor[1].y = Cursor[0].y-TextMetric.tmHeight*sin(Alpha); for (j=0; jCount; j++) { td = (TTextData *)tl->Items[j]; if (td->hMem) { width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (td->pos>=k) { GlobalFree(td->hMem); Theta = Alpha-M_PI/2; if (Theta<0) Theta += 2*M_PI; m2.eM11 = FixedFormDouble(cos(Theta)); m2.eM12 = FixedFormDouble(sin(Theta)); m2.eM21 = FixedFormDouble(-sin(Theta)); m2.eM22 = FixedFormDouble(cos(Theta)); if ((dwRet = GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, 0, NULL, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} if ((td->hMem = GlobalAlloc(GPTR, dwRet)) == NULL) goto fail; if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, dwRet, lpBuf, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (a+(width+newdist)/R<2*M_PI) { CircleFont(td, R, Alpha, (Byte *)lpBuf); GlobalUnlock(td->hMem); lpBuf = NULL; cursor = true; } else { GlobalUnlock(td->hMem); lpBuf = NULL; GlobalFree(td->hMem); td->hMem = 0; cursor = false; } } else { cursor = true; } } else { if (td->color==-1) { td->color = PaletteForm->DIB256Palette->GetFGCOLORREF(ti->Bitmap->BitsPerPixel); } Theta = Alpha-M_PI/2; if (Theta<0) Theta += 2*M_PI; m2.eM11 = FixedFormDouble(cos(Theta)); m2.eM12 = FixedFormDouble(sin(Theta)); m2.eM21 = FixedFormDouble(-sin(Theta)); m2.eM22 = FixedFormDouble(cos(Theta)); if ((dwRet = GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, 0, NULL, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} if ((td->hMem = GlobalAlloc(GPTR, dwRet)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((lpBuf = GlobalLock(td->hMem)) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((GetGlyphOutline(ti->Canvas->Handle, td->c, GGO_BITMAP, &td->gm, dwRet, lpBuf, &m2)) == GDI_ERROR) {ec = EC_FONT_NOSUPPORT; goto fail;} width = sqrt(td->gm.gmCellIncX*td->gm.gmCellIncX+td->gm.gmCellIncY*td->gm.gmCellIncY); if (a+(width+newdist)/R<2*M_PI) { CircleFont(td, R, Alpha, (Byte *)lpBuf); GlobalUnlock(td->hMem); lpBuf = NULL; cursor = true; } else { GlobalUnlock(td->hMem); lpBuf = NULL; GlobalFree(td->hMem); td->hMem = 0; cursor = false; } } Alpha -= (width+newdist)/R; if (Alpha<0) Alpha += 2*M_PI; a += (width+newdist)/R; if (cursor) { if (td->pos<=CursorNewPos) { Cursor[0].x = Pos[1].x+(R-TextMetric.tmDescent)*cos(Alpha); Cursor[0].y = Pos[1].y-(R-TextMetric.tmDescent)*sin(Alpha); Cursor[1].x = Cursor[0].x+TextMetric.tmHeight*cos(Alpha); Cursor[1].y = Cursor[0].y-TextMetric.tmHeight*sin(Alpha); if ((Cursor[1].x>0 && Cursor[1].x0 && Cursor[1].yStopScanLine(); ti->Bitmap->StopScanLine(); ti->Repaint(); while (Text->Count) { td = (TTextData *)Text->Last(); if (td->hMem) GlobalFree(td->hMem); HeapFree(GetProcessHeap(), 0, td); Text->Remove(td); } delete Text; Text = tl; return; fail: if (tl) { if (lpBuf) GlobalUnlock(td->hMem); while (tl->Count) { td = (TTextData *)tl->Last(); if (td->hMem) GlobalFree(td->hMem); HeapFree(GetProcessHeap(), 0, td); tl->Remove(td); } } ti->Bitmap->StopScanLine(); Original->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TTextForm::DrawLocate() { POINT l; double r; if (Shape==2) { l.x = Pos[1].x-Pos[0].x; l.y = Pos[1].y-Pos[0].y; r = sqrt(l.x*l.x+l.y*l.y); MainImageForm->DrawEllipseLocate(Rect(Pos[1].x-r, Pos[1].y-r, Pos[1].x+r, Pos[1].y+r)); } else { MainImageForm->DrawLineLocate(Pos[0], Pos[1]); } } //--------------------------------------------------------------------------- void __fastcall TTextForm::IsPosition() { if (bPosition) { Edit->Enabled = true; Edit->SetFocus(); ButtonOK->Enabled = true; } else { Edit->Enabled = false; ButtonOK->Enabled = false; } } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- __fastcall TTextForm::TTextForm(TComponent* Owner) : TForm(Owner) { //========================================================== StringTable.Create(DirectoryBin, Language, "Text"); SetSmallFont(Font); ButtonFont->Caption = IDS_FONT; Label1->Caption = IDS_FONT; Label2->Caption = IDS_COMMON_SIZE; Label3->Caption = IDS_SHAPE; Label4->Caption = IDS_INTERVAL; ComboBoxShape->Items->Clear(); ComboBoxShape->Items->Add(IDS_HORV); ComboBoxShape->Items->Add(IDS_COMMON_OBLIQUE); ComboBoxShape->Items->Add(IDS_CIRCLE); ButtonOK->Caption = IDS_COMMON_BUTTONOK; //=========================================================== } //--------------------------------------------------------------------------- bool __fastcall TTextForm::InitForm() { TIniFile *IniFile = NULL; int ec = EC_NONE; bool undoSw = false; TUndoData *ud; ParentHeight = Parent->Height+20; ClientHeight = 193; Parent->Height = ParentHeight+ClientHeight; if ((Text = new TList)==NULL) { ec = EC_MEMORY_LACK; goto fail; } IniFile = new TIniFile(DirectoryItem+"\\Text.ini"); if (IniFile) { MainImageForm->iMainImage->Canvas->Font->Name = IniFile->ReadString("Font", "Name", DefaultFontName); MainImageForm->iMainImage->Canvas->Font->Size = IniFile->ReadInteger("Font", "Size", 8); delete IniFile; } GetTextMetrics(MainImageForm->iMainImage->Canvas->Handle, &TextMetric); Shape = 0; bPosition = false; IsPosition(); Step = 0; newdist = 0; IsDraw = false; IsCursor = true; CursorOldPos = CursorNewPos = 0; if ((undoSw = MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height))) == false) { ec = EC_MEMORY_LACK; goto fail; } if ((ud = Undo->Last)==NULL) { ec = EC_UNDO_NONE; goto fail; } Original = ud->Bitmap; ComboBoxShape->ItemIndex = Shape; View(); return true; fail: if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- void __fastcall TTextForm::ExitForm() { TIniFile *IniFile; Undo->Read(); Original = NULL; IniFile = new TIniFile(DirectoryItem+"\\Text.ini"); if (IniFile) { IniFile->WriteString("Font", "Name", MainImageForm->iMainImage->Canvas->Font->Name); IniFile->WriteInteger("Font", "Size", MainImageForm->iMainImage->Canvas->Font->Size); delete IniFile; } DeleteText(); delete Text; ::RepaintImage(); } //--------------------------------------------------------------------------- void __fastcall TTextForm::iMainImageMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { POINT l; double R, Alpha, Theta; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) return; if (Button==mbLeft) { if (Step>0) { Pos[1] = Point(X, Y); switch (Shape) { case 0: l.x = Pos[1].x-Pos[0].x; l.y = Pos[1].y-Pos[0].y; if (abs(l.x)iMainImage->Bitmap->Copy(Original, SRCCOPY); MainImageForm->iMainImage->Repaint(); Pos[0] = Point(X, Y); Pos[1] = Pos[0]; bPosition = false; Step = 1; } IsPosition(); DrawLocate(); IsDraw = true; IsCursor = bPosition; } } //--------------------------------------------------------------------------- void __fastcall TTextForm::iMainImageMouseMove(TShiftState Shift, int X, int Y) { POINT l; if (Step>0) { if (IsDraw) DrawLocate(); Pos[1] = Point(X, Y); if (Shape==0) { l.x = Pos[1].x-Pos[0].x; l.y = Pos[1].y-Pos[0].y; if (abs(l.x)DrawLineLocate(Cursor[0], Cursor[1]); } //---------------------------------------------------------------------------