TextView Gtkmm - Changing Size - g++

I am trying to build a window in Gtkmm. All of my widgets are appearing, but I cannot adjust the height of my textviews. I have tried set_border_window_size() and set_size_request(), but neither are working. That is, they are not changing any aspect of the textview size.
Here is my window constructor:
UDPWindow::UDPWindow() :
Gtk::ApplicationWindow(),
box_hBox(Gtk::ORIENTATION_HORIZONTAL, 7),
box_vBox1(Gtk::ORIENTATION_VERTICAL, 7),
box_vBox2(Gtk::ORIENTATION_VERTICAL, 7),
box_sentData(Gtk::ORIENTATION_VERTICAL, 7),
box_receivedData(Gtk::ORIENTATION_VERTICAL, 7),
frm_sentData("Sent Data"),
frm_receivedData("Received Data"),
lbl_sendMessage("Message to Send"),
lbl_sendDevice("Select Device"),
btn_send("Send Message"),
btn_quit("Quit"),
comms(NULL)
{
// set up UDP Communications
//comms = new UDP_Communicator();
uchar device[3] = {1, 2, 3};
/*device[0] = comms->createNewSocket(52088, "192.168.1.2", 2);
device[1] = comms->createNewSocket(8090, "192.168.1.3", 2);
device[2] = comms->createNewSocket(48183, "192.168.1.4", 2);
comms->start();
comms->postMessage(MSG_ADD_DEVICE_TO_HANDSHAKE, "", device[0]);
comms->postMessage(MSG_ADD_DEVICE_TO_HANDSHAKE, "", device[1]);
comms->postMessage(MSG_START_HANDSHAKE, "", 0);*/
//fill combo box
std::stringstream str;
str << (int)device[0];
cmb_sendDevice.append(str.str());
str.str(std::string());
str.clear();
str << (int)device[1];
cmb_sendDevice.append(str.str());
str.str(std::string());
str.clear();
str << (int)device[2];
cmb_sendDevice.append(str.str());
cmb_sendDevice.set_active(0);
// set up message text box
txt_sendMessage.set_max_length(50);
txt_sendMessage.set_text("Enter Message");
// set up quit button
btn_quit.signal_clicked().connect(sigc::mem_fun(*this, &UDPWindow::on_btn_quit));
// set up send button
btn_send.signal_clicked().connect(sigc::mem_fun(*this, &UDPWindow::on_btn_send));
// set up sent data scroll text
txt_sentData.set_editable(false);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_TOP, 15);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_BOTTOM, 15);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_LEFT, 100);
txt_sentData.set_border_window_size(Gtk::TEXT_WINDOW_RIGHT, 100);
txt_sentData.set_size_request(-1, 100);
scrl_sentData.add(txt_sentData);
scrl_sentData.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
// set up received data scroll text
txt_receivedData.set_editable(false);
scrl_receivedData.add(txt_receivedData);
scrl_receivedData.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
add(box_hBox);
box_hBox.pack_start(box_vBox1, Gtk::PACK_SHRINK);
box_sentData.pack_start(lbl_sendDevice, Gtk::PACK_SHRINK);
box_sentData.pack_start(cmb_sendDevice, Gtk::PACK_SHRINK);
box_sentData.pack_start(lbl_sendMessage, Gtk::PACK_SHRINK);
box_sentData.pack_start(txt_sendMessage, Gtk::PACK_SHRINK);
box_sentData.pack_start(btn_send, Gtk::PACK_SHRINK);
box_sentData.pack_start(scrl_sentData, Gtk::PACK_SHRINK);
frm_sentData.add(box_sentData);
box_vBox1.pack_start(frm_sentData, Gtk::PACK_SHRINK);
box_hBox.pack_start(box_vBox2, Gtk::PACK_SHRINK);
box_receivedData.pack_start(scrl_receivedData, Gtk::PACK_SHRINK);
box_receivedData.pack_start(btn_quit, Gtk::PACK_SHRINK);
frm_receivedData.add(box_receivedData);
box_vBox2.pack_start(frm_receivedData, Gtk::PACK_SHRINK);
this->show_all();
}
There is a set_default_size() function attached to Gtk::window, but as a widget the textview doesn't seem to have access to it. I am at a loss on what to do.
The above posted code has both set_border_window_size() and set_size_request() included even though only one set of functions were used at a time.

