home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / tplab009.zip / tl_core.cpp < prev    next >
C/C++ Source or Header  |  1996-05-05  |  7KB  |  271 lines

  1. /* 
  2.  
  3.  
  4.     tl_core.cpp (emx+gcc) 
  5.     Tape Label Editor Version 0.09
  6.  
  7.     (C) 1996 Giovanni Iachello
  8.     This is freeware software. You can use or modify it as you wish,
  9.     provided that the part of code that I wrote remains freeware.
  10.     Freeware means that the source code must be available on request 
  11.     to anyone.
  12.     You must also include this notice in all files derived from this
  13.     file.
  14.  
  15.  
  16. */
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20.  
  21. #include "tapelab.h"
  22.  
  23. _labelformat::_labelformat()
  24. {
  25.     flaps=4;
  26.     size=0; 
  27.     title1=new char; *title1='\0';
  28.     title2=new char; *title2='\0';
  29.     text1=new char; *text1='\0';
  30.     text2=new char; *text2='\0';
  31.     date1=new char; *date1='\0';
  32.     date2=new char; *date2='\0';
  33.     source1=0;
  34.     source2=0;
  35.     nr1=0;
  36.     nr2=0;
  37.     for (int i=0; i<6; i++) whatinfo[i]=1;
  38.     
  39.     // init title fonts FATTRS and info
  40.     memset(&title1font,0,sizeof(title1font));
  41.     title1font.fattrs.usRecordLength = sizeof(FATTRS); /* sets size of structure   */
  42.     title1font.fattrs.usCodePage = 850;        /* code-page 850                    */
  43.     title1font.fattrs.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */
  44.     strcpy(title1font.fattrs.szFacename ,"Helvetica");
  45.     title1font.point=12;
  46.     title1font.height=16;
  47.  
  48.     title2font=title1font;
  49.  
  50.     text1font=title1font;
  51.     text1font.point=10;
  52.     text1font.height=12;
  53.     text2font=text1font;
  54.     datefont=text1font;
  55.     sourcefont=text1font;
  56.     nrfont=text1font;
  57.  
  58.     form.textvert1=form.textvert2=1100;
  59.     form.texthoriz1=form.texthoriz2=1000;
  60.     form.textlm=20;
  61.     form.texttm=20;
  62.     form.tabsize=100;
  63.     form.titlelm=30;
  64.     
  65.     customsize.width=1010;
  66.     customsize.flap[0]=160;
  67.     customsize.flap[1]=130;
  68.     customsize.flap[2]=645;
  69.     customsize.flap[3]=640;
  70.     writecustomfixpoints();
  71. }
  72.  
  73. _labelformat::~_labelformat()
  74. {
  75.     delete title1;
  76.     delete title2;
  77.     delete text1;
  78.     delete text2;
  79.     delete date1;
  80.     delete date2;
  81. }
  82.  
  83. char* filebanner="Tape Lab data file\x1a";
  84.  
  85. char version=0;
  86.  
  87. #define fwritestr(a,f) { \
  88.     int len = strlen(a) + 1; \
  89.     fwrite(&len,sizeof(len),1,f); \
  90.     fwrite(a,len,1,f); \
  91. }                        
  92.  
  93. #define freadstr(a,f) { \
  94.     int len; \
  95.     fread(&len,sizeof(len),1,f); \
  96.     a=new char[len]; \
  97.     fread(a,len,1,f); \
  98. }                        
  99.  
  100. BOOL _labelformat::save(const char* file)
  101. {
  102.     FILE *f=fopen(file,"wb");
  103.     if ( !f ) return FALSE;
  104.     fwrite(filebanner,strlen(filebanner)+1,1,f);
  105.     fwrite(&version,sizeof(version),1,f);
  106.     fwrite(&size,sizeof(size),1,f);
  107.     fwrite(&flaps,sizeof(flaps),1,f);
  108.     fwrite(&title1font,sizeof(title1font),1,f);
  109.     fwrite(&title2font,sizeof(title2font),1,f);
  110.     fwrite(&text1font,sizeof(text1font),1,f);
  111.     fwrite(&text2font,sizeof(text2font),1,f);
  112.     fwrite(&datefont,sizeof(datefont),1,f);
  113.     fwrite(&sourcefont,sizeof(sourcefont),1,f);
  114.     fwrite(&nrfont,sizeof(nrfont),1,f);
  115.     fwrite(&form,sizeof(form),1,f);
  116.     fwrite(&source1,sizeof(source1),1,f);
  117.     fwrite(&source2,sizeof(source2),1,f);
  118.     fwrite(&nr1,sizeof(nr1),1,f);
  119.     fwrite(&nr2,sizeof(nr2),1,f);
  120.     fwrite(whatinfo,sizeof(int),sizeof(6),f);
  121.  
  122.     fwritestr(title1,f);
  123.     fwritestr(title2,f);
  124.     fwritestr(text1,f);
  125.     fwritestr(text2,f);
  126.     fwritestr(date1,f);
  127.     fwritestr(date2,f);
  128.  
  129.     fwrite(&customsize,sizeof(customsize),1,f);
  130.  
  131.     if (fclose(f)) return FALSE;
  132.     return TRUE;
  133. }
  134.  
  135. BOOL _labelformat::load(const char* file)
  136. {
  137.     delete title1;
  138.     delete title2;
  139.     delete text1;
  140.     delete text2;
  141.     delete date1;
  142.     delete date2;
  143.     FILE *f=fopen(file,"rb");
  144.     if ( !f ) { _labelformat(); return FALSE; }
  145.  
  146.     char *signature=new char[strlen(filebanner)+2];
  147.     fread(signature,strlen(filebanner)+2,1,f);
  148.     // controlla che sia mia!
  149.     if ( strcmp(filebanner,signature) ) { 
  150.         _labelformat(); 
  151.         delete signature; 
  152.         return FALSE;    
  153.     }            
  154.     // controlla la versione
  155.     if ( signature[strlen(filebanner)+1] != version ) { 
  156.         _labelformat(); 
  157.         delete signature;
  158.         return FALSE; 
  159.     }
  160.  
  161.     fread(&size,sizeof(size),1,f);
  162.     fread(&flaps,sizeof(flaps),1,f);
  163.     fread(&title1font,sizeof(title1font),1,f);
  164.     fread(&title2font,sizeof(title2font),1,f);
  165.     fread(&text1font,sizeof(text1font),1,f);
  166.     fread(&text2font,sizeof(text2font),1,f);
  167.     fread(&datefont,sizeof(datefont),1,f);
  168.     fread(&sourcefont,sizeof(sourcefont),1,f);
  169.     fread(&nrfont,sizeof(nrfont),1,f);
  170.     fread(&form,sizeof(form),1,f);
  171.     fread(&source1,sizeof(source1),1,f);
  172.     fread(&source2,sizeof(source2),1,f);
  173.     fread(&nr1,sizeof(nr1),1,f);
  174.     fread(&nr2,sizeof(nr2),1,f);
  175.     fread(whatinfo,sizeof(int),sizeof(6),f);
  176.  
  177.     freadstr(title1,f);
  178.     freadstr(title2,f);
  179.     freadstr(text1,f);
  180.     freadstr(text2,f);
  181.     freadstr(date1,f);
  182.     freadstr(date2,f);
  183.  
  184.     fread(&customsize,sizeof(customsize),1,f);
  185.     writecustomfixpoints();
  186.  
  187.     delete signature;
  188.     fclose(f);
  189.     return TRUE;
  190. }
  191.  
  192. void _labelformat::newformat(_labelformat* nf)
  193. {
  194.     // load format information from newformat 
  195.     // do not update text fields...
  196.     flaps=nf->flaps;
  197.     size=nf->size; 
  198.     for (int i=0; i<6; i++) whatinfo[i]=nf->whatinfo[i];
  199.     
  200.     title1font=nf->title1font;
  201.  
  202.     title2font=nf->title2font;
  203.  
  204.     text1font=nf->text1font;
  205.     text2font=nf->text2font;
  206.     datefont=nf->datefont;
  207.     sourcefont=nf->sourcefont;
  208.     nrfont=nf->nrfont;
  209.  
  210.     form=nf->form;
  211.     customsize=nf->customsize;
  212.     writecustomfixpoints();
  213. }
  214.  
  215. void _labelformat::writecustomfixpoints() // write fixpoints structure with customsize data
  216. {
  217.     PMPoint pos(100,100);
  218.     fixpoints[3][8]=pos;
  219.     fixpoints[3][9]=pos;
  220.     fixpoints[3][9].x+=customsize.width;
  221.     for (int i=3; i>=0; i--)
  222.     {
  223.         pos.y+=customsize.flap[i];
  224.         fixpoints[3][i*2]=pos;
  225.         fixpoints[3][i*2+1]=pos;
  226.         fixpoints[3][i*2+1].x+=customsize.width;
  227.     }
  228. }
  229.  
  230. // label size:
  231. // 0 - vecchio tipo 3/4 flaps
  232. // 1 - cassette TDK nuove (piccole) 3 flaps
  233. // 2 - cassette Sony nuove (piccole) 2 flaps
  234.  
  235. POINTL fixpoints[4][10] = { 
  236.     {
  237.         { 100,1675}, { 1110,1675},
  238.         { 100,1515}, { 1110,1515},
  239.         { 100,1385}, { 1110,1385},
  240.         { 100,740 }, { 1110,740 },
  241.         { 100,100 }, { 1110,100 }
  242.     },
  243.     {
  244.         { 100,970 }, { 1110,970 },
  245.         { 100,870 }, { 1110,870 },
  246.         { 100,745 }, { 1110,745 },
  247.         { 100,100 }, { 1110,100 },
  248.         { 100,100 }, { 1110,100 }
  249.     },
  250.     {
  251.         { 100,840 }, { 1120,840 },
  252.         { 100,840 }, { 1120,840 },
  253.         { 100,740 }, { 1120,740 },
  254.         { 100,100 }, { 1120,100 },
  255.         { 100,100 }, { 1120,100 }
  256.     },
  257.     {
  258.         { 100,840 }, { 1120,840 },
  259.         { 100,840 }, { 1120,840 },
  260.         { 100,740 }, { 1120,740 },
  261.         { 100,100 }, { 1120,100 },
  262.         { 100,100 }, { 1120,100 }
  263.     }
  264. };
  265.  
  266. // TIPI DI NR
  267.  
  268. char *apchSources[]={ "CD","LP","MC","Radio","Master","Live","VTR" };
  269. char *apchNR[]={ "None","Dolby","Dolby B","Dolby C","Dolby S","dbx" };
  270.  
  271.