Example #1
0
/*
 * Class:     org_coolreader_crengine_ReaderView
 * Method:    updateSelectionInternal
 * Signature: (Lorg/coolreader/crengine/Selection;)V
 */
JNIEXPORT void JNICALL Java_org_coolreader_crengine_ReaderView_updateSelectionInternal
  (JNIEnv * _env, jobject _this, jobject _sel)
{
    CRJNIEnv env(_env);
    ReaderViewNative * p = getNative(_env, _this);
    CRObjectAccessor sel(_env, _sel);
    CRStringField sel_startPos(sel, "startPos");
    CRStringField sel_endPos(sel, "endPos");
    CRStringField sel_text(sel, "text");
    CRStringField sel_chapter(sel, "chapter");
    CRIntField sel_startX(sel, "startX");
    CRIntField sel_startY(sel, "startY");
    CRIntField sel_endX(sel, "endX");
    CRIntField sel_endY(sel, "endY");
    CRIntField sel_percent(sel, "percent");
    lvPoint startpt ( sel_startX.get(), sel_startY.get() );
    lvPoint endpt ( sel_endX.get(), sel_endY.get() );
	ldomXPointer startp = p->_docview->getNodeByPoint( startpt );
	ldomXPointer endp = p->_docview->getNodeByPoint( endpt );
    if ( !startp.isNull() && !endp.isNull() ) {
        ldomXRange r( startp, endp );
        if ( r.getStart().isNull() || r.getEnd().isNull() )
            return;
        r.sort();
		if ( !r.getStart().isVisibleWordStart() )
			r.getStart().prevVisibleWordStart();
		//lString16 start = r.getStart().toString();
		if ( !r.getEnd().isVisibleWordEnd() )
			r.getEnd().nextVisibleWordEnd();
        if ( r.isNull() )
            return;
        //lString16 end = r.getEnd().toString();
        //CRLog::debug("Range: %s - %s", UnicodeToUtf8(start).c_str(), UnicodeToUtf8(end).c_str());
        r.setFlags(1);
        p->_docview->selectRange( r );
        int page = p->_docview->getBookmarkPage(startp);
        int pages = p->_docview->getPageCount();
        lString16 titleText;
        lString16 posText;
        p->_docview->getBookmarkPosText(startp, titleText, posText);
        int percent = 0;
        if ( pages>1 )
        	percent = 10000 * page/(pages-1);
        lString16 selText = r.getRangeText( '\n', 8192 );
        sel_percent.set(percent);
    	sel_startPos.set( startp.toString() );
    	sel_endPos.set( endp.toString() );
    	sel_text.set(selText);
    	sel_chapter.set(titleText);
    }

}
Example #2
0
/*
 * Class:     org_coolreader_crengine_ReaderView
 * Method:    moveSelectionInternal
 * Signature: (Lorg/coolreader/crengine/Selection;II)Z
 */
JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_ReaderView_moveSelectionInternal
  (JNIEnv * _env, jobject _this, jobject _sel, jint _cmd, jint _param)
{
    CRJNIEnv env(_env);
    ReaderViewNative * p = getNative(_env, _this);
    CRObjectAccessor sel(_env, _sel);
    CRStringField sel_startPos(sel, "startPos");
    CRStringField sel_endPos(sel, "endPos");
    CRStringField sel_text(sel, "text");
    CRStringField sel_chapter(sel, "chapter");
    CRIntField sel_startX(sel, "startX");
    CRIntField sel_startY(sel, "startY");
    CRIntField sel_endX(sel, "endX");
    CRIntField sel_endY(sel, "endY");
    CRIntField sel_percent(sel, "percent");
    int res = p->_docview->doCommand( (LVDocCmd)_cmd, (int)_param );
    if ( res ) {
        ldomXRangeList & sel = p->_docview->getDocument()->getSelections();
        if ( sel.length()>0 ) {
            ldomXRange currSel;
            currSel = *sel[0];
            if ( !currSel.isNull() ) {
                sel_startPos.set( currSel.getStart().toString() );
                sel_endPos.set( currSel.getEnd().toString() );
                lvPoint startpt ( currSel.getStart().toPoint() );
                lvPoint endpt ( currSel.getEnd().toPoint() );
                sel_startX.set( startpt.x );
                sel_startY.set( startpt.y );
                sel_endX.set( endpt.x );
                sel_endY.set( endpt.y );

                int page = p->_docview->getBookmarkPage(currSel.getStart());
                int pages = p->_docview->getPageCount();
                lString16 titleText;
                lString16 posText;
                p->_docview->getBookmarkPosText(currSel.getStart(), titleText, posText);
                int percent = 0;
                if ( pages>1 )
                	percent = 10000 * page/(pages-1);
                lString16 selText = currSel.getRangeText( '\n', 8192 );
                sel_percent.set(percent);
            	sel_text.set(selText);
            	sel_chapter.set(titleText);

            	return JNI_TRUE;
            }
        }
    }
    return JNI_FALSE;
}
Example #3
0
Adesk::Boolean
AsdkSmiley::worldDraw(AcGiWorldDraw *wd)
{
    assertReadEnabled();

    AcGeVector3d offset(0,0,0);
    AcGeCircArc3d face = mfacecircle;

    // If dragging, don't fill the smiley
    //
    if( wd->isDragging() ){
        wd->subEntityTraits().setColor( colorIndex() );
        wd->subEntityTraits().setFillType( kAcGiFillNever );
    }
    else
        wd->subEntityTraits().setFillType( kAcGiFillAlways );

    // Give the circle a GS marker of 1
    //
    wd->subEntityTraits().setSelectionMarker( 1 );
    wd->geometry().circle( face.center(), face.radius(), mnormal );

    if( !wd->isDragging() )
        wd->subEntityTraits().setColor( 250 );

    // Give the eyes GS markers of 2 etc.
    //
    AcGePoint3dArray eyearray;

    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        wd->subEntityTraits().setSelectionMarker( i + 2 );
        wd->geometry().circle( eyearray.at(i) + offset, meyesize, mnormal );
    }

    AcGePoint3d smilecen( mouthCenter() + offset ),
                startpt( mouthLeft() + offset ),
                endpt( mouthRight() + offset );
    AcGeVector3d startvec = startpt - smilecen,
                 endvec = endpt - smilecen;
    double mouthangle = startvec.angleTo( endvec );

    wd->subEntityTraits().setSelectionMarker( eyearray.length() + 2 );
    wd->geometry().circularArc( smilecen, mouthRadius(), mnormal, startvec, mouthangle, kAcGiArcChord );
    return Adesk::kTrue;
}
Example #4
0
/**
 * Returns the baseline of the current object at the given level.
 * The baseline is the line that passes through (x1, y1) and (x2, y2).
 * WARNING: with vertical text, baselines may be vertical!
 */
