Merge two formats first has higher precedence e.g., first = cell-level formatting and second = row-level formatting Result has attributes of both with cell-level formatting taking precedence
| 448 | // Result has attributes of both with cell-level |
| 449 | // formatting taking precedence |
| 450 | static Format merge(Format first, Format second) { |
| 451 | Format result; |
| 452 | |
| 453 | // Width and height |
| 454 | if (first.width_.has_value()) |
| 455 | result.width_ = first.width_; |
| 456 | else |
| 457 | result.width_ = second.width_; |
| 458 | |
| 459 | if (first.height_.has_value()) |
| 460 | result.height_ = first.height_; |
| 461 | else |
| 462 | result.height_ = second.height_; |
| 463 | |
| 464 | // Font styling |
| 465 | if (first.font_align_.has_value()) |
| 466 | result.font_align_ = first.font_align_; |
| 467 | else |
| 468 | result.font_align_ = second.font_align_; |
| 469 | |
| 470 | if (first.font_style_.has_value()) { |
| 471 | // Merge font styles using std::set_union |
| 472 | std::vector<FontStyle> merged_font_style(first.font_style_->size() + |
| 473 | second.font_style_->size()); |
| 474 | #if defined(_WIN32) || defined(_WIN64) |
| 475 | // Fixes error in Windows - Sequence not ordered |
| 476 | std::sort(first.font_style_->begin(), first.font_style_->end()); |
| 477 | std::sort(second.font_style_->begin(), second.font_style_->end()); |
| 478 | #endif |
| 479 | std::set_union(first.font_style_->begin(), first.font_style_->end(), |
| 480 | second.font_style_->begin(), second.font_style_->end(), |
| 481 | merged_font_style.begin()); |
| 482 | result.font_style_ = merged_font_style; |
| 483 | } else |
| 484 | result.font_style_ = second.font_style_; |
| 485 | |
| 486 | if (first.font_color_.has_value()) |
| 487 | result.font_color_ = first.font_color_; |
| 488 | else |
| 489 | result.font_color_ = second.font_color_; |
| 490 | |
| 491 | if (first.font_background_color_.has_value()) |
| 492 | result.font_background_color_ = first.font_background_color_; |
| 493 | else |
| 494 | result.font_background_color_ = second.font_background_color_; |
| 495 | |
| 496 | // Padding |
| 497 | if (first.padding_left_.has_value()) |
| 498 | result.padding_left_ = first.padding_left_; |
| 499 | else |
| 500 | result.padding_left_ = second.padding_left_; |
| 501 | |
| 502 | if (first.padding_top_.has_value()) |
| 503 | result.padding_top_ = first.padding_top_; |
| 504 | else |
| 505 | result.padding_top_ = second.padding_top_; |
| 506 | |
| 507 | if (first.padding_right_.has_value()) |