Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# generated from manifests external_dependencies
arabic-reshaper
python-bidi
reportlab
6 changes: 6 additions & 0 deletions setup/sign_oca_font_support/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 1 addition & 5 deletions sign_oca/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

========
Sign Oca
========
Expand All @@ -17,7 +13,7 @@ Sign Oca
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github
Expand Down
1 change: 1 addition & 0 deletions sign_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import controllers
from . import models
from . import wizards
from . import utils
7 changes: 7 additions & 0 deletions sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,12 @@
"web/static/src/libs/fontawesome/css/font-awesome.css",
],
},
"external_dependencies": {
"python": [
"arabic-reshaper",
"python-bidi",
"reportlab",
],
},
"maintainers": ["etobella"],
}
27 changes: 25 additions & 2 deletions sign_oca/models/sign_oca_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@

import hashlib
import json
import os
from base64 import b64decode, b64encode
from hashlib import sha256
from io import BytesIO

from PyPDF2 import PdfFileReader, PdfFileWriter
from reportlab.graphics.shapes import Drawing, Line, Rect
from reportlab.lib.colors import black, transparent
from reportlab.lib.enums import TA_RIGHT
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfgen import canvas
from reportlab.platypus import Image, Paragraph

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.http import request
from odoo.tools import float_repr
from odoo.tools import file_path, float_repr

from .. import utils as fonts_utils


