------------------------------------------------------------------------------
| 579 | |
| 580 | //------------------------------------------------------------------------------ |
| 581 | void vtkFreeTypeTools::MapTextPropertyToId(vtkTextProperty* tprop, size_t* id) |
| 582 | { |
| 583 | if (!tprop || !id) |
| 584 | { |
| 585 | vtkErrorMacro(<< "Wrong parameters, one of them is nullptr"); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | // The font family is hashed into 16 bits (= 17 bits so far) |
| 590 | const char* fontFamily = |
| 591 | tprop->GetFontFamily() != VTK_FONT_FILE ? tprop->GetFontFamilyAsString() : tprop->GetFontFile(); |
| 592 | size_t fontFamilyLength = 0; |
| 593 | if (fontFamily) |
| 594 | { |
| 595 | fontFamilyLength = strlen(fontFamily); |
| 596 | } |
| 597 | vtkTypeUInt32 hash = vtkFreeTypeTools::HashBuffer(fontFamily, fontFamilyLength); |
| 598 | |
| 599 | // Create a "string" of text properties |
| 600 | unsigned char ucValue = tprop->GetBold(); |
| 601 | hash = vtkFreeTypeTools::HashBuffer(&ucValue, sizeof(unsigned char), hash); |
| 602 | ucValue = tprop->GetItalic(); |
| 603 | hash = vtkFreeTypeTools::HashBuffer(&ucValue, sizeof(unsigned char), hash); |
| 604 | ucValue = tprop->GetShadow(); |
| 605 | hash = vtkFreeTypeTools::HashBuffer(&ucValue, sizeof(unsigned char), hash); |
| 606 | hash = vtkFreeTypeTools::HashBuffer(tprop->GetColor(), 3 * sizeof(double), hash); |
| 607 | double dValue = tprop->GetOpacity(); |
| 608 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 609 | hash = vtkFreeTypeTools::HashBuffer(tprop->GetBackgroundColor(), 3 * sizeof(double), hash); |
| 610 | dValue = tprop->GetBackgroundOpacity(); |
| 611 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 612 | hash = vtkFreeTypeTools::HashBuffer(tprop->GetFrameColor(), 3 * sizeof(double), hash); |
| 613 | ucValue = tprop->GetFrame(); |
| 614 | hash = vtkFreeTypeTools::HashBuffer(&ucValue, sizeof(unsigned char), hash); |
| 615 | int iValue = tprop->GetFrameWidth(); |
| 616 | hash = vtkFreeTypeTools::HashBuffer(&iValue, sizeof(int), hash); |
| 617 | iValue = tprop->GetFontSize(); |
| 618 | hash = vtkFreeTypeTools::HashBuffer(&iValue, sizeof(int), hash); |
| 619 | hash = vtkFreeTypeTools::HashBuffer(tprop->GetShadowOffset(), 2 * sizeof(int), hash); |
| 620 | dValue = tprop->GetOrientation(); |
| 621 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 622 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 623 | dValue = tprop->GetLineSpacing(); |
| 624 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 625 | dValue = tprop->GetLineOffset(); |
| 626 | hash = vtkFreeTypeTools::HashBuffer(&dValue, sizeof(double), hash); |
| 627 | iValue = tprop->GetUseTightBoundingBox(); |
| 628 | hash = vtkFreeTypeTools::HashBuffer(&iValue, sizeof(int), hash); |
| 629 | |
| 630 | // Set the first bit to avoid id = 0 |
| 631 | // (the id will be mapped to a pointer, FTC_FaceID, so let's avoid nullptr) |
| 632 | *id = 1; |
| 633 | |
| 634 | // Add in the hash. |
| 635 | // We're dropping a bit here, but that should be okay. |
| 636 | *id |= hash << 1; |
| 637 | |
| 638 | // Insert a copy of the TextProperty into the lookup table |