Text

Align text side by side in single line, keeping canvas data persistent

Hi,
I have a few requirements for my project


     
  1. Align text in single line after scribble conversion: After writing a sentence the converted words should align close each other in a sentence format
  2.  

  3. Keeping canvas data persistent: Keep recognized words even after application is minimized
  4.  

  5. Remove user stroke: I wish to remove user strokes which are recognized and provide editing control over word are text editor

I tried your application Smart Note, this provides exact features that I want in my project.


Dear Vikas,

We won’t be able to provide a specific snippet to integrate in your code on this forum actually, but we can provide some theoretical advices about eraser implementation:
- Store coordinates from onDrawing(InkCaptureView v, float x, float y) method
- Use those coordinates to create a segment that corresponds to the eraser movement
- For each stroke, use getX and getY methods and check if the eraser segment crosses a stroke (you will find useful help on usual android developer websites if you need)
- In that case, remove the stroke from the SmartPage

About a customized ITC integration in your project, it is difficult to answer without more details about the use case and the project structure. I also wonder if another widget such as Single Char or Single Line Text widget would better fit your needs.

Best regards

About your last question, I am not sure to understand what do you need an
I mean I can't create ITC layout in this project, I already use canvas and generate stroke data, I need your help to specify what input to give to which ATK library API call so that I get converted text as output from ATK, which I will display in my own canvas.
Thanks.

Sorry for the delay, your reply about 'Erasing drawing pen strokes:…' requires some reflections with the developer team. We will get back to you as soon as possible.
About your last question, I am not sure to understand what do you need and what happens exactly:
'-In another part of my project I have special requirement:
In this part I can’t integrate complete ITC sample, so I have to provide input to ITC library and render its converted text back in my project. I need you to specify how to provide input to text recognition API of ITC library.'
could you please give more details about this use case?
Best regards

-In another part of my project I have special requirement:
In this part I can't integrate complete ITC sample, so I have to provide input to ITC library and render its converted text back in my project. I need you to specify how to provide input to text recognition API of ITC library.

Update

– Erasing drawing pen strokes:…
Added a video for better understanding of eraser activity
Link --> http://1drv.ms/1Jcc7UE
Code that am using:

  @Override
public void onDrawing(InkCaptureView v, float x, float y)
{
  if(RecoActivity.erraseStrokes){
   Path allPath = v.getStrokePath();
   SmartPage page = mPageInterpreters[mSelectedPageInterpreterIndex].getPage();
   final List<SmartStroke> allStrokesList = page.getDrawingStrokes();
   final List<SmartStroke> noStrokesList = new ArrayList<SmartStroke>();
  
   inkChange(page, noStrokesList, allStrokesList);
  }
}

– Erasing drawing pen strokes:…
Few questions :
-How to check the intersection of the strokes in the « SmartPage » with the « InkCaptureView » stroke.
Am using final List<SmartStroke> allStrokesList = page.getStrokes(); but I get a list of all strokes, now how to check intersection.

-How to call « removeStroke » on the intersected Stroke

-removeStrokesrequire strokes not view so how to get strokes out of InkCaptureView
Provide with code snap or examples and also specify all tools that you say are available to implement erase activity.

Dear SelvaR,

thank you for the update.

From what I can read in your code, the only reason you could have uneven gaps is that your test on « wordGap <= 400 » is false and then you keep typesetting the words at « wordSpace = word.getLeftBound() ». Here the space is never homogenized contrary to what is done when setting « wordSpace = lastWordEnd + fontSize ». As the typesetting operation will change the width of the word (depending on the size of the font), you cannot keep the word at the same place AND have a homogenous space gap at the same time.

– Erasing drawing pen strokes:...

>>You can use the « removeStroke » or « removeStrokes » API functions. These normally do not remove all the strokes. I am not sure to understand the issue with building an eraser. You normally have all the tools to build it.
In the « MainViewController » Class, you can use the « onDrawing » and/or « onDrawEnd » callbacks to check the intersection of the strokes in the « SmartPage » with the « InkCaptureView » stroke. If you call « removeStroke » on the intersected Stroke it will update the « SmartStrokeLayoutView » plugged on the « MainViewController » class with the « inkChange » callback. Remember that « InkCaptureView » represents only the stroke you are currently writing. The previously inserted stroke in the « SmartPage » are drawn through a « SmartStrokeView » in the « SmartStrokeLayoutView ».

Also, there is already a topic to develop an erasure feature, which can be found here: http://developer-support.myscript.com/support/discussions/topics/16000007741

Last, in order to help you more precisely, would it be possible to get picture or video of the typse set operation? That would be of help.

I hope this answer your questions.

