mcneel / rhino3dm

Libraries based on OpenNURBS with a RhinoCommon style
MIT License
573 stars 135 forks source link

Cannot get text from text entities #585

Closed fraguada closed 3 months ago

fraguada commented 4 months ago

Seems reading these on windows works fine, but breaks under linux.

fraguada commented 4 months ago

py work fine on linux but takes different routes to get Plain Text and Rich Text, etc js/py bindings go to

https://github.com/mcneel/opennurbs/blob/19df20038249fc40771dbd80201253a76100842c/opennurbs_annotationbase.cpp#L675

const ON_wString ON_Annotation::PlainText() const
{
  if (nullptr == m_text)
    return ON_wString::EmptyString;
  const ON_TextRunArray* runs = m_text->TextRuns(true);
  if (nullptr != runs && 0 == runs->Count())
    BoundingBox();  // Side effect of building text runs
  return m_text->PlainText();
}

and dotnet: https://github.com/mcneel/rhino3dm/blob/main/src/librhino3dm_native/on_text.cpp#L98

RH_C_FUNCTION void ON_V6_Annotation_GetTextString(const ON_Annotation* constAnnotation, ON_wString* wstring, bool rich)
{
  if (nullptr != wstring)
  {
    if (constAnnotation)
    {
      if (rich)
      {
        const ON_TextContent* text_content = constAnnotation->Text();
        if(nullptr != text_content)
          (*wstring) = text_content->PlatformRichTextFromRuns();
      }
      else
        (*wstring) = constAnnotation->PlainText();
    }
    else
      *wstring = ON_wString::EmptyString;
  }
}
fraguada commented 4 months ago

js / py only have RichText and PlainText exposed, need to expose PlainTextWithFields. js outputs empty string for RichText.

fraguada commented 4 months ago

For a 3dm with a text entity that has "Hello World!" as text, the outputs on linux

fraguada commented 3 months ago

Works across languages and platforms!

fraguada commented 3 months ago

published a beta to nuget: https://www.nuget.org/packages/Rhino3dm/8.6.0-beta