Dear Dipannita,
thank you for contacting us.
Here is one way to proceed I just came up with:
-You get all the blocks
-For each block, get the the y top left corner, the height, and add these to get the y coordinate of the bottom of the block
-After getting the y coordinate of the bottom of all the blocks, get the highest one
-Call the addBlock function using the highest y coordinate
Here is a quick algorithm I just made (just take it as an example, and adapt it to your needs):
ContentBlock[] blocks=editor.getRootBlock().getChildren(); int nbBlocks = blocks.length; float ymax = 0; for(int i=0;i<nbBlocks;i++) { float y = blocks[i].getBox().y; float height = blocks[i].getBox().height; if(y+height>ymax) ymax=y+height; } editor.addBlock(0,ymax, "Diagram");
Also, in order to prevent your application from crashing, I recommend you catch any exception that is liekly to be risen from the addBlock function: https://developer.myscript.com/refguides/interactive-ink/android/1.3/com/myscript/iink/Editor.html#addBlock-float-float-java.lang.String-
Best regards,
Olivier
Thanks. After adding the above algorithm end result is same, y getting as 24.13, do I need to multiply anything with it? Please help I am stuck into this
Dear Dipannita,
the reason is that you do not have any sub-block, but only the root block, and therefore do addBlokck at (0,0).
In a first time, you can move/resize the block. Adding a second blokc should work fine
Another solution is that you export as JIIX, get the bounding box of your text result, and add block with the max y.
Best regards,
Olivier
Thanks for your reply. I have tried addBlock at(0,0), but did n't work addBlock(0, 0, "Text"); Even I tried adding MimeType. The only time it worked with some dummy text. But we can't add block with dummy text initially.
Second approach, I took JIIX export, add y and height from bounding-box of container block to locate y, note that no need to loop through children to find max y and height as container block bounding box y and height gives the same result. But still block gets added in the same position, what am I doing wrong?
{
"type": "Container",
"id": "MainBlock",
"bounding-box": {
"x": 6.8906269,
"y": 13.7805,
"width": 133.2188,
"height": 174.55301
}...
String str = editorView.getEditor().export_(editorView.getEditor().getRootBlock(), MimeType.JIIX);
JSONObject main = new JSONObject(str);
JSONObject bounding = main.getJSONObject("bounding-box");
Float y = Float.parseFloat(bounding.getString("y")) + Float.parseFloat(bounding.getString("height"));
Log.d(TAG, "contentChanged: " + y);
editorView.getEditor().addBlock(0, y, "Diagram");
Hey Olivier, can you please respond?
Dear Dipannita,
after discussing internally, we recommend you proceed this way instead:
float ymax = editor.getRootBlock().getBox().y+editor.getRootBlock().getBox().height;
Point p = new Point(0, ymax+5);
Renderer r = editor.getRenderer();
Transform v = r.getViewTransform();
v.apply(p);
editor.addBlock(p.x,p.y, "Diagram");
Best regards,
Olivier
Dear Olivier,
Thanks for your response.
I have tried your above code, got success only when I have written one line of text.
2. With less text in multiple lines, bellow is the result, first block got added in the beginning, next time got added in proper place.
3. Now the third one with proper 3 lines of text crashes the app
Could you please see what could be the issue with other two cases, I have tried isIdle()and waitForIdle()but same result.
Dear Dipannita,
currently, we recommend you parse all the sub-blocks instead, and get the and height of the one at the bottom. This can be done as follows:
try { float subblocksYMax=0; float height = 0; ContentBlock[] blocks = editorView.getEditor().getRootBlock().getChildren(); for(int i=0;i<blocks.length;i++) { float blockY = blocks[i].getBox().y; if(subblocksYMax< blockY) { subblocksYMax=blockY; height=blocks[i].getBox().height; } } float ymax = subblocksYMax + height; Point p = new Point(0.0f, ymax + 5.0f); Transform v = editorView.getEditor().getRenderer().getViewTransform(); v.apply(p); editorView.getEditor().addBlock(p.x, p.y, "Diagram"); } catch (Exception e) { Log.e(TAG, "Failed to add Diagram block ", e); }
Best regards,
Olivier
Dipannita Das
I want to give options like nebo app to embed diagram, math, text within a Text Document. So I have created a Part as "Text Document" and now after writing some text I want to add diagram just bellow it. I have to use addBlock , but what will be the x and y, how to set x, y dynamically?
Also I want to embed this entire document within a pdf. What will be the export format for this text document?