- Posts: 6
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
ObjsGetCharIndex only works at first time
IP: 192.168.0.71
11 years 9 months ago #6457
by discoby
ObjsGetCharIndex only works at first time was created by discoby
I want to get the hit word in OnPDFSingleTapped(float x, float y) of demo project.
But i can only get valid char's index at first time, than i just get -1 value after that.
anything i miss?????
Here is the code:
public boolean OnPDFSingleTapped(float x, float y)
{
PDFVPage vpage = m_view.vGetPage(m_pageno);
PDFPos pos = m_view.vGetPos((int)x, (int)y);
float pt[] = new float[2]; pt[0] = pos.x; pt[1] = pos.y;
Page page_cur = vpage.GetPage();
page_cur.ObjsStart();
int idx;
int hit_idx = page_cur.ObjsGetCharIndex(pt);
int hit_srart = hit_idx;
int hit_end = hit_idx;
idx = 1;
while (hit_srart != -1){
idx = page_cur.ObjsAlignWord(hit_srart, -1);
Log.d("###", "idx = " + idx + " hit_srart = " + hit_srart);
if (idx != -1 && idx != hit_srart)
hit_srart = idx;
else
break;
}
idx = 1;
while (hit_end != -1){
idx = page_cur.ObjsAlignWord(hit_end, 1);
Log.d("###", "idx = " + idx + " hit_end = " + hit_end);
if (idx != -1 && idx != hit_end)
hit_end = idx;
else
break;
}
String str = page_cur.ObjsGetString(hit_srart, hit_end+1);
Log.d("###", "str = " + str);
page_cur.Close();
But i can only get valid char's index at first time, than i just get -1 value after that.
anything i miss?????
Here is the code:
public boolean OnPDFSingleTapped(float x, float y)
{
PDFVPage vpage = m_view.vGetPage(m_pageno);
PDFPos pos = m_view.vGetPos((int)x, (int)y);
float pt[] = new float[2]; pt[0] = pos.x; pt[1] = pos.y;
Page page_cur = vpage.GetPage();
page_cur.ObjsStart();
int idx;
int hit_idx = page_cur.ObjsGetCharIndex(pt);
int hit_srart = hit_idx;
int hit_end = hit_idx;
idx = 1;
while (hit_srart != -1){
idx = page_cur.ObjsAlignWord(hit_srart, -1);
Log.d("###", "idx = " + idx + " hit_srart = " + hit_srart);
if (idx != -1 && idx != hit_srart)
hit_srart = idx;
else
break;
}
idx = 1;
while (hit_end != -1){
idx = page_cur.ObjsAlignWord(hit_end, 1);
Log.d("###", "idx = " + idx + " hit_end = " + hit_end);
if (idx != -1 && idx != hit_end)
hit_end = idx;
else
break;
}
String str = page_cur.ObjsGetString(hit_srart, hit_end+1);
Log.d("###", "str = " + str);
page_cur.Close();
IP: 192.168.0.71
11 years 9 months ago #6458
by discoby
Replied by discoby on topic ObjsGetCharIndex only works at first time
Now i can get other hit word every time, if i avoid doing page.close()...
But in some articles' reply, page.close() is necessary to avoid momory leak....
What is the correct procedure?????
But in some articles' reply, page.close() is necessary to avoid momory leak....
What is the correct procedure?????
IP: 192.168.0.71
11 years 9 months ago #6459
by radaee
Replied by radaee on topic ObjsGetCharIndex only works at first time
Page object obtained by PDFVPage object is managed by PDFView class.
you shall not close the Page object from PDFVPage.
you shall not close the Page object from PDFVPage.
Time to create page: 0.398 seconds