bool PageIterator::Baseline(PageIteratorLevel level,
                            int* x1, int* y1, int* x2, int* y2) const {
  if (it_->word() == NULL) return false;  // Already at the end!
  ROW* row = it_->row()->row;
  WERD* word = it_->word()->word;
  TBOX box = (level == RIL_WORD || level == RIL_SYMBOL)
           ? word->bounding_box()
           : row->bounding_box();
  int left = box.left();
  ICOORD startpt(left, static_cast<inT16>(row->base_line(left) + 0.5));
  int right = box.right();
  ICOORD endpt(right, static_cast<inT16>(row->base_line(right) + 0.5));
  // Rotate to image coordinates and convert to global image coords.
  startpt.rotate(it_->block()->block->re_rotation());
  endpt.rotate(it_->block()->block->re_rotation());
  *x1 = startpt.x() / scale_ + rect_left_;
  *y1 = (rect_height_ - startpt.y()) / scale_ + rect_top_;
  *x2 = endpt.x() / scale_ + rect_left_;
  *y2 = (rect_height_ - endpt.y()) / scale_ + rect_top_;
  return true;
}
Example #5
0
void AsdkSmiley::ensureRadius()
{
    AcGeVector2d vec( meyesapart / 2, meyesheight );
    if (( vec.length() + 1.2 * meyesize ) > radius() )
        setRadius( vec.length() + 1.2 * meyesize);

    AcGePoint3d center( center() ),
                smilecen( mouthCenter() ),
                startpt( mouthLeft() ),
				endpt( mouthRight() ),
				botpt( mouthBottom() );

    AcGeVector3d vecstart = startpt - smilecen;

    if ( center.distanceTo( startpt ) > radius() / 1.1 )
        setRadius( 1.1 * center.distanceTo( startpt ));
    
	if ( center.distanceTo( endpt ) > radius() / 1.1 )
        setRadius( 1.1 * center.distanceTo( endpt ));

	if ( center.distanceTo( botpt ) > radius() / 1.1 )
        setRadius( 1.1 * center.distanceTo( botpt ));
}
Example #6
0
Acad::ErrorStatus
AsdkSmiley::explode(AcDbVoidPtrArray& entities) const
{
    assertReadEnabled();

    AcDbCircle *pCircle = new AcDbCircle( center(), mnormal, radius() );
    entities.append( pCircle );

    // Create eyes
    //
    AcGePoint3dArray eyearray;
    eyes( eyearray );
    for( int i = 0; i < eyearray.length(); i++ ){
        AcDbCircle *pCircle = new AcDbCircle( eyearray.at(i), mnormal, meyesize );
        entities.append( pCircle );
    }

    // Create smile arc
    //
    AcGePoint3d smilecen( mouthCenter() ),
                startpt( mouthLeft() ),
                endpt( mouthRight() );
    AcGeVector3d normvec( 1, 0, 0 ),
                 startvec = startpt - smilecen,
                 endvec = endpt - smilecen;
    double startang = 2 * kPi - startvec.angleTo( normvec ),
           endang = 2 * kPi - endvec.angleTo( normvec );
    AcDbArc *pArc = new AcDbArc( smilecen, mnormal, mouthRadius(), startang, endang );
    entities.append( pArc );

    // Create smile arc chord
    //
    AcDbLine *pLine = new AcDbLine( startpt, endpt );
    entities.append( pLine );

    return Acad::eOk;
}
Example #7
0
bool TFtp::Server::Run() {
  sys::error_code         err;
  asio::ip::udp::endpoint endpt(asio::ip::address::from_string(_ip), kPort);
  while (1) {
    _io.reset();
    // ожидание новых подключений
    if (not _new_sess) {
      _new_sess.reset(new Session(_io));
      _new_sess->Open(&endpt);
      _new_sess->AsyncAccept();
      _sessions.push_front(_new_sess);
    }
    // полинг сессий
    for (auto sess_it = _sessions.begin(); sess_it != _sessions.end(); sess_it++) {
      Session::Ptr sess_ptr = *sess_it;
      if (not sess_ptr) {
        continue;
      }
      sess_ptr->Process(_pub_files);
      if (not sess_ptr->IsAlive()) {
        sess_it = _sessions.erase(sess_it);
        _new_sess.reset();
        _io.stop();
        return true;
      }
    }
    _io.run(err);
    if (err) {
      std::cout << "Ошибка сервера: " << err << "; "
                << std::endl;
      break;
    }
  }
  _io.stop();
  return false;
}
Example #8
0
// deletes a selection and it's contents
void EditView::SelDel()
{
EditView *ev = this;
int old_cy;

	if (ev->selection.present)
	{
		int x1, y1, x2, y2;
		
		BeginUndoGroup(ev);
		GetSelectionExtents(ev, &x1, &y1, &x2, &y2);
		
		lstat2(" ** SelDel from [%d,%d] - [%d,%d]", x1, y1, x2, y2);
		
		// remember current screen position of cursor
		old_cy = ev->cursor.screen_y;
		
		// when undoing a seldel always move cursor to the end of the deleted text
		DocPoint endpt(ev, x2, y2);
		endpt.Increment();
		
		// delete selection and it's contents
		selection_drop(ev);
		ev->action_delete_range(x1, y1, x2, y2);
		
		// move to start of selection
		ev->cursor.move(x1, y1);
		
		// ensure cursor is still visible, and try to keep it at the
		// same screen Y position it was at before (when deleting a large portion of text)
		ev->BringLineIntoView(ev->cursor.y, BV_SPECIFIC_Y, old_cy);
		XScrollToCursor();
		
		EndUndoGroupSetCursor(ev, endpt.x, endpt.y);
	}
}
Example #9
0
//create the mesh for edges based on variable size from SizingFunction (var)
void EdgeMesher::VariableMeshing(ModelEnt *ent, int &num_edges, std::vector<double> &coords)
{
  double umin, umax, measure;
  (void) measure;
  // because of that, keep track of the first node position and last node position
  // first node position does not change, but the last node position do change
  // coords will contain all nodes, including umax in Urecord!

  SizingFunction *sf = mk_core()->sizing_function(ent->sizing_function_index());
  //get the u range for the edge
  iGeom::EntityHandle edge = ent->geom_handle();
  iGeom::Error gerr = ent->igeom_instance() ->getEntURange(edge, umin, umax);
  IBERRCHK(gerr, "Trouble get parameter range for edge.");

  if (umin == umax) throw Error(MK_BAD_GEOMETRIC_EVALUATION, "Edge evaluated to some parameter umax and umin.");

  //get the arc length
  measure = ent -> measure();

  // start advancing for each edge mesh, from the first point position
  double currentPar = umin;
  double currentPosition[3];
  gerr = ent->igeom_instance() ->getEntUtoXYZ(edge, umin, currentPosition[0],
      currentPosition[1], currentPosition[2] );

  double endPoint[3];
  gerr = ent->igeom_instance() ->getEntUtoXYZ(edge, umax, endPoint[0],
      endPoint[1], endPoint[2] );
  Vector<3> endpt(endPoint);

  double targetSize = sf->size(currentPosition);
  double startSize = targetSize;

  double endSize = sf->size(endPoint);
  // advance u such that the next point is at "currentSize" distance
  // or close to it
  // try first with a u that is coming from the (umax-umin)/number of edges
  double deltaU = (umax-umin)/num_edges;
  //coords.clear(); we do not want to clear, as the first node is still fine
  std::vector<double> URecord;    //record the values for u; we may have to adjust all
  // of them accordingly, and even add one more if we have some evenify problems.
  // keep in mind that size is just a suggestion, number of intervals is more important for
  // paver mesher
  Vector<3> pt(currentPosition);

  //bool notDone = true;
  double prevU = umin;
  while (currentPar + 1.1*deltaU < umax)
  {
    // do some binary search; actually, better, do Newton-Raphson, which should converge
    // faster
    //
    prevU = currentPar;
    currentPar += deltaU;
    // adjust current par, such that
    double point[3];
    gerr=ent->igeom_instance()->getEntUtoXYZ(edge, currentPar, point[0], point[1], point[2] );
    IBERRCHK(gerr, "Trouble getting position at parameter u.");
    Vector<3> ptCandidate(point);
    double compSize = length(ptCandidate-pt);
    int nit = 0;

    while ( (fabs(1.-compSize/targetSize)> 0.02 ) && (nit < 5))// 2% of the target size
    {
      // do Newton iteration
      double tangent[3];
      gerr=ent->igeom_instance() ->getEntTgntU(edge, currentPar, tangent[0], tangent[1], tangent[2] );
      IBERRCHK(gerr, "Trouble getting tangent at parameter u.");
      Vector<3> tang(tangent);
      double dldu = 1./compSize * ((ptCandidate-pt )%tang);
      nit++;// increase iteration count
      if (dldu!=0.)
      {
        double deu= (targetSize-compSize)/dldu;
        currentPar+=deu;
        if (prevU>currentPar)
        {
          break; // something is wrong
        }
        if (umax < currentPar)
        {
          currentPar = umax;
          break;
        }
        ent->igeom_instance()->getEntUtoXYZ(edge, currentPar, point[0], point[1], point[2]);
        Vector<3> newPt(point);
        compSize = length(newPt-pt);
        ptCandidate = newPt;
      }

    }
    // we have found an acceptable point/param
    URecord.push_back(currentPar);
    deltaU = currentPar-prevU;// should be greater than 0
    pt = ptCandidate;
    targetSize = sf->size(pt.data());// a new target size, at the current point



  }
  // when we are out of here, we need to adjust the URecords, to be more nicely
  // distributed; also, look at the evenify again
  int sizeU = (int)URecord.size();
  if ((sizeU%2==0) && ent->constrain_even() )
  {
    // add one more
    if (sizeU==0)
    {
      // just add one in the middle, and call it done
      URecord.push_back( (umin+umax)/2);
    }
    else
    {
      //at least 2 (maybe 4)
      double lastDelta = URecord[sizeU-1]-URecord[sizeU-2];
      URecord.push_back(URecord[sizeU-1]+lastDelta );
    }
  }
  // now, we have to redistribute, such as the last 2 deltas are about the same
  // so, we should have after a little work,
  // umin, umin+c*(URecord[0]-umin), ... umin+c*(URecord[size-1]-umin), umax
  // what we have now is
  // umin, URecord[0], ... ,URecord[size-1], and umax could be even outside or inside
  // keep the last sizes equal
  //  umin+c(UR[size-2]-umin) + umax = 2*( umin+c*(UR[size-1]-umin))
  //  c ( 2*(UR[size-1]-umin) -(UR[size-2]-umin) ) = umax - umin
  // c ( 2*UR[size-1] - UR[size-2] - umin ) = umax - umin
  // c = (umax-umin)/( 2*UR[size-1] - UR[size-2] - umin)
  sizeU = (int)URecord.size();// it may be bigger by one than the last time
  if (sizeU == 0)
  {
    // nothing to do, only one edge to generate
  }
  else if (sizeU == 1)
  {
    // put it according to the sizes at ends, and assume a nice variation for u
    // (u-umin) / (umax-u) = startSize / endSize
    // (u-umin)*endSize = (umax-u) * startSize
    // u(endSize+startSize)=(umax*startSize+umin*endSize)
    URecord[0] = (umax*startSize+umin*endSize)/(startSize+endSize);

  }
  else // sizeU>=2, so we can spread the param a little more, assuming nice
    // uniform mapping
  {
    double c =  (umax-umin)/( 2*URecord[sizeU-1] - URecord[sizeU-2] - umin);
    for (int i=0; i<sizeU; i++)
      URecord[i] = umin + c*(URecord[i] -umin);// some spreading out
  }
  // now, we can finally get the points for each U, U's should be spread out nicely
  URecord.push_back(umax); // just add the last u, for the end point
  //
  sizeU = (int) URecord.size(); // new size, after pushing the last u, umax
  num_edges = sizeU;// this is the new number of edges; the last one will be the end point
  // of the edge, corresponding to umax
  coords.resize(3*sizeU+3);
  // we already know that at i=0 is the first node, start vertex of edge
  // the rest will be computed from u
  // even the last one, which is an overkill
  for (int i = 1; i <= num_edges; i++)
  {
    double u = URecord[i-1];
    gerr = ent->igeom_instance()->getEntUtoXYZ(edge, u, coords[3*i], coords[3*i+1], coords[3*i+2]);
    IBERRCHK(gerr, "Trouble getting U from XYZ along the edge.");
  }
  return;

}
Example #10
0
static int getTextFromPositions(lua_State *L) {
	CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
	int x0 = luaL_checkint(L, 2);
	int y0 = luaL_checkint(L, 3);
	int x1 = luaL_checkint(L, 4);
	int y1 = luaL_checkint(L, 5);

	LVDocView *tv = doc->text_view;
	lvRect margin = tv->getPageMargins();

	lvPoint startpt(x0, y0);
	lvPoint endpt(x1, y1);
	ldomXPointer startp = tv->getNodeByPoint(startpt);
	ldomXPointer endp = tv->getNodeByPoint(endpt);
	if (!startp.isNull() && !endp.isNull()) {
	    lua_newtable(L); // new text boxes
		ldomXRange r(startp, endp);
		if (r.getStart().isNull() || r.getEnd().isNull())
			return 0;
		r.sort();

		if (!r.getStart().isVisibleWordStart())
			r.getStart().prevVisibleWordStart();
		if (!r.getEnd().isVisibleWordEnd())
			r.getEnd().nextVisibleWordEnd();
		if (r.isNull())
			return 0;

		if (r.getStart() == r.getEnd()) { // for single CJK character
			ldomNode * node = r.getStart().getNode();
			lString16 text = node->getText();
			int textLen = text.length();
			int offset = r.getEnd().getOffset();
			if (offset < textLen - 1)
				r.getEnd().setOffset(offset + 1);
		}

		r.setFlags(1);
		tv->selectRange(r);  // we don't need native highlight of selection

		int page = tv->getBookmarkPage(startp);
		int pages = tv->getPageCount();
		lString16 titleText;
		lString16 posText;
		tv->getBookmarkPosText(startp, titleText, posText);
		lString16 selText = r.getRangeText( '\n', 8192 );

		lua_pushstring(L, "text");
		lua_pushstring(L, UnicodeToLocal(selText).c_str());
		lua_settable(L, -3);
		lua_pushstring(L, "pos0");
		lua_pushstring(L, UnicodeToLocal(r.getStart().toString()).c_str());
		lua_settable(L, -3);
		lua_pushstring(L, "pos1");
		lua_pushstring(L, UnicodeToLocal(r.getEnd().toString()).c_str());
		lua_settable(L, -3);
		lua_pushstring(L, "title");
		lua_pushstring(L, UnicodeToLocal(titleText).c_str());
		lua_settable(L, -3);
		lua_pushstring(L, "context");
		lua_pushstring(L, UnicodeToLocal(posText).c_str());
		lua_settable(L, -3);
		lua_pushstring(L, "percent");
		lua_pushnumber(L, 1.0*page/(pages-1));
		lua_settable(L, -3);
	    return 1;
	}
    return 0;
}