C++'ta Şekilleri Bağlayıcılarla Bağlama
Aspose.Slides FOSS’taki bağlayıcılar, diğer şekillerdeki bağlantı noktalarına bağlanan çizgi şekilleridir. Bağlı bir şekli hareket ettirdiğinizde, bağlayıcı uç noktası da onunla birlikte hareket eder. En yaygın bağlayıcı türü BENT_CONNECTOR3‘dir, bu da tek bir dirsek bükülmesiyle engellerin etrafından yönlendirir.
Önkoşullar
git clone https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
cd Aspose.Slides-FOSS-for-Cpp && mkdir build && cd build
cmake .. && cmake --build .Bağlantı Sitesi Dizinleri
Her şeklin dört numaralı bağlantı noktası vardır:
| İndeks | Konum |
|---|---|
0 | Üst orta |
1 | Sol orta |
2 | Alt orta |
3 | Sağ orta |
İki Şekli Bağla
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& slide = prs.slides()[0];
// Add two rectangles
auto& box1 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 50, 200, 200, 100);
auto& box2 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 450, 200, 200, 100);
box1.text_frame()->set_text("Start");
box2.text_frame()->set_text("End");
// Add a bent connector (initial bounds are overwritten by the connection)
auto& conn = slide.shapes().add_connector(
asf::ShapeType::BENT_CONNECTOR3, 0, 0, 10, 10);
// Connect right side of box1 (site 3) to left side of box2 (site 1)
conn.set_start_shape_connected_to(&box1);
conn.set_start_shape_connection_site_index(3);
conn.set_end_shape_connected_to(&box2);
conn.set_end_shape_connection_site_index(1);
prs.save("connected.pptx", asf::SaveFormat::PPTX);
return 0;
}Bağlantı uç noktaları ayarlandığında (0, 0, 10, 10) yer tutucu sınırları add_connector‘ye iletilir ve yok sayılır; PowerPoint bağlayıcıyı ekli şekillere yeniden yönlendirir.
Bağlayıcı Türleri
namespace asf = Aspose::Slides::Foss;
// Straight line
asf::ShapeType::STRAIGHT_CONNECTOR1;
// Single elbow (L-shape)
asf::ShapeType::BENT_CONNECTOR2;
// Double elbow (Z-shape): most common
asf::ShapeType::BENT_CONNECTOR3;
// Curved connector
asf::ShapeType::CURVED_CONNECTOR3;Bağlayıcı Çizgiyi Stilize Et
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& slide = prs.slides()[0];
auto& box1 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 50, 150, 180, 80);
auto& box2 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 500, 300, 180, 80);
auto& conn = slide.shapes().add_connector(
asf::ShapeType::BENT_CONNECTOR3, 0, 0, 10, 10);
conn.set_start_shape_connected_to(&box1);
conn.set_start_shape_connection_site_index(2); // bottom of box1
conn.set_end_shape_connected_to(&box2);
conn.set_end_shape_connection_site_index(0); // top of box2
// Style: dashed blue line, 2 pt width
auto& lf = conn.line_format();
lf.set_width(2.0);
lf.fill_format().solid_fill_color().set_color(asf::Color::blue);
lf.set_dash_style(asf::LineDashStyle::DASH);
prs.save("styled-connector.pptx", asf::SaveFormat::PPTX);
return 0;
}Birden Çok Bağlayıcıya Sahip Akış Diyagramı
#include <Aspose/Slides/Foss/presentation.h>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs;
auto& slide = prs.slides()[0];
// Three-step flowchart
auto& step1 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 350, 50, 200, 70);
auto& step2 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 350, 220, 200, 70);
auto& step3 = slide.shapes().add_auto_shape(
asf::ShapeType::RECTANGLE, 350, 390, 200, 70);
step1.text_frame()->set_text("Step 1");
step2.text_frame()->set_text("Step 2");
step3.text_frame()->set_text("Step 3");
auto connect_vertical = [&](auto& top_shape, auto& bottom_shape) {
auto& c = slide.shapes().add_connector(
asf::ShapeType::BENT_CONNECTOR3, 0, 0, 10, 10);
c.set_start_shape_connected_to(&top_shape);
c.set_start_shape_connection_site_index(2); // bottom
c.set_end_shape_connected_to(&bottom_shape);
c.set_end_shape_connection_site_index(0); // top
};
connect_vertical(step1, step2);
connect_vertical(step2, step3);
prs.save("flowchart.pptx", asf::SaveFormat::PPTX);
return 0;
}Bağlayıcı Özelliklerini Oku
#include <Aspose/Slides/Foss/presentation.h>
#include <iostream>
int main() {
namespace asf = Aspose::Slides::Foss;
asf::Presentation prs("connected.pptx");
for (size_t i = 0; i < prs.slides()[0].shapes().size(); ++i) {
auto& shape = prs.slides()[0].shapes()[i];
if (shape.is_connector()) {
auto& connector = static_cast<asf::Connector&>(shape);
std::cout << "Connector found\n";
}
}
return 0;
}