-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
294 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,15 @@ | |
// | ||
// Copyright 2022-2025, John McNamara, [email protected] | ||
|
||
use std::io::Cursor; | ||
use std::{collections::HashSet, io::Cursor}; | ||
|
||
use crate::xmlwriter::{ | ||
xml_data_element, xml_declaration, xml_empty_tag, xml_end_tag, xml_start_tag, | ||
}; | ||
|
||
pub struct FeaturePropertyBag { | ||
pub(crate) writer: Cursor<Vec<u8>>, | ||
pub(crate) feature_property_bags: HashSet<FeaturePropertyBagTypes>, | ||
} | ||
|
||
impl FeaturePropertyBag { | ||
|
@@ -24,7 +25,10 @@ impl FeaturePropertyBag { | |
pub(crate) fn new() -> FeaturePropertyBag { | ||
let writer = Cursor::new(Vec::with_capacity(2048)); | ||
|
||
FeaturePropertyBag { writer } | ||
FeaturePropertyBag { | ||
writer, | ||
feature_property_bags: HashSet::new(), | ||
} | ||
} | ||
|
||
// ----------------------------------------------------------------------- | ||
|
@@ -50,6 +54,14 @@ impl FeaturePropertyBag { | |
// Write the XFComplements <bag> element. | ||
self.write_xf_compliments_bag(); | ||
|
||
// Write the DXFComplements <bag> element. | ||
if self | ||
.feature_property_bags | ||
.contains(&FeaturePropertyBagTypes::DXFComplements) | ||
{ | ||
self.write_dxf_compliments_bag(); | ||
} | ||
|
||
// Close the feature_property_bagProperties tag. | ||
xml_end_tag(&mut self.writer, "FeaturePropertyBags"); | ||
} | ||
|
@@ -111,6 +123,22 @@ impl FeaturePropertyBag { | |
xml_end_tag(&mut self.writer, "bag"); | ||
} | ||
|
||
// Write the DXFComplements <bag> element. | ||
fn write_dxf_compliments_bag(&mut self) { | ||
let attributes = [ | ||
("type", "DXFComplements"), | ||
("extRef", "DXFComplementsMapperExtRef"), | ||
]; | ||
|
||
xml_start_tag(&mut self.writer, "bag", &attributes); | ||
xml_start_tag(&mut self.writer, "a", &[("k", "MappedFeaturePropertyBags")]); | ||
|
||
self.write_bag_id("", "2"); | ||
|
||
xml_end_tag(&mut self.writer, "a"); | ||
xml_end_tag(&mut self.writer, "bag"); | ||
} | ||
|
||
// Write the <bagId> element. | ||
fn write_bag_id(&mut self, key: &str, id: &str) { | ||
let mut attributes = vec![]; | ||
|
@@ -122,3 +150,9 @@ impl FeaturePropertyBag { | |
xml_data_element(&mut self.writer, "bagId", id, &attributes); | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Eq, PartialEq, Hash)] | ||
pub(crate) enum FeaturePropertyBagTypes { | ||
XFComplements, | ||
DXFComplements, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2032-2035, John McNamara, [email protected] | ||
// Copyright 2022-2025, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{Format, Workbook, XlsxError}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2025, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{Format, Workbook, XlsxError}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file_1(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
let worksheet = workbook.add_worksheet(); | ||
|
||
worksheet.write(0, 0, "Col1")?; | ||
worksheet.write(1, 0, 1)?; | ||
worksheet.write(2, 0, 2)?; | ||
worksheet.write(3, 0, 3)?; | ||
worksheet.write(4, 0, 4)?; | ||
|
||
worksheet.write(0, 1, "Col2")?; | ||
worksheet.insert_checkbox(1, 1, true)?; | ||
worksheet.insert_checkbox(2, 1, false)?; | ||
worksheet.insert_checkbox(3, 1, false)?; | ||
worksheet.insert_checkbox(4, 1, true)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
// Test with standard boolean value and format. | ||
fn create_new_xlsx_file_2(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
let worksheet = workbook.add_worksheet(); | ||
let format = Format::new().set_checkbox(); | ||
|
||
worksheet.write(0, 0, "Col1")?; | ||
worksheet.write(1, 0, 1)?; | ||
worksheet.write(2, 0, 2)?; | ||
worksheet.write(3, 0, 3)?; | ||
worksheet.write(4, 0, 4)?; | ||
|
||
worksheet.write(0, 1, "Col2")?; | ||
worksheet.write_boolean_with_format(1, 1, true, &format)?; | ||
worksheet.write_boolean_with_format(2, 1, false, &format)?; | ||
worksheet.write_boolean_with_format(3, 1, false, &format)?; | ||
worksheet.write_boolean_with_format(4, 1, true, &format)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_checkbox06_1() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("checkbox06") | ||
.set_function(create_new_xlsx_file_1) | ||
.unique("1") | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} | ||
|
||
#[test] | ||
fn test_checkbox06_2() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("checkbox06") | ||
.set_function(create_new_xlsx_file_2) | ||
.unique("2") | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
Oops, something went wrong.