Because the TextView is inside a ScrolledWindow, the ScrolledWindow's attributes are what determines the size.
scrl_sentData.set_size_request(-1, 100);

Related

Unable to rotate image in PDFBox

I am trying to change the angle of the image by using matrix.Its a needle image which points the value in a chart.
If i am giving "at.rotate(Math.toRadians(45));" , then its looking like it went inside the page, but i need it in the page.
Here is the code i m trying
//Retrieving the pages of the document
PDPage page = document.getPage(0);
//Creating PDImageXObject object
PDImageXObject needle = PDImageXObject.createFromFile("SpeedometerNeedle-300dpi-ActualSize.png"
,document);
PDPageContentStream contentStream = new PDPageContentStream(document, page, AppendMode.APPEND, true, true);
//Drawing the image in the PDF document
// draw 90° rotated, placed on the right of the first image
Matrix at = new Matrix(needle.getHeight() / 4, 0, 0, needle.getWidth() / 4,120, 565);
at.rotate(Math.toRadians(45));
// contentStream.drawImage(needle, 100, 565, needle.getWidth() / 4, needle.getHeight() / 4);
contentStream.drawImage(needle,at);
contentStream.close();
I am using org.apache.pdfbox:pdfbox:2.0.1 version ,So if i am trying to use
AffineTransform at = new AffineTransform(ximage.getHeight() / 2, 0, 0, ximage.getWidth() / 2, x + ximage1.getWidth(), y);
at.rotate(Math.toRadians(90));
contentStream.drawXObject(ximage, at);
Then drawXObject method is shown as deprecated.
So suggest me how to use it.

Weird projection using custom panorama and large equirectengular file

