Browse Source

cmScore.h/c : Completed cmScoreGraphic*() function implementation.

master
Kevin Larke 8 years ago
parent
commit
8d8869bd6c
2 changed files with 38 additions and 25 deletions
  1. 37
    24
      app/cmScore.c
  2. 1
    1
      app/cmScore.h

+ 37
- 24
app/cmScore.c View File

@@ -2430,38 +2430,43 @@ cmScRC_t cmScoreGraphicAlloc( cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef)
2430 2430
   cmScRC_t       rc = kOkScRC;
2431 2431
   cmSc_t*        p  = _cmScHandleToPtr(h);
2432 2432
   cmScGraphic_t* v  = cmMemAllocZ(cmScGraphic_t,p->cnt);
2433
-  unsigned       i,j,k;
2433
+  unsigned       i,j,k,k0;
2434 2434
 
2435 2435
   unsigned       bordH = 5;
2436 2436
   unsigned       bordW = 5;
2437
-  unsigned       noteW = 100;
2438
-  unsigned       noteH = 100;
2439
-  unsigned       left  = 0;
2440
-  unsigned       top   = 0;
2441
-  unsigned       nextTop = 0;
2442
-  
2437
+  unsigned       noteW = 30;
2438
+  unsigned       noteH = 30;
2439
+  unsigned       left  = bordH;
2440
+  unsigned       top   = bordW;
2441
+
2442
+  // for each score location
2443 2443
   for(i=0,k=0; i<p->locCnt; ++i)
2444 2444
   {
2445
-    left += noteW + bordW;
2446
-    top   = nextTop + bordH;
2447
-    
2448
-    for(j=0; j<p->loc[i].evtCnt; ++i)
2445
+    left += k0!=k ? noteW + bordW : 0;
2446
+    top   = noteH + 2*bordH;
2447
+
2448
+    k0 = k;
2449
+
2450
+    // for each event in location i
2451
+    for(j=0; j<p->loc[i].evtCnt; ++j)
2449 2452
     {
2450 2453
       const cmScoreEvt_t* e = p->loc[i].evtArray[j];
2451 2454
       
2452 2455
       switch( e->type)
2453 2456
       {
2454
-        case kBarEvtScId:          
2457
+        case kBarEvtScId:
2458
+          top = bordH;
2459
+          
2455 2460
         case kNonEvtScId:
2456 2461
           
2457 2462
           assert( k < p->cnt );
2458 2463
           
2459
-          v[k].type     = e->type;
2460
-          v[k].scEvtIdx = e->index;
2461
-          v[k].left     = left;
2462
-          v[k].top      = top;
2463
-          v[k].width    = noteW;
2464
-          v[k].height   = noteH;
2464
+          v[k].type       = e->type;
2465
+          v[k].csvEventId = e->csvEventId;
2466
+          v[k].left       = left;
2467
+          v[k].top        = top;
2468
+          v[k].width      = noteW;
2469
+          v[k].height     = noteH;
2465 2470
           
2466 2471
           if( e->type == kBarEvtScId )
2467 2472
             v[k].text = cmTsPrintfP(NULL,"%i",e->barNumb);
@@ -2470,8 +2475,6 @@ cmScRC_t cmScoreGraphicAlloc( cmScH_t h, cmScGraphic_t** vRef, unsigned* nRef)
2470 2475
           
2471 2476
           top += noteH + bordH;
2472 2477
           
2473
-          if( top > nextTop )
2474
-            nextTop = top;
2475 2478
           
2476 2479
           k += 1;
2477 2480
           
@@ -2507,11 +2510,21 @@ cmScRC_t      cmScoreGraphicWriteF(  cmScH_t h, const cmChar_t* fn, cmScGraphic_
2507 2510
   cmScRC_t  rc = kOkScRC;
2508 2511
   cmSc_t*   p  = _cmScHandleToPtr(h);
2509 2512
   cmFileH_t fH = cmFileNullHandle;
2513
+  unsigned  i;
2510 2514
   
2511 2515
   if( cmFileOpen(&fH,fn,kWriteFileFl,p->err.rpt) != kOkFileRC )
2512 2516
     return cmErrMsg(&p->err,kFileFailScRC,"Graphic file create failed for '%s'.",cmStringNullGuard(fn));
2513 2517
 
2514
-  cmFilePrint(fH,"<!DOCTYPE html>\n<html>\n<body>\n<svg>\n");
2518
+  unsigned svgWidth  = v[n-1].left + v[n-1].width  + 10;
2519
+  unsigned svgHeight = 0;
2520
+
2521
+  for(i=0; i<n; ++i)
2522
+    if( v[i].top  + v[i].height > svgHeight )
2523
+      svgHeight = v[i].top  + v[i].height;
2524
+
2525
+  svgHeight += 10;
2526
+  
2527
+  cmFilePrintf(fH,"<!DOCTYPE html>\n<html>\n<head><link rel=\"stylesheet\" type=\"text/css\" href=\"score0.css\"></head><body>\n<svg width=\"%i\" height=\"%i\">\n",svgWidth,svgHeight);
2515 2528
   
2516 2529
   if((rc != cmScoreGraphicWrite(h,fH,v,n)) != kOkScRC )
2517 2530
     goto errLabel;
@@ -2531,15 +2544,15 @@ cmScRC_t      cmScoreGraphicWrite(   cmScH_t h, cmFileH_t fH, cmScGraphic_t* v,
2531 2544
   {
2532 2545
     const cmScGraphic_t* g = v + i;
2533 2546
     
2534
-    if( cmFilePrintf(fH,"<rect x=\"%i\" y=\"%i\" width=\"%i\" height=\"%i\" fill=\"white\"/>\n",g->left,g->top,g->width,g->height) != kOkFileRC )
2547
+    if( cmFilePrintf(fH,"<rect x=\"%i\" y=\"%i\" width=\"%i\" height=\"%i\" class=\"score\"/>\n",g->left,g->top,g->width,g->height) != kOkFileRC )
2535 2548
       return cmErrMsg(&p->err,kFileFailScRC,"File write failed on graphic file output.");
2536 2549
 
2537 2550
     if( g->text != NULL )
2538 2551
     {
2539 2552
       unsigned tx = g->left + g->width/2;
2540
-      unsigned ty = g->top  + g->height/2;
2553
+      unsigned ty = g->top  + 20; //g->height/2;
2541 2554
     
2542
-      if( cmFilePrintf(fH,"<text x=\"%i\" y=\"%i\" alignment-baseline=\"middle\" text-anchor=\"middle\">%s</text>\n",tx,ty,g->text) != kOkFileRC )
2555
+      if( cmFilePrintf(fH,"<text x=\"%i\" y=\"%i\" text-anchor=\"middle\" class=\"stext\">%s</text>\n",tx,ty,g->text) != kOkFileRC )
2543 2556
         return cmErrMsg(&p->err,kFileFailScRC,"File write failed on graphic file output.");
2544 2557
     }
2545 2558
     

+ 1
- 1
app/cmScore.h View File

@@ -275,7 +275,7 @@ extern "C" {
275 275
   typedef struct
276 276
   {
277 277
     unsigned        type;
278
-    unsigned        scEvtIdx;
278
+    unsigned        csvEventId;
279 279
     unsigned        left;
280 280
     unsigned        top;
281 281
     unsigned        width;

Loading…
Cancel
Save