JNIEXPORT jint JNICALL Java_com_draekko_libharu_PdfPage_textRect
  (JNIEnv *env, jobject obj, jfloat jleft, jfloat jtop, jfloat jright, jfloat jbottom, jstring jtext, jobject jalignmentEnum) {

    haru_setup_error_handler(env, __func__);

    jclass TextRectAlign = env->FindClass("com/draekko/libharu/PdfPage$TextRectAlign");
    jmethodID TextRectAlign_getNameMethod = env->GetMethodID(TextRectAlign, "name", "()Ljava/lang/String;");
    jstring alignment_value = (jstring)env->CallObjectMethod(jalignmentEnum, TextRectAlign_getNameMethod);
    const char* alignment_str = env->GetStringUTFChars(alignment_value, 0);

    const char *text = env->GetStringUTFChars(jtext, 0);
    HPDF_UINT  *len;
    HPDF_REAL  left = jleft;
    HPDF_REAL  top = jtop;
    HPDF_REAL  right = jright;
    HPDF_REAL  bottom = jbottom;
    HPDF_TextAlignment align;
    HPDF_INT   value;

    if (strcmp(alignment_str, "TALIGN_LEFT") == 0) {
        align = HPDF_TALIGN_LEFT;
    } else if (strcmp(alignment_str, "TALIGN_RIGHT") == 0) {
        align = HPDF_TALIGN_RIGHT;
    } else if (strcmp(alignment_str, "TALIGN_CENTER") == 0) {
        align = HPDF_TALIGN_CENTER;
    } else if (strcmp(alignment_str, "TALIGN_JUSTIFY") == 0) {
        align = HPDF_TALIGN_JUSTIFY;
    } else {
        haru_throw_exception("Unsupported alignment.");
    }

    HPDF_Page page = get_HPDF_Page(env, obj);
    HPDF_Page_TextRect (page, left, top, right, bottom, text, align, len);

    env->ReleaseStringUTFChars(jtext, text);

    if (len == NULL) {
        value = -1;
    } else if (len < 0) {
        value = 0;
    } else {
        value = (long)len;
    }

    haru_clear_error_handler();

    return value;
}
/*
 * Class:     org_libharu_PdfPage
 * Method:    textRect
 * Signature: (FFFFLjava/lang/String;I)V
 */
