Hello guys! I have a question.
I want to do following:
Before I was working with V8I implementation, here everything worked fine :
I iterate through said cell descriptor. Whenever I found element with type TEXT_ELM, I changed its font size.
For extraction I used:
mdlText_extract(to extract TextSize from element). Change parameters in extracted TextSize structure. Recreate element with new font size, using mdlText_createW(myElement,myElement,NULL,NULL,NULL,&extractedSize,NULL,NULL,modelRef)
And all worked fine. However, in CONNECT it doesn´t work as expected. I managed it to work, so it changes the font size, but styling and transform suddenly disappears, so I´ve decided to check the new way with EditElementHandle and TextBlock API.
What I tried to do was (simple test to replace existing text) :
ElementHandle eh(out,modelRefP); //out is my MSElement extracted from MSElementDescr iteration i talked before EditElementHandle eeh(out, modelRefP); // Check if the selection is a Text element. ITextQueryCP textQuery = eh.GetITextQuery(); if (!textQuery || !textQuery->IsTextElement(eh)) return 1; // Extract the TextBlock from the Text element. ITextPartIdPtr textPart; TextBlockPtr textBlock = textQuery->GetTextPart(eh, *textPart); if (textBlock.IsNull() || textBlock->IsEmpty()) return 1; // Get the string from the Text block. WString str = textBlock->ToString(); if (str.empty()) return 1; RunPropertiesPtr runPropP = textBlock->GetRunPropertiesForAdd().Clone(); DPoint2d fontSize = runPropP->GetFontSize(); fontSize.x = 20; fontSize.y = 20; runPropP->SetFontSize(fontSize); textBlock->SetRunPropertiesForAdd(*runPropP); CaretPtr searchStart = textBlock->CreateStartCaret(); CaretPtr end = textBlock->CreateEndCaret(); textBlock->Remove(*searchStart,*end); EditElementHandle eeh2; textBlock->AppendText(L"Test"); TextBlockToElementResult res2 = TextHandlerBase::CreateElement(eeh2, nullptr, *textBlock);
My idea was to remove and re-enter same text with different properties, because I couldn´t find a way to do it without that (maybe there is some? Remapping doesn´t involve font size) and changing the RunProperties affects only actions that happen after it is set...
And, as you maybe expected, nothing happens, the text is same. I know that you can call AddToModel (then it appears in model, but the original is still same). I also saw ReplaceInModel function, but the elements have no ElementRef yet.
I´ve tried this (with a little hope):
*out = *eeh2.getElementP();
But i got segfault during the iteration of next elements
Do you guys know how to approach something like this?
Well I found a working solution. I couldn´t get the new API to work the way as I wanted (or I didn´t find a proper way yet), but I managed it to work with old mdlText_create function. The thing is, in V8I, I was using mdlText_createWide, and after you used this function for text element, it recreated the text element with same font, style etc (even though I passed nullptr as arguments for these) . But in CONNECT, it recreates text element + it also "resets" other stuff. So I had to pass these parameters to this function as well (even though they were unchanged). This way, I got the element I wanted with changed font size.
Hi Lubo,
Lubo B said:but I managed it to work with old mdlText_create function.
your question was how to change the font size for (existing) text, so I am not sure how "text create" function can be the solution?
Lubo B said:But in CONNECT, it recreates text element + it also "resets" other stuff.
I have no experience with native API in CE in this case, but TextBlock API, available in NET (which is a think wrapper around the same native API), does allow really to modify (replace) text or to change parameters, whereas other settings are maintained. I did not do any detail testing whether all data (user attributes, XAttributes/EC data) is maintained, but I guess they are, because the element is not created as a new one from scratch.
Lubo B said:This way, I got the element I wanted with changed font size.
As I wrote earlier, to change the font size can be achieved several different ways. Without a help of text style (which is always preferred), the size can be set at "run level", and it works just fine.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Lubo B said:simple test to replace existing text
Here's an example that replaces text in a stand-alone text element or text in a cell. It works with the TextBlock API and ChildElementIter for cells.
TextBlock
ChildElementIter
Regards, Jon Summers LA Solutions