I'll try to explain my problem :
I'm creating a custom panorama with the Street View API, I cut my panorama image by 512px tiles (my panorama is always a multiple of 512px).
It's render well, in most case :
http://postimg.org/image/vdrre7qt7/
But, when I'm using large panorama, it's render like this :
http://postimg.org/image/5uxo0nof7/
This effect disapear when I zoom in.
On mobile, whatever the panorama size is, it's render the same (and have to zoom in to 3 or 4 zoom value to have it right).
Here is my code (size.w and size.h are the panorama dimension):
var streetViewPanoramaData = {
links: [],
copyright: 'Stuff',
tiles: {
tileSize: new google.maps.Size(512, 512),
worldSize: new google.maps.Size(size.w, size.h),
centerHeading: 0,
getTileUrl: t.getCustomPanoramaTileUrl
}
};
streetViewPanoramaData["location"] = {
pano: panoID,
description: "Custom Panorama",
latLng: new google.maps.LatLng(37.556429, -122.050745)
};
Here is the getCustomePanoramaTileURL
this.getCustomPanoramaTileUrl = function(panoID, zoom, tileX, tileY) {
// Return a pano image given the panoID.
return "/the/directory/" + panoID + '/' + 0 + '_' + tileX + '_' + tileY + '.jpg';
}
"/the/directory/panoID" contain my tiles.
Any lead will be appreciate :)
I think, I had exactly the same problem. It took me hours to solve it.
So, the problem is, that you create only 1 image and split it into tiles.
Google requires multiple images, split into tiles - one image for each zoom level.
You need to create each version of the panorama for successive 1/2 height 1/2 width sizes until the panorama fits into one tile.
For example, if you have a panorama of 6000 * 3000 pixels and you use a 512 * 512 tile size, you will need to create:
panorama 6000 * 3000 (12*6 tiles)
panorama 3000 * 1500 (6*3 tiles)
panorama 1500 * 750 (3*2 tiles)
panorama 750 * 375 (2*1 tiles)
panorama 375 * 187 (1*1 tile)
This is little PHP script I use to generate tiles:
// util function used below
function resize_image($old_src, $new_src, $new_width, $new_height=null)
{
$src=imagecreatefromjpeg($old_src);
list($width, $height)=getimagesize($old_src);
$new_height = $new_height ? $new_height : round(($height/$width)*$new_width);
$tmp=imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if (file_exists($new_src))
unlink($new_src);
imagejpeg($tmp, $new_src, 85);
}
$pano="/path/to/your/panorama.jpg";
$tiles_dir="/directory/where/you/want/to/place/tiles";
$crop_width=$crop_height=500; // your tiles size
$zooms=array(8000, 4000, 2000, 1000, 500); // I have 8000*4000 image, so I set sizes manually
$zooms=array_reverse($zooms);
foreach ($zooms as $zoom_level=>$zoom_width)
{
$name=str_replace('.jpg', '', basename($pano));
$zoom_dir=$tiles_dir.'/'.$name.'/'.$zoom_level;
if (!is_dir($zoom_dir))
mkdir($zoom_dir, 0777, true);
$temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
resize_image($pano, $temp_image_src, $zoom_width); // my own function that resizes image
$img = new Imagick($temp_image_src);
$imgHeight=$img->getImageHeight();
$imgWidth=$img->getImageWidth();
$crop_width_num_times=ceil($imgWidth/$crop_width);
$crop_height_num_times=ceil($imgHeight/$crop_height);
$counter_x=0;
for ($i=0; $i<$crop_width_num_times; $i++)
{
$counter_y=0;
for ($j=0; $j<$crop_height_num_times; $j++)
{
$img = new Imagick($temp_image_src);
$x=($i*$crop_width);
$y=($j*$crop_height);
$img->cropImage($crop_width, $crop_height, $x, $y);
$data=$img->getImageBlob();
for ($z=0; $z<=5; $z++)
{
$newFileName=$zoom_dir."/".$counter_x."_".$counter_y.".jpg";
$result=file_put_contents($newFileName, $data);
}
$counter_y++;
}
$counter_x++;
}
}

table header in pdf getting displayed using itextpdf5.1.1 but not in itextpdf5.5.3

We have generated a pdf in landscape mode with header and footer as part of the pdf. The header table and footer display fine in pdf using itextpdf5.1.1 jar. However when we update the jar to 5.5.3, the header table does not show only the footer shows. Below is the code snippet.
document = new Document(PageSize.A4.rotate(), 20, 20, 75, 20);
PdfCopy copy = new PdfCopy(document, new FileOutputStream(strPDFFile));
document.open();
PdfReader pdfReaderIntermediate =
new PdfReader(strIntermediatePDFFile);
numberOfPages = pdfReaderIntermediate.getNumberOfPages();
Font ffont = new Font(Font.FontFamily.UNDEFINED, 7, Font.NORMAL);
System.out.println("###### No. of Pages: " + numberOfPages);
for (int j = 0; j < numberOfPages; ) {
page = copy.getImportedPage(pdfReaderIntermediate, ++j);
stamp = copy.createPageStamp(page);
Phrase footer =
new Phrase(String.format("%d of %d", j, numberOfPages), ffont);
ColumnText.showTextAligned(stamp.getUnderContent(),
Element.ALIGN_CENTER, footer,
(document.right() - document.left()) /
2 + document.leftMargin(),
document.bottom() - 10, 0);
if (j != 1) {
headerTable = new PdfPTable(2);
headerTable.setTotalWidth(700);
headerTable.getDefaultCell().setFixedHeight(10);
headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
headerTable.addCell(new Phrase(String.format(header1), ffont));
headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
headerTable.addCell(new Phrase(String.format(header2), ffont));
headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
headerTable.addCell(new Phrase(String.format(header3), ffont));
headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
headerTable.addCell(new Phrase(String.format(header5, j),
ffont));
headerTable.completeRow();
headerTable.writeSelectedRows(0, 5, 60.5f, 550,
stamp.getUnderContent());
}
stamp.alterContents();
copy.addPage(page);
}
document.close();
When we change the jar from 5.1.1 to 5.5.3 the header is lost. May be a change is needed in the way we call the header for the new jar.
Any inputs will be well appreciated.
Thanks.
You have cells with default padding (i.e. 2) and height 10, and you try to insert text at height 7. But 2 (top margin) + 7 (text height) + 2 (bottom margin) = 11, i.e. more than fits into your cell height 10. Thus, the text does not fit and is not displayed.
You can fix this by either
using a smaller font, e.g. 6, or
using a heigher cell, e.g. 11, or
using a smaller padding, e.g. 1:
headerTable.getDefaultCell().setPadding(1);
With any of these changes, your header shows.
I don't know in which way iText 5.1.1 handled this differently, but the behavior of current iText versions makes sense.