class SignOcaRequest(models.Model):
Expand Down Expand Up @@ -521,7 +525,26 @@ def _get_pdf_page_text(self, item, box):
can = canvas.Canvas(packet, pagesize=(box.getWidth(), box.getHeight()))
if not item["value"]:
return False
par = Paragraph(item["value"], style=self._getParagraphStyle())
value = item["value"]
# Detect if text contains Arabic characters
is_arabic = any("\u0600" <= ch <= "\u06FF" for ch in value)
# Font selection
font_name = item.get("font", "Helvetica")
fonts_directory = file_path(os.path.join("sign_oca", "static", "fonts"))
font_path = None
if is_arabic:
font_name = "Amiri"
font_path = os.path.join(fonts_directory, "Amiri-Regular.ttf")
fonts_utils.ensure_font_registered("Amiri", font_path)
text = fonts_utils.prepare_text(value, is_arabic)
style = ParagraphStyle(
name="Custom",
fontName=font_name,
fontSize=12,
leading=14,
alignment=TA_RIGHT if is_arabic else 0, # 0 = left
)
par = Paragraph(text, style=style)
par.wrap(
item["width"] / 100 * float(box.getWidth()),
item["height"] / 100 * float(box.getHeight()),
Expand Down
42 changes: 18 additions & 24 deletions sign_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Sign Oca</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="sign-oca">
<h1 class="title">Sign Oca</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="sign-oca">
<h1>Sign Oca</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b17d01dcbe348901b5e778fda1c276bbd58e85a4a1c3f1cdffbb855ad51afe05
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sign/tree/16.0/sign_oca"><img alt="OCA/sign" src="https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sign-16-0/sign-16-0-sign_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sign&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sign/tree/16.0/sign_oca"><img alt="OCA/sign" src="https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sign-16-0/sign-16-0-sign_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sign&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to create documents for signature inside Odoo using
OWL.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -403,17 +398,17 @@ <h1>Sign Oca</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>There is a wizard (sign.oca.template.generate.multi) that can be used
for any model needed. If there is a template without a linked model or
linked to a model (res.partner for example) an action will be
automatically displayed in the tree and form view (only for users with
Sign permissions).</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<div class="section" id="creation-of-templates">
<h3><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h2>
<ul class="simple">
<li>Access Sign / Templates</li>
<li>Create a new template</li>
Expand All @@ -425,7 +420,7 @@ <h3><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h3>
</ul>
</div>
<div class="section" id="sign-role">
<h3><a class="toc-backref" href="#toc-entry-4">Sign role</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">Sign role</a></h2>
<ul class="simple">
<li>Access Sign / Settings / Roles</li>
<li>Create a new role (Equipment employee for example)</li>
Expand All @@ -436,7 +431,7 @@ <h3><a class="toc-backref" href="#toc-entry-4">Sign role</a></h3>
</ul>
</div>
<div class="section" id="sign-a-document-from-template">
<h3><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a></h2>
<ul class="simple">
<li>Access Sign / Templates</li>
<li>Press the Sign button from a template</li>
Expand All @@ -451,7 +446,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a>
</ul>
</div>
<div class="section" id="sign-a-pending-document">
<h3><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h2>
<ul class="simple">
<li>Go to the pencil icon in the upper right corner (systray) of the sign
request to access the pending signatures.</li>
Expand All @@ -464,7 +459,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h3>
</ul>
</div>
<div class="section" id="sign-from-template">
<h3><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h2>
<ul class="simple">
<li>Go to any list view or form view (except sign.oca models), e.g.:
Contacts</li>
Expand All @@ -482,9 +477,9 @@ <h3><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h3>
</div>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h1>
<div class="section" id="tasks">
<h3><a class="toc-backref" href="#toc-entry-9">Tasks</a></h3>
<h2><a class="toc-backref" href="#toc-entry-9">Tasks</a></h2>
<ul class="simple">
<li>Ensure that the signature is inalterable. Maybe we might need to use
some tools like endevise or pyHanko with a certificate. Signer can be
Expand All @@ -493,23 +488,23 @@ <h3><a class="toc-backref" href="#toc-entry-9">Tasks</a></h3>
</div>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-10">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-10">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sign/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/sign/issues/new?body=module:%20sign_oca%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-11">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-11">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-12">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-12">Authors</a></h2>
<ul class="simple">
<li>Dixmit</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-13">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
<ul class="simple">
<li>Enric Tobella (<a class="reference external" href="http://www.dixmit.com">www.dixmit.com</a>)</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
Expand All @@ -523,7 +518,7 @@ <h3><a class="toc-backref" href="#toc-entry-13">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -538,6 +533,5 @@ <h3><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
Binary file added sign_oca/static/fonts/Amiri-Regular.ttf
Binary file not shown.
36 changes: 36 additions & 0 deletions sign_oca/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2025 Kencove - Mohamed Alkobrosli
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import os

import arabic_reshaper
from bidi.algorithm import get_display
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont


def ensure_font_registered(font_name, font_path):
"""
Ensure a TTF/OTF font is registered in ReportLab.
If already registered, does nothing.
"""
try:
pdfmetrics.getFont(font_name)
except KeyError as err:
if not os.path.exists(font_path):
raise FileNotFoundError(f"Font file not found: {font_path}") from err
pdfmetrics.registerFont(TTFont(font_name, font_path))


def prepare_text(text, is_arabic=False):
"""
Prepares text for ReportLab rendering.
- If Arabic, reshapes + applies bidi.
- Otherwise, leaves text as is.
"""
if not text:
return ""
if is_arabic:
reshaped = arabic_reshaper.reshape(text)
return get_display(reshaped)
return text
87 changes: 87 additions & 0 deletions sign_oca_font_support/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
=====================
Sign OCA Font Support
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3f61009f2307c2e9f0e4e5648153302557141328211b29b4a3c8690f4252c896
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github
:target: https://github.com/OCA/sign/tree/16.0/sign_oca_font_support
:alt: OCA/sign
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sign-16-0/sign-16-0-sign_oca_font_support
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sign&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to add custom fonts for different language
characters like Arabic.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sign/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sign/issues/new?body=module:%20sign_oca_font_support%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Kencove

Contributors
------------

- `Kencove <https://kencove.com>`__

- Mohamed Alkobrosli

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-Kencove| image:: https://github.com/Kencove.png?size=40px
:target: https://github.com/Kencove
:alt: Kencove

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Kencove|

This module is part of the `OCA/sign <https://github.com/OCA/sign/tree/16.0/sign_oca_font_support>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions sign_oca_font_support/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import utils
19 changes: 19 additions & 0 deletions sign_oca_font_support/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2025 Kencove - Mohamed Alkobrosli
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Sign OCA Font Support",
"version": "16.0.1.0.0",
"website": "https://github.com/OCA/sign",
"author": "Kencove, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["sign_oca"],
"external_dependencies": {
"python": [
"arabic-reshaper",
"python-bidi",
"reportlab",
],
},
"installable": True,
"maintainers": ["Kencove"],
}
Loading