JNIEXPORT void JNICALL
Java_org_libharu_PdfPage_textRect(JNIEnv *env, jobject obj, jfloat l, jfloat t, jfloat r, jfloat b,
        jstring textString, jint align) {
    jint page;
    const char* text;

    /* Get mHPDFPagePointer */
    page = (*env)->GetIntField(env, obj, mHPDFPagePointer);

    /* Get the text as a native char array */
    text = (*env)->GetStringUTFChars(env, textString, NULL);

    HPDF_Page_TextRect((HPDF_Page) page, (HPDF_REAL) l, (HPDF_REAL) t, (HPDF_REAL) r, (HPDF_REAL) b,
            text, getHPDFTextAlign(align), NULL);

    /* Release (free) the native char array */
    (*env)->ReleaseStringUTFChars(env, textString, text);
}
Example #3
0
void table(HPDF_Page page, HPDF_Font font, int row, int col, int X, int Y, int H,
        int *p, char**text){
    int width = HPDF_Page_GetWidth(page);
    //int height = HPDF_Page_GetHeight(page);
    int r=0, c=0, x, y, W = (width-20) / col;
    char tmp[130], tmp2[130];


    for (r = 0; r < row; r++)
    {
        x = 0; W = 0;
        for (c = 0; c < col; c++)
        {
            x = x + W;
            W = ((width-20)/100)*p[c];
            y = Y - (r * H);
            HPDF_Page_Rectangle (page, x +X , y , W, H);
            HPDF_Page_Stroke (page);

            HPDF_Page_BeginText (page);
            HPDF_Page_SetFontAndSize (page, font, 10);

            sprintf(tmp2, "%dx%d", r,c);
            sprintf(tmp,"[%s] %d %d %d %d | %d %d %d %d", tmp2, x , y, W, y, /*!*/ x+5 , y+10, x+W, y-10);
            sprintf(tmp,"[%s] %s", tmp2, text[(r*col)+c]);
            sprintf(tmp, "%s", text[(r*col)+c]);

            HPDF_Page_TextRect (page, x+2 +X+2 , y+15, x+W, y-10,
                    tmp, HPDF_TALIGN_LEFT, NULL);
            HPDF_Page_EndText (page);

            //HPDF_Page_TextRect (page, 10 , 600, 50, 550,
            //break;
        }
        //break;

    }
};
Example #4
0
void WPdfImage::drawText(const WRectF& rect, 
			 WFlags<AlignmentFlag> flags,
			 TextFlag textFlag,
			 const WString& text,
			 const WPointF *clipPoint)
{
  // FIXME: textFlag
  
  if (clipPoint && painter() && !painter()->clipPath().isEmpty()) {
    if (!painter()->clipPathTransform().map(painter()->clipPath())
	  .isPointInPath(painter()->worldTransform().map(*clipPoint)))
      return;
  }

  if (trueTypeFont_ && !trueTypeFonts_->busy())
    trueTypeFonts_->drawText(painter()->font(), rect, flags, text);
  else {
    HPDF_REAL left, top, right, bottom;
    HPDF_TextAlignment alignment = HPDF_TALIGN_LEFT;

    AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
    AlignmentFlag verticalAlign = flags & AlignVerticalMask;

    switch (horizontalAlign) {
    default:
      // should never happen
    case AlignmentFlag::Left:
      left = rect.left();
      right = left + 10000;
      alignment = HPDF_TALIGN_LEFT;
      break;
    case AlignmentFlag::Right:
      right = rect.right();
      left = right - 10000;
      alignment = HPDF_TALIGN_RIGHT;
      break;
    case AlignmentFlag::Center:
      {
	float center = rect.center().x();
	left = center - 5000;
	right = center + 5000;
	alignment = HPDF_TALIGN_CENTER;
	break;
      }
    }

    switch (verticalAlign) {
    default:
      // fall-through ; should never happen
    case AlignmentFlag::Top:
      top = rect.top(); break;
    case AlignmentFlag::Middle:
      // FIXME: use font metrics to center middle of ascent !
      top = rect.center().y() - 0.60 * fontSize_; break;
    case AlignmentFlag::Bottom:
      top = rect.bottom() - fontSize_; break;
    }

    bottom = top + fontSize_;

    if (trueTypeFonts_->busy())
      setChanged(PainterChangeFlag::Font);

    HPDF_Page_GSave(page_);

    // Undo the global inversion
    HPDF_Page_Concat(page_, 1, 0, 0, -1, 0, bottom);

    HPDF_Page_BeginText(page_);

    // Need to fill text using pen color
    const WColor& penColor = painter()->pen().color();
    HPDF_Page_SetRGBFill(page_,
			 penColor.red() / 255.,
			 penColor.green() / 255.,
			 penColor.blue() / 255.);

    std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();

    HPDF_Page_TextRect(page_, left, fontSize_, right, 0, s.c_str(),
		       alignment, nullptr);

    HPDF_Page_EndText(page_);

    HPDF_Page_GRestore(page_);
  }
}
Example #5
0
void WPdfImage::drawText(const WRectF& rect, 
			 WFlags<AlignmentFlag> flags,
			 TextFlag textFlag,
			 const WString& text)
{
  // FIXME: textFlag

  if (trueTypeFont_ && !trueTypeFonts_->busy())
    trueTypeFonts_->drawText(painter()->font(), rect, flags, text);
  else {
    HPDF_REAL left, top, right, bottom;
    HPDF_TextAlignment alignment;

    AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
    AlignmentFlag verticalAlign = flags & AlignVerticalMask;

    switch (horizontalAlign) {
    case AlignLeft:
      left = rect.left();
      right = left + 1000;
      alignment = HPDF_TALIGN_LEFT;
      break;
    case AlignRight:
      right = rect.right();
      left = right - 1000;
      alignment = HPDF_TALIGN_RIGHT;
      break;
    case AlignCenter:
      {
	float center = rect.center().x();
	left = center - 500;
	right = center + 500;
	alignment = HPDF_TALIGN_CENTER;
	break;
      }
    default:
      break;
    }

    switch (verticalAlign) {
    case AlignTop:
      top = rect.top(); break;
    case AlignMiddle:
      // FIXME: use font metrics to center middle of ascent !
      top = rect.center().y() - 0.60 * fontSize_; break;
    case AlignBottom:
      top = rect.bottom() - fontSize_; break;
    default:
      break;
    }

    bottom = top + fontSize_;

    if (trueTypeFonts_->busy())
      setChanged(Font);

    HPDF_Page_GSave(page_);

    // Undo the global inversion
    HPDF_Page_Concat(page_, 1, 0, 0, -1, 0, bottom);

    HPDF_Page_BeginText(page_);

    // Need to fill text using pen color
    const WColor& penColor = painter()->pen().color();
    HPDF_Page_SetRGBFill(page_,
			 penColor.red() / 255.,
			 penColor.green() / 255.,
			 penColor.blue() / 255.);

    std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();

    HPDF_Page_TextRect(page_, left, fontSize_, right, 0, s.c_str(),
		       alignment, 0);

    HPDF_Page_EndText(page_);

    HPDF_Page_GRestore(page_);
  }
}