How to change text height in pdfbox

PDFBOX / JSF
Im trying to change the font height of a given text. I know how to change the fontsize only.
PDPageContentStream contentStreambc = new PDPageContentStream(doc1, page, true, true);
contentStreambc.setFont( fonta, 16 );
contentStreambc.beginText();
contentStreambc.moveTextPositionByAmount(200, 320);
contentStreambc.drawString( "abcdef");
contentStreambc.endText();
contentStreambc.close();
The code works fine. But How I change the font height ?
thanks in advance stack members.
If you need something like this
you can create it with this code:
PDRectangle rec = new PDRectangle(220, 70);
PDDocument document = null;
document = new PDDocument();
PDPage page = new PDPage(rec);
document.addPage(page);
PDPageContentStream content = new PDPageContentStream(document, page, true, true);
content.beginText();
content.moveTextPositionByAmount(7, 55);
content.setFont(PDType1Font.HELVETICA, 12);
content.drawString("Normal text (size 12)");
content.setTextMatrix(1, 0, 0, 1.5f, 7, 30);
content.drawString("Stretched text (size 12, factor 1.5)");
content.setTextMatrix(1, 0, 0, 2f, 7, 5);
content.drawString("Stretched text (size 12, factor 2)");
content.endText();
content.close();
document.save("SimplePdfStretchedText.pdf");
The code stretches the text by setting the text matrix accordingly; for details cf. chapter 9 of the PDF specification ISO 32000-1.
PS: As you mention bar codes in a comment to another answer, this should indeed allow you to make higher bar codes while keeping the distances.

Background color change on dynamic page

I am building a webstore, where the quantity of displayed products is dinamically changing, by pressing "Show more" button. Background color should be changing multiple times while scrolling down and I found this article, which solves this problem, but it has fixed page height. Is it possible to change that?
You use a parameter to control the adaption rate and set this according to your needs if you don't know the page size on forehand (because a dynamic load for instance).
cStart = [250, 195, 56] // Gold
, cEnd = [179, 217, 112] // Lime
, cDiff = [cEnd[0] - cStart[0], cEnd[1] - cStart[1], cEnd[1] - cStart[0]];
$(document).ready(function(){
$(document).scroll(function() {
var speed = 0.0005;
var p = $(this).scrollTop()* speed;
p = Math.min(1, Math.max(0, p)); // Clamp to [0, 1]
var cBg = [Math.round(cStart[0] + cDiff[0] * p), Math.round(cStart[1] + cDiff[1] * p), Math.round(cStart[2] + cDiff[2] * p)];
$("body").css('background-color', 'rgb(' + cBg.join(',') +')');
});
});