Best regards,

Olivier

-First of all what do you mean by « does not work...
I mean that strokes after conversion to text are places with uneven gaps and sometimes previous line words keep changing when scribbling in next line.

-Where and how is initialized/reset variable lastWordEnd ?
I initialize lastWordEnd and other variables in beginning of MainViewControler.java

//===== for text lines=====================================
private float mFirstLinePos;
private float mGap;
private int mLineCount;
private int fontSize = 40;
boolean converted = false;
private float wordGap = 0;
private float wordSpace = 0;
private float lastWordEnd = 0;

-Why do you have a particular case for « wordGap <= 400 » ?
This case is used to keep words in same place (where user writes) if user purposelessly scribbles with such large gap between each word.

-It seems that your « wordGap » variable is set 2 times...
I calculate gap between previous word and current word at the beginning of rearranging words. Yes as you said second time value does not impact the code

-You are using the « fontSize » as common value to add...
Sure as you suggested, now am using getSpaceWidth to get space for word gap.

if(wordGap <= 400){
     if(wordGap == 0){
      wordSpace = word.getLeftBound();
     }else{
      wordSpace = lastWordEnd + cbf.getSpaceWidth();
 
    }

– Erasing drawing pen strokes:
removeStroke removes all the strokes in canvas, I found a way to get (x,y) coordinates when using erase activity. Please provide method to erase strokes matching to (x,y) coordinates which are in that InkCaptureView.
When boolean value erraseStrokes is set(i.e. when erase tool is selected), I wish to erase strokes matching to that particular (x,y) coordinates in InkCaptureView v.

@Override
public void onDrawing(InkCaptureView v, float x, float y)
{
  if(RecoActivity.erraseStrokes){
   //mITCModelItemListener.onStrokeRemoved(removedStroke);
  }
}

Dear Vikas

- Arranging typeset:

We had a look to the portion of your code where you compute the position of the typeset words to respect consistent spaces. We are not sure to understand the implementation. Several remarks/questions :

-First of all what do you mean by « does not work as expected » could you please give more precisions please ?
-Where and how is initialized/reset variable lastWordEnd ?
-Why do you have a particular case for « wordGap <= 400 » ?
-It seems that your « wordGap » variable is set 2 times. At the end of the for loop and before the « wordGap <= 400 » test. Then the second affectation will have no effect. Is it what you want ?
-You are using the « fontSize » as common value to add space between words. I would suggest the « getSpaceWidth » method from the « CharBoxFactory » which should give you a better value. You can have a look at the « CharBoxFactory.java » file for the default implementation.

- Erasing drawing pen strokes:

If what you want to do is removing the drawing strokes from the SmartPage you should use the « removeStroke » API in the « SmartPage ». If what you mean is being able to remove drawing strokes after an erase gesture it is not a feature available through this component. Indeed gestures are only available on recognized strokes which are part of « SmartWord ». You could think of implementing an « Eraser » tool which could in a first version call the « removeStroke » API each time the « Eraser » stroke intersect with a stroke. In a second version you could consider removing the portion of the stroke intersected.

I hope those answers can help you. Feel free to come back to us if you have any doubt.

Best Regards,

Olivier

Hi,


I tried the typeset method and it's working fine, thanks.
I have few more requirements:
-- Arranging typeset words of same line in proper sentence format (after conversion to typeset, each word should have only a space gap).
I tried following way to calculate (highlighted in bold in code segment) space between subsequent words and place in sentence but does not work as expected
Code:

@Override
public void recognizerEnd(SmartPage arg0) {
 if(converted == false){
 List<SmartWord> words = mPageInterpreters[mSelectedPageInterpreterIndex].getPage().getWords();
 // Get the current page
  SmartPage currentPage = mPageInterpreters[mSelectedPageInterpreterIndex].getPage();
  // Get the word factory
  WordFactory wf = currentPage.getWordFactory();
  // Get the CharBoxFactory
  final CharBoxFactory cbf = (CharBoxFactory)wf.getCharBoxFactory();
 
  // Set the text size according to guidelines gap if any
  cbf.setTextSize(fontSize);
 
  // Create the list of typeset SmartWords
  final List<SmartWord> typeSetWords = new ArrayList<SmartWord>(words.size());
 
  for (SmartWord word : words)
  {
   //======on line=============================
   DisplayMetrics displayMetrics = new DisplayMetrics();
 
  WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
   wm.getDefaultDisplay().getMetrics(displayMetrics);
   float dpi = displayMetrics.densityDpi;
   float screenHeight = mContext.getResources().getDisplayMetrics().heightPixels;
   final int size = Math.round(screenHeight);
   final int densityDpi = mContext.getResources().getDisplayMetrics().densityDpi;
   mGap = 1.5f * densityDpi / 2.54f;
   mLineCount = Math.round(size / mGap);
   int txtLine = Math.round(word.getBaseLine() / mGap);
   if(txtLine == 0)
    txtLine = 1;
   int txtBottom = (int) ((int) mGap*txtLine);
   if (txtBottom > size)
    txtBottom = size;
<strong>wordGap = Math.abs(lastWordEnd - word.getLeftBound());
    if(wordGap <= 400){
     if(wordGap == 0){
      wordSpace = word.getLeftBound();
     }else{
      wordSpace = lastWordEnd + fontSize;
     }
    }else{
     wordSpace = word.getLeftBound();
    }</strong>
  if (word.getType() == SmartWord.Type.TYPESET)
  typeSetWords.add(word);
  else
  typeSetWords.add(wf.createTypeSetWord(word, wordSpace, txtBottom, word.getSpaceBefore()));
  lastWordEnd = word.getRightBound();
  wordGap = wordGap + word.getLeftBound();
  }
  currentPage.replaceWords(words, typeSetWords);
 }
 converted = true;
}

-- Erasing drawing pen stroke (which are not recognized by smart word)

Dear Vikas,
I think following posts may help you in your development:
http://developer-support.myscript.com/support/discussions/topics/16000007741
http://developer-support.myscript.com/support/discussions/topics/16000007740
http://developer-support.myscript.com/support/discussions/topics/16000007742
Please let us know if you have any specific question regarding those posts.
Best regards

I tried to modify code but could not automatically Typeset scribbled strokes, can you provide me with code-snippet or any way which will allow Typeset automatically after scribbles stroke, with little delay just like text conversion (scribbling a stroke and waiting will convert only that word or scribbling a sentence and waiting will convert all words scribbled)

public void inkChange(final SmartPage smartPage, final List<SmartStroke> addedStrokes, final List<SmartStroke> removedStrokes)
{
Handler mainHandler = new Handler(mContext.getMainLooper());


// Typeset the selected SmartWords
typesetWords(mPageInterpreters[mSelectedPageInterpreterIndex].getPage().getWords());


mainHandler.post(new Runnable()
{
@Override
public void run()
{
// Remove the graphical strokes
if (!removedStrokes.isEmpty())
for (SmartStroke removedStroke : removedStrokes)
mITCModelItemListener.onStrokeRemoved(removedStroke);

// Add the new graphical strokes
if (!addedStrokes.isEmpty())
for (SmartStroke addedStroke : addedStrokes)
mITCModelItemListener.onStrokeAdded(addedStroke);
}
});

}


Dear Vikas,

thank you for the precisions.

Actually, a lot of work was done internally for the Smart Note product, and many of the feaures of the Smart Note are not available in the widgets at present.

From this, you understand you would have to do a significant amount of work to get the same level of functionnality.

Nevertheless, some of the features you are requesting already exist in the ITC widget:
– Once user scribbles on canvas, stroke is converted to text (stroke is removed) later user can edit the converted text
>>Similar feature can be implement at present. You can find an example slecting text: Go to Menu -> Gestures -> selection -> Enable Gesture. You can then select ink, and decide to Typeset it.
=> From this, you understand using the inkChange method of the ISmartPageChangeListener, you can decide to Typeset the ink, and display it in your application.

– Lasso tool to select and drag the stroke/text to any position
=> With the above selection Gesture, you have a behavior similar to a lasso. Of course, you should tune the size/color of gesture to correspond to a lasso...
– Eraser to erase both text or stroke
=> Referring to the SmartPage API you can find in the documentation, you will find functions such as removeStroke, removeStrokes, removeWord, removeWords which you can use when a selection has been done...

In order to help you further, we would need more specification.

Nevertheless, keep in mind a lot of the Smart Note features are not available in the Widgets.

Best regards,

Olivier

Features that I require for my customized application similar to SmartNote

- Once user scribbles on canvas, stroke is converted to text (stroke is removed) later user can edit the converted text
- Lasso tool to select and drag the stroke/text to any position
- Eraser to erase both text or stroke

Provide me with API or code that would help me achieve these features

Hi Olivier,

- Am using ITC text widget
- Purpose of my project is to scribble like SmartNote over image, and provide text editing feature like SmartNote by eliminating user strokes and edit converted text
- But is there any code or API in ITC sample which I can use to bring SmartNote level functionality

Provide me with solutions to above requirements

Login or Signup to post a comment
  • Support
  • Forums
  • Text
  • Align text side by side in single line, keeping canvas data persistent