Browse Source

异形群组功能 CorelDRAW X4 和 X6 更新支持使用

Hongwenjun 2 months ago
parent
commit
fb8852ae28

+ 24 - 20
09_BoundaryGroup/BoundaryGroup.cpp

@@ -10,15 +10,15 @@ bool isDPCurve(IVGShapePtr s) {
   return dpc;
 }
 IVGShapePtr CreateBoundary(corel *cdr, IVGShapePtr s) {
-
-  auto scp = s->CreateBoundary(0, 0, true, false);
-
-  //  这个 API X7 以上才支持,所以现在直接画矩形
-  // BoundingBox box;
-  // s->GET_BOUNDING_BOX(box);
-  // auto scp = cdr->ActiveLayer->CreateRectangle2(box.x, box.y, box.w, box.h,
-  // ZERO_4PC);
-
+  IVGShapePtr scp;
+  if (cdr->VersionMajor < 17) {
+    s->CreateSelection();
+    cdr->FrameWork->Automation->InvokeItem( _bstr_t("b0491566-5ffe-450a-b17e-f2f496b4eb22"));
+    scp = cdr->ActiveSelectionRange->Shapes->Item[1];
+  } else {
+    //  这个 API X7 以上才支持,所以现在直接画矩形
+    scp = s->CreateBoundary(0, 0, true, false);    
+  }
   return scp;
 }
 
@@ -103,17 +103,23 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
 
 
   // 建立辅助的异性边界物件,需要填充颜色,搞了半天才搞定
-  auto bounds = sr->CreateBoundary(0, 0, true, false); // 建立异性边界物件
-  bounds->Fill->UniformColor->RGBAssign(255, 0, 0);    // 填充红色
+  IVGShapePtr bounds;
+  if (cdr->VersionMajor < 17) {
+    sr->CreateSelection();
+    cdr->FrameWork->Automation->InvokeItem( _bstr_t("b0491566-5ffe-450a-b17e-f2f496b4eb22"));
+    bounds = cdr->ActiveSelectionRange->Shapes->Item[1];
+    bounds->OrderToFront();
+  } else {
+    bounds = sr->CreateBoundary(0, 0, true, false); // 建立异性边界物件  
+  }
+
+  bounds->Fill->UniformColor->RGBAssign(255, 0, 0);
   auto sbox = bounds->BreakApartEx(); // 把边界 拆分为多个边界 用来分组
 
   if (sbox->Count > 2) {
     //  VGCore::IVGShapeRange::Sort ( _bstr_t CompareExpression, long
     //  StartIndex, long EndIndex, const _variant_t & Data );
-    sbox->Sort(
-      _bstr_t(
-            "@shape1.width * @shape1.height > @shape2.width * @shape2.height"),
-        1, sbox->Count, _variant_t());
+    sbox->Sort(bstr_t( "@shape1.width * @shape1.height > @shape2.width * @shape2.height"),  1, sbox->Count, _variant_t());
   }
 
   // 删除文字添加的方框
@@ -161,10 +167,8 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
 // 测试运行 异形群组
 void run_BoundaryGroup(corel *cdr) {
   auto start = std::chrono::high_resolution_clock::now(); // 开始时间
-  if (cdr->VersionMajor < 17) {
-    sprintf(infobuf, "异形群组目前只支持X7以上版本!");
-    return;
-  }
+  // if (cdr->VersionMajor < 17) {
+  //   sprintf(infobuf, "异形群组目前只支持X7以上版本!");  return; }
 
   BeginOpt(cdr);
 
@@ -178,7 +182,7 @@ void run_BoundaryGroup(corel *cdr) {
   cdr->ActiveDocument->ClearSelection();
 
   if (cnt > 300) {
-    // 调用矩形分组,分执行异形群组
+    // 调用矩形分组,分执行异形群组
     if (BoxGrouping(cdr, sr, sr_box, 0.1)) {
       for (int i = 0; i < sr_box->Count; i++) {
         auto s = sr_box->Shapes->Item[i + 1];

+ 4 - 0
09_BoundaryGroup/VBA_GMS/VbaCallCPG.bas

@@ -48,3 +48,7 @@ Sub Box_AutoGroup()
  ret = vbadll(10, -2#)
 End Sub
 
+'// 第11号功能: 异形群组功能
+Sub BoundaryGroup()
+ ret = vbadll(11, 0)
+End Sub

+ 6 - 0
09_BoundaryGroup/vbadll.cpp

@@ -48,11 +48,17 @@ try {
             Box_AutoGroup(cdr, x);
         break;
 
+        case 11:
+            run_BoundaryGroup(cdr);
+        break;
+
+
         default:
             return 0;
     }
 } catch (_com_error &e) {
     MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+    EndOpt(cdr);
 }
     